Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ Configure the connection to your Timetracker instance.
|---|---|---|---|
| `--url` | `-u` | yes* | Base URL of your Timetracker instance |
| `--token` | `-t` | yes* | Bearer token for authentication |
| `--border` | | no | Table border style for list output: `minimal` (default), `square`, or `markdown` |
| `--border` | | no | Table border style for list output: `minimal` (default), `square`, `markdown`, or `ascii` |
| `--week-start` | | no | First day of the week for `--week`/`--last-week`: `sunday` (default) or `monday` |
| `--show` | | no | Display current config (token masked) |
| `--reset` | | no | Delete all local config and activity cache |

Expand All @@ -89,6 +90,11 @@ timetracker config -t eyJnew...

# Change the list table border (no network call, credentials untouched)
timetracker config --border square
timetracker config --border ascii

# Set week start to Sunday (default) or Monday
timetracker config --week-start sunday
timetracker config --week-start monday

# Remove all local config
timetracker config --reset
Expand Down Expand Up @@ -162,13 +168,13 @@ List time entries for a period.
| `--output` | `-o` | no | Output format: `json` (batch-upload compatible) or `csv` |
| `--today` | | no | Shortcut for today's entries |
| `--yesterday` | | no | Shortcut for yesterday's entries |
| `--week` | | no | Entries for the current week (Mon–Sun) |
| `--week` / `--current-week` | | no | Entries for the current week (Mon–Sun) |
| `--last-week` | | no | Entries for the previous week (Mon–Sun) |
| `--month` | | no | Entries for the current month |
| `--month` / `--current-month` | | no | Entries for the current month |
| `--last-month` | | no | Entries for the previous month |
| `--ids` | | no | Show entry IDs in the last column, in place of comments |

All period shortcuts (`--today`, `--yesterday`, `--week`, `--last-week`, `--month`, `--last-month`) and `--period` are mutually exclusive and cannot be combined with `--from` or `--to`.
All period shortcuts (`--today`, `--yesterday`, `--week`, `--current-week`, `--last-week`, `--month`, `--current-month`, `--last-month`) and `--period` are mutually exclusive and cannot be combined with `--from` or `--to`.

```bash
# Today's entries
Expand Down Expand Up @@ -222,9 +228,9 @@ Accepts the same period options as `list`.
| `--output` | `-o` | no | Output format: `json` or `csv`. Defaults to a table |
| `--today` | | no | Today |
| `--yesterday` | | no | Yesterday |
| `--week` | | no | Current week (Mon–Sun) |
| `--week` / `--current-week` | | no | Current week (Mon–Sun) |
| `--last-week` | | no | Previous week (Mon–Sun) |
| `--month` | | no | Current month |
| `--month` / `--current-month` | | no | Current month (default when no period is given) |
| `--last-month` | | no | Previous month |

```bash
Expand Down Expand Up @@ -256,9 +262,9 @@ Browse, create, copy, edit and delete time entries in an interactive terminal UI
| `--work-item` | `-w` | no | Filter by Work Item ID |
| `--today` | | no | Entries for today (default) |
| `--yesterday` | | no | Entries for yesterday |
| `--week` | | no | Entries for the current week |
| `--week` / `--current-week` | | no | Entries for the current week |
| `--last-week` | | no | Entries for the previous week |
| `--month` | | no | Entries for the current month |
| `--month` / `--current-month` | | no | Entries for the current month |
| `--last-month` | | no | Entries for the previous month |

```bash
Expand Down
2 changes: 2 additions & 0 deletions Timetracker.Tests/FakePeriodOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ internal sealed class FakePeriodOptions : IPeriodOptions
public bool Today { get; init; }
public bool Yesterday { get; init; }
public bool Week { get; init; }
public bool CurrentWeek { get; init; }
public bool LastWeek { get; init; }
public bool Month { get; init; }
public bool CurrentMonth { get; init; }
public bool LastMonth { get; init; }
}
75 changes: 74 additions & 1 deletion Timetracker.Tests/PeriodResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace Timetracker.Tests;

public class PeriodResolverTests
public class PeriodResolverTests : IDisposable
{
public void Dispose() => ValidationUtils.WeekStartOverride = null;
// --- Error paths -------------------------------------------------------

[Fact]
Expand Down Expand Up @@ -137,6 +138,8 @@ public void Period_ResolvesToWholeMonth()
[Fact]
public void Week_IsMondayToSunday()
{
ValidationUtils.WeekStartOverride = DayOfWeek.Monday;

var ok = PeriodResolver.TryResolve(new FakePeriodOptions { Week = true }, out var from, out var to, out _);

Assert.True(ok);
Expand All @@ -148,6 +151,8 @@ public void Week_IsMondayToSunday()
[Fact]
public void LastWeek_IsExactlySevenDaysBeforeThisWeek()
{
ValidationUtils.WeekStartOverride = DayOfWeek.Monday;

PeriodResolver.TryResolve(new FakePeriodOptions { Week = true }, out var weekFrom, out var weekTo, out _);
PeriodResolver.TryResolve(new FakePeriodOptions { LastWeek = true }, out var lastFrom, out var lastTo, out _);

Expand Down Expand Up @@ -176,4 +181,72 @@ public void LastMonth_CoversFirstToLastDayOfPreviousMonth()
Assert.Equal(from.AddMonths(1).AddDays(-1), to);
Assert.Equal(DateTime.Today.Month, from.AddMonths(1).Month);
}

// --- current-* aliases -------------------------------------------------

[Fact]
public void CurrentMonth_ResolvesIdenticallyToMonth()
{
PeriodResolver.TryResolve(new FakePeriodOptions { Month = true }, out var mFrom, out var mTo, out _);
var ok = PeriodResolver.TryResolve(new FakePeriodOptions { CurrentMonth = true }, out var from, out var to, out _);

Assert.True(ok);
Assert.Equal(mFrom, from);
Assert.Equal(mTo, to);
}

[Fact]
public void CurrentWeek_ResolvesIdenticallyToWeek()
{
PeriodResolver.TryResolve(new FakePeriodOptions { Week = true }, out var wFrom, out var wTo, out _);
var ok = PeriodResolver.TryResolve(new FakePeriodOptions { CurrentWeek = true }, out var from, out var to, out _);

Assert.True(ok);
Assert.Equal(wFrom, from);
Assert.Equal(wTo, to);
}

[Fact]
public void CurrentMonth_AndMonth_AreMutuallyExclusive()
{
var opts = new FakePeriodOptions { Month = true, CurrentMonth = true };

var ok = PeriodResolver.TryResolve(opts, out _, out _, out var error);

Assert.False(ok);
Assert.Contains("mutually exclusive", error);
}

[Fact]
public void CurrentWeek_AndWeek_AreMutuallyExclusive()
{
var opts = new FakePeriodOptions { Week = true, CurrentWeek = true };

var ok = PeriodResolver.TryResolve(opts, out _, out _, out var error);

Assert.False(ok);
Assert.Contains("mutually exclusive", error);
}

[Fact]
public void CurrentMonth_WithFromOrTo_Fail()
{
var opts = new FakePeriodOptions { CurrentMonth = true, From = "2026/06/01" };

var ok = PeriodResolver.TryResolve(opts, out _, out _, out var error);

Assert.False(ok);
Assert.Contains("shortcuts cannot be used", error);
}

[Fact]
public void CurrentWeek_WithFromOrTo_Fail()
{
var opts = new FakePeriodOptions { CurrentWeek = true, To = "2026/06/30" };

var ok = PeriodResolver.TryResolve(opts, out _, out _, out var error);

Assert.False(ok);
Assert.Contains("shortcuts cannot be used", error);
}
}
66 changes: 62 additions & 4 deletions Timetracker.Tests/ResolveDateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ namespace Timetracker.Tests;
/// </summary>
public sealed class ResolveDateTests : IDisposable
{
public void Dispose() => ValidationUtils.Clock = TimeProvider.System;
public void Dispose()
{
ValidationUtils.Clock = TimeProvider.System;
ValidationUtils.WeekStartOverride = null;
}

private static void PinTo(int year, int month, int day)
=> ValidationUtils.Clock = new FixedClock(year, month, day);
Expand All @@ -31,10 +35,11 @@ public void ResolveDate_Yesterday_UsesTheClock()
}

[Fact]
public void ResolveCurrentWeek_MidWeek_ReturnsThatWeeksMondayToSunday()
public void ResolveCurrentWeek_MondayStart_MidWeek_ReturnsMondayToSunday()
{
// 2026-03-18 is a Wednesday.
PinTo(2026, 3, 18);
ValidationUtils.WeekStartOverride = DayOfWeek.Monday;

var (from, to) = ValidationUtils.ResolveCurrentWeek();

Expand All @@ -43,10 +48,11 @@ public void ResolveCurrentWeek_MidWeek_ReturnsThatWeeksMondayToSunday()
}

[Fact]
public void ResolveCurrentWeek_OnSunday_ReturnsTheEndingWeek()
public void ResolveCurrentWeek_MondayStart_OnSunday_ReturnsTheEndingWeek()
{
// 2026-03-22 is a Sunday — the week should still be 03-16..03-22.
PinTo(2026, 3, 22);
ValidationUtils.WeekStartOverride = DayOfWeek.Monday;

var (from, to) = ValidationUtils.ResolveCurrentWeek();

Expand All @@ -55,16 +61,68 @@ public void ResolveCurrentWeek_OnSunday_ReturnsTheEndingWeek()
}

[Fact]
public void ResolveLastWeek_ReturnsPreviousMondayToSunday()
public void ResolveLastWeek_MondayStart_ReturnsPreviousMondayToSunday()
{
PinTo(2026, 3, 18);
ValidationUtils.WeekStartOverride = DayOfWeek.Monday;

var (from, to) = ValidationUtils.ResolveLastWeek();

Assert.Equal(new DateTime(2026, 3, 9), from);
Assert.Equal(new DateTime(2026, 3, 15), to);
}

[Fact]
public void ResolveCurrentWeek_SundayStart_MidWeek_ReturnsSundayToSaturday()
{
// 2026-03-18 is a Wednesday; week should be 03-15 (Sun) .. 03-21 (Sat).
PinTo(2026, 3, 18);
ValidationUtils.WeekStartOverride = DayOfWeek.Sunday;

var (from, to) = ValidationUtils.ResolveCurrentWeek();

Assert.Equal(new DateTime(2026, 3, 15), from); // Sunday
Assert.Equal(new DateTime(2026, 3, 21), to); // Saturday
}

[Fact]
public void ResolveCurrentWeek_SundayStart_OnSunday_StartsOnThatDay()
{
// 2026-03-15 is a Sunday — should be the start of the week.
PinTo(2026, 3, 15);
ValidationUtils.WeekStartOverride = DayOfWeek.Sunday;

var (from, to) = ValidationUtils.ResolveCurrentWeek();

Assert.Equal(new DateTime(2026, 3, 15), from);
Assert.Equal(new DateTime(2026, 3, 21), to);
}

[Fact]
public void ResolveCurrentWeek_SundayStart_OnSaturday_ReturnsCurrentWeek()
{
// 2026-03-21 is a Saturday — last day of the Sun-start week.
PinTo(2026, 3, 21);
ValidationUtils.WeekStartOverride = DayOfWeek.Sunday;

var (from, to) = ValidationUtils.ResolveCurrentWeek();

Assert.Equal(new DateTime(2026, 3, 15), from);
Assert.Equal(new DateTime(2026, 3, 21), to);
}

[Fact]
public void ResolveLastWeek_SundayStart_ReturnsPreviousSundayToSaturday()
{
PinTo(2026, 3, 18);
ValidationUtils.WeekStartOverride = DayOfWeek.Sunday;

var (from, to) = ValidationUtils.ResolveLastWeek();

Assert.Equal(new DateTime(2026, 3, 8), from); // Sunday
Assert.Equal(new DateTime(2026, 3, 14), to); // Saturday
}

[Fact]
public void ResolveCurrentMonth_ReturnsFirstToLastDay()
{
Expand Down
5 changes: 4 additions & 1 deletion Timetracker/Options/ConfigOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class ConfigOptions
[Option("reset", Required = false, HelpText = "Remove all local configuration and activity cache files.")]
public bool Reset { get; set; }

[Option("border", Required = false, HelpText = "Table border style for list output: minimal (default), square, or markdown.")]
[Option("border", Required = false, HelpText = "Table border style for list output: minimal (default), square, markdown, or ascii.")]
public string Border { get; set; }

[Option("week-start", Required = false, HelpText = "First day of the week for --week and --last-week shortcuts: sunday (default) or monday.")]
public string WeekStart { get; set; }
}
2 changes: 2 additions & 0 deletions Timetracker/Options/IPeriodOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public interface IPeriodOptions
bool Week { get; }
bool LastWeek { get; }
bool Month { get; }
bool CurrentMonth { get; }
bool LastMonth { get; }
bool CurrentWeek { get; }
}
12 changes: 11 additions & 1 deletion Timetracker/Options/InteractiveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
namespace Timetracker.Options;

[Verb("interactive", HelpText = "Interactively browse, edit and delete time entries.")]
public class InteractiveOptions
public class InteractiveOptions : IPeriodOptions
{
[Option('p', "period", Required = false, HelpText = "Specific month in YYYY/MM format (e.g., 2026/06).")]
public string Period { get; set; }

// Interactive mode does not support explicit date ranges.
string IPeriodOptions.From => null;
string IPeriodOptions.To => null;

[Option('w', "work-item", Required = false, HelpText = "Filter entries by Work Item ID.")]
public int? WorkItemId { get; set; }

Expand All @@ -20,12 +24,18 @@ public class InteractiveOptions
[Option("week", Required = false, HelpText = "Show entries for the current week.")]
public bool Week { get; set; }

[Option("current-week", Required = false, HelpText = "Alias for --week. Show entries for the current week.")]
public bool CurrentWeek { get; set; }

[Option("last-week", Required = false, HelpText = "Show entries for the previous week.")]
public bool LastWeek { get; set; }

[Option("month", Required = false, HelpText = "Show entries for the current month.")]
public bool Month { get; set; }

[Option("current-month", Required = false, HelpText = "Alias for --month. Show entries for the current month.")]
public bool CurrentMonth { get; set; }

[Option("last-month", Required = false, HelpText = "Show entries for the previous month.")]
public bool LastMonth { get; set; }
}
6 changes: 6 additions & 0 deletions Timetracker/Options/ListOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class ListOptions : IPeriodOptions
[Option("month", Required = false, HelpText = "Show entries for the current month. Cannot be used with --from, --to, --period or other shortcuts.")]
public bool Month { get; set; }

[Option("current-month", Required = false, HelpText = "Alias for --month. Show entries for the current month.")]
public bool CurrentMonth { get; set; }

[Option("last-month", Required = false, HelpText = "Show entries for the previous month. Cannot be used with --from, --to, --period or other shortcuts.")]
public bool LastMonth { get; set; }

Expand All @@ -38,6 +41,9 @@ public class ListOptions : IPeriodOptions
[Option("week", Required = false, HelpText = "Show entries for the current week (Monday to Sunday). Cannot be used with --from, --to or --period.")]
public bool Week { get; set; }

[Option("current-week", Required = false, HelpText = "Alias for --week. Show entries for the current week (Monday to Sunday).")]
public bool CurrentWeek { get; set; }

[Option("last-week", Required = false, HelpText = "Show entries for the previous week (Monday to Sunday). Cannot be used with --from, --to or --period.")]
public bool LastWeek { get; set; }
}
10 changes: 8 additions & 2 deletions Timetracker/Options/SummaryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace Timetracker.Options;
[Verb("summary", HelpText = "Show a daily summary of logged hours for a given period.")]
public class SummaryOptions : IPeriodOptions
{
[Option('f', "from", Required = false, HelpText = "Start date in the format YYYY/MM/DD, 'today' or 'yesterday'. Defaults to today.")]
[Option('f', "from", Required = false, HelpText = "Start date in the format YYYY/MM/DD, 'today' or 'yesterday'. Defaults to the start of the current month.")]
public string From { get; set; }

[Option('t', "to", Required = false, HelpText = "End date in the format YYYY/MM/DD, 'today' or 'yesterday'. Defaults to today.")]
[Option('t', "to", Required = false, HelpText = "End date in the format YYYY/MM/DD, 'today' or 'yesterday'. Defaults to the end of the current month.")]
public string To { get; set; }

[Option('p', "period", Required = false, HelpText = "Summarize a specific month in the format YYYY/MM (e.g., 2026/06). Cannot be used with --from, --to or week/month shortcuts.")]
Expand All @@ -17,6 +17,9 @@ public class SummaryOptions : IPeriodOptions
[Option("month", Required = false, HelpText = "Summarize the current month. Cannot be used with --from, --to, --period or other shortcuts.")]
public bool Month { get; set; }

[Option("current-month", Required = false, HelpText = "Alias for --month. Summarize the current month.")]
public bool CurrentMonth { get; set; }

[Option("last-month", Required = false, HelpText = "Summarize the previous month. Cannot be used with --from, --to, --period or other shortcuts.")]
public bool LastMonth { get; set; }

Expand All @@ -29,6 +32,9 @@ public class SummaryOptions : IPeriodOptions
[Option("week", Required = false, HelpText = "Summarize the current week (Monday to Sunday). Cannot be used with --from, --to or --period.")]
public bool Week { get; set; }

[Option("current-week", Required = false, HelpText = "Alias for --week. Summarize the current week (Monday to Sunday).")]
public bool CurrentWeek { get; set; }

[Option("last-week", Required = false, HelpText = "Summarize the previous week (Monday to Sunday). Cannot be used with --from, --to or --period.")]
public bool LastWeek { get; set; }

Expand Down
Loading
Loading