Preserve civil daypart clocks across DST
This commit is contained in:
@@ -33,3 +33,72 @@ func TestClockWindowHandlesOvernight(t *testing.T) {
|
||||
t.Fatalf("End = %s, want 2026-05-30T06:00", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClockWindowUsesCivilTimeAcrossDSTTransitions(t *testing.T) {
|
||||
location, err := LoadLocation("America/Chicago")
|
||||
if err != nil {
|
||||
t.Fatalf("LoadLocation() error = %v", err)
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
date time.Time
|
||||
start string
|
||||
end string
|
||||
wantStart string
|
||||
wantEnd string
|
||||
}{
|
||||
{
|
||||
name: "spring-forward daytime",
|
||||
date: time.Date(2026, time.March, 8, 12, 0, 0, 0, location),
|
||||
start: "00:00",
|
||||
end: "06:00",
|
||||
wantStart: "2026-03-08T00:00:00-06:00",
|
||||
wantEnd: "2026-03-08T06:00:00-05:00",
|
||||
},
|
||||
{
|
||||
name: "fall-back daytime",
|
||||
date: time.Date(2026, time.November, 1, 12, 0, 0, 0, location),
|
||||
start: "00:00",
|
||||
end: "06:00",
|
||||
wantStart: "2026-11-01T00:00:00-05:00",
|
||||
wantEnd: "2026-11-01T06:00:00-06:00",
|
||||
},
|
||||
{
|
||||
name: "spring-forward overnight",
|
||||
date: time.Date(2026, time.March, 8, 12, 0, 0, 0, location),
|
||||
start: "22:00",
|
||||
end: "06:00",
|
||||
wantStart: "2026-03-08T22:00:00-05:00",
|
||||
wantEnd: "2026-03-09T06:00:00-05:00",
|
||||
},
|
||||
{
|
||||
name: "spring-forward end of day",
|
||||
date: time.Date(2026, time.March, 8, 12, 0, 0, 0, location),
|
||||
start: "18:00",
|
||||
end: "24:00",
|
||||
wantStart: "2026-03-08T18:00:00-05:00",
|
||||
wantEnd: "2026-03-09T00:00:00-05:00",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
start, err := ParseClock(tt.start)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseClock(%q) error = %v", tt.start, err)
|
||||
}
|
||||
end, err := ParseClock(tt.end)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseClock(%q) error = %v", tt.end, err)
|
||||
}
|
||||
|
||||
window := ClockWindow(tt.date, location, start, end)
|
||||
if got := window.Start.Format(time.RFC3339); got != tt.wantStart {
|
||||
t.Fatalf("Start = %s, want %s", got, tt.wantStart)
|
||||
}
|
||||
if got := window.End.Format(time.RFC3339); got != tt.wantEnd {
|
||||
t.Fatalf("End = %s, want %s", got, tt.wantEnd)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user