Add forecast daypart derivation
This commit is contained in:
35
internal/timeutil/periods_test.go
Normal file
35
internal/timeutil/periods_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package timeutil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPeriodOverlapUsesHalfOpenIntervals(t *testing.T) {
|
||||
start := time.Date(2026, 5, 29, 6, 0, 0, 0, time.UTC)
|
||||
left := Period{Start: start, End: start.Add(time.Hour)}
|
||||
touching := Period{Start: start.Add(time.Hour), End: start.Add(2 * time.Hour)}
|
||||
overlapping := Period{Start: start.Add(30 * time.Minute), End: start.Add(90 * time.Minute)}
|
||||
|
||||
if left.Overlaps(touching) {
|
||||
t.Fatal("touching half-open periods overlap, want false")
|
||||
}
|
||||
if !left.Overlaps(overlapping) {
|
||||
t.Fatal("overlapping periods do not overlap, want true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClockWindowHandlesOvernight(t *testing.T) {
|
||||
location := time.FixedZone("Test", -5*60*60)
|
||||
date := time.Date(2026, 5, 29, 12, 0, 0, 0, location)
|
||||
start, _ := ParseClock("22:00")
|
||||
end, _ := ParseClock("06:00")
|
||||
|
||||
window := ClockWindow(date, location, start, end)
|
||||
if got := window.Start.Format("2006-01-02T15:04"); got != "2026-05-29T22:00" {
|
||||
t.Fatalf("Start = %s, want 2026-05-29T22:00", got)
|
||||
}
|
||||
if got := window.End.Format("2006-01-02T15:04"); got != "2026-05-30T06:00" {
|
||||
t.Fatalf("End = %s, want 2026-05-30T06:00", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user