|
|
@@ -416,66 +416,3 @@ func TestRoundToStartOfFollowingWeek(t *testing.T) {
|
|
|
t.Errorf("expected date to be rounded to the same sunday, got: %d, %s", roundedFromTuesday.Day(), roundedFromTuesday.Weekday().String())
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-func TestRoundToStartOfWeekMonday(t *testing.T) {
|
|
|
- testCases := map[string]struct {
|
|
|
- input time.Time
|
|
|
- expected time.Time
|
|
|
- }{
|
|
|
- "monday at midnight UTC is unchanged": {
|
|
|
- input: time.Date(2026, time.April, 13, 0, 0, 0, 0, time.UTC),
|
|
|
- expected: time.Date(2026, time.April, 13, 0, 0, 0, 0, time.UTC),
|
|
|
- },
|
|
|
- "monday mid-day rounds to start of same day": {
|
|
|
- input: time.Date(2026, time.April, 13, 12, 34, 56, 0, time.UTC),
|
|
|
- expected: time.Date(2026, time.April, 13, 0, 0, 0, 0, time.UTC),
|
|
|
- },
|
|
|
- "tuesday rounds back to preceding monday": {
|
|
|
- input: time.Date(2026, time.April, 7, 0, 0, 0, 0, time.UTC),
|
|
|
- expected: time.Date(2026, time.April, 6, 0, 0, 0, 0, time.UTC),
|
|
|
- },
|
|
|
- "wednesday rounds back to preceding monday": {
|
|
|
- input: time.Date(2026, time.April, 22, 23, 59, 59, 0, time.UTC),
|
|
|
- expected: time.Date(2026, time.April, 20, 0, 0, 0, 0, time.UTC),
|
|
|
- },
|
|
|
- "saturday rounds back to preceding monday": {
|
|
|
- input: time.Date(2026, time.April, 11, 12, 0, 0, 0, time.UTC),
|
|
|
- expected: time.Date(2026, time.April, 6, 0, 0, 0, 0, time.UTC),
|
|
|
- },
|
|
|
- "sunday rounds back six days to preceding monday": {
|
|
|
- input: time.Date(2026, time.April, 12, 12, 0, 0, 0, time.UTC),
|
|
|
- expected: time.Date(2026, time.April, 6, 0, 0, 0, 0, time.UTC),
|
|
|
- },
|
|
|
- "rounding back across a month boundary": {
|
|
|
- input: time.Date(2026, time.May, 2, 10, 0, 0, 0, time.UTC),
|
|
|
- expected: time.Date(2026, time.April, 27, 0, 0, 0, 0, time.UTC),
|
|
|
- },
|
|
|
- }
|
|
|
-
|
|
|
- for name, tc := range testCases {
|
|
|
- t.Run(name, func(t *testing.T) {
|
|
|
- got := RoundToStartOfWeekMonday(tc.input)
|
|
|
- if !got.Equal(tc.expected) {
|
|
|
- t.Errorf("RoundToStartOfWeekMonday(%s) = %s; want %s", tc.input, got, tc.expected)
|
|
|
- }
|
|
|
- if got.Weekday() != time.Monday {
|
|
|
- t.Errorf("RoundToStartOfWeekMonday(%s).Weekday() = %s; want Monday", tc.input, got.Weekday())
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func TestRoundToStartOfWeekMonday_PreservesLocation(t *testing.T) {
|
|
|
- // The helper rounds in the input's timezone so that callers using local
|
|
|
- // time windows observe a local-Monday boundary.
|
|
|
- boulder := time.FixedZone("Boulder", -7*60*60)
|
|
|
- in := time.Date(2026, time.April, 7, 1, 30, 0, 0, boulder)
|
|
|
- got := RoundToStartOfWeekMonday(in)
|
|
|
- want := time.Date(2026, time.April, 6, 0, 0, 0, 0, boulder)
|
|
|
- if !got.Equal(want) {
|
|
|
- t.Errorf("RoundToStartOfWeekMonday(%s) = %s; want %s", in, got, want)
|
|
|
- }
|
|
|
- if got.Location() != boulder {
|
|
|
- t.Errorf("expected location to be preserved; got %s", got.Location())
|
|
|
- }
|
|
|
-}
|