Skip to content

Commit

Permalink
feat(reports): ✨ implement reports of any arbitrary date/span (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed Jul 7, 2023
1 parent 4a84860 commit e45e46e
Show file tree
Hide file tree
Showing 4 changed files with 330 additions and 37 deletions.
31 changes: 31 additions & 0 deletions assets/svg/tip-error.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/tip-error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 11 additions & 7 deletions src/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class Settings
internal const string ProjectPrefix = "@";
internal const string EscapeCharacter = @"\";
internal const string FlagPrefix = "-";
internal const string DateSeparator = ">";
internal const string FauxWhitespace = "_";

internal const string ClearDescriptionFlag = $"{Settings.FlagPrefix}C";
internal const string TimeSpanFlag = $"{Settings.FlagPrefix}t";
Expand All @@ -49,7 +51,9 @@ public class Settings
internal static readonly Regex UnescapedProjectRegex = new Regex(@$"(?<!\{Settings.EscapeCharacter}){Settings.ProjectPrefix}");
internal static readonly Regex UnescapedFlagRegex = new Regex(@$" {Settings.FlagPrefix}");
internal static readonly Regex ProjectCaptureRegex = new Regex(@$"(?<!\{Settings.EscapeCharacter}){Settings.ProjectPrefix}(.*)");
internal static readonly Regex ReportsSpanPartialOffsetRegex = new Regex(@"(^|\D)-");
internal static readonly Regex ReportsSpanOffsetRegex = new Regex(@"-(\d+)");
internal static readonly Regex ReportsSpanDatesRegex = new Regex(@$"^([^{Settings.DateSeparator}]+){Settings.DateSeparator}?([^{Settings.DateSeparator}]+)?$");

internal enum ReportsSpanKey
{
Expand All @@ -69,7 +73,7 @@ internal enum ReportsSpanKey
1 => "yesterday",
_ => $"{offset} days ago",
},
Score = 400,
Score = 40000,
// Offsetted day
Start = (referenceDate, _, offset) => referenceDate.AddDays(-offset),
End = (referenceDate, _, offset) => referenceDate.AddDays(-offset),
Expand All @@ -83,7 +87,7 @@ internal enum ReportsSpanKey
1 => "last week",
_ => $"{offset} weeks ago",
},
Score = 300,
Score = 30000,
// Start of the offsetted week
Start = (referenceDate, beginningOfWeek, offset) => referenceDate.AddDays(-((7 + ((int)referenceDate.DayOfWeek - (int)beginningOfWeek)) % 7) - (offset * 7)),
// End of the offsetted week
Expand All @@ -98,7 +102,7 @@ internal enum ReportsSpanKey
1 => "last month",
_ => $"{offset} months ago",
},
Score = 200,
Score = 20000,
// First day of the offsetted month
Start = (referenceDate, _, offset) => new DateTimeOffset(referenceDate.Year, referenceDate.Month, 1, 0, 0, 0, referenceDate.Offset).AddMonths(-offset),
// Last day of the offsetted month
Expand All @@ -113,7 +117,7 @@ internal enum ReportsSpanKey
1 => "last year",
_ => $"{offset} years ago",
},
Score = 100,
Score = 10000,
// First day of the offsetted year
Start = (referenceDate, _, offset) => new DateTimeOffset(referenceDate.Year - offset, 1, 1, 0, 0, 0, referenceDate.Offset),
// Last day of the offsetted year
Expand All @@ -136,23 +140,23 @@ public enum ReportsGroupingKey
{
Argument = Settings.ReportsGroupingProjectsArgument,
Interpolation = "View tracked time grouped by project",
Score = 300,
Score = 30000,
Grouping = Settings.ReportsGroupingKey.Projects,
SubArgument = null,
},
new ReportsGroupingCommandArgument
{
Argument = Settings.ReportsGroupingClientsArgument,
Interpolation = "View tracked time grouped by client",
Score = 200,
Score = 20000,
Grouping = Settings.ReportsGroupingKey.Clients,
SubArgument = Settings.ReportsGroupingProjectsArgument,
},
new ReportsGroupingCommandArgument
{
Argument = Settings.ReportsGroupingEntriesArgument,
Interpolation = "View tracked time entries",
Score = 100,
Score = 10000,
Grouping = Settings.ReportsGroupingKey.Entries,
SubArgument = null,
},
Expand Down
Loading

0 comments on commit e45e46e

Please sign in to comment.