diff --git a/static.go b/static.go index 1734dc8..3f99399 100644 --- a/static.go +++ b/static.go @@ -97,6 +97,9 @@ func gtfsDate(offset time.Duration) string { h := int(offset.Hours()) m := int(offset.Minutes()) - h*60 s := int(offset.Seconds()) - h*3600 - m*60 + if h < 0 || m < 0 || s < 0 { + return "" + } return fmt.Sprintf("%02d%02d%02d", h, m, s) } diff --git a/whitebox_test.go b/whitebox_test.go index 597c11a..6a2a774 100644 --- a/whitebox_test.go +++ b/whitebox_test.go @@ -116,7 +116,31 @@ func TestStaticRangePerDate(t *testing.T) { }, }, - // TODO: write a test of overflow with DST change + { + "overflow with change to standard time", + time.Date(2023, 11, 5, 00, 59, 0, 0, tzET), + 2 * time.Minute, + 29 * time.Hour, + []span{ + {"20231104", "245900", "250100"}, + {"20231105", "", "000100"}, + }, + }, + + { + "overflow with change to daylight savings", + time.Date(2023, 3, 12, 00, 59, 0, 0, tzET), + 2 * time.Minute, + 29 * time.Hour, + []span{ + {"20230311", "245900", "250100"}, + {"20230312", "015900", "020100"}, + }, + }, + + // NOTE: DST changes are really annoying. Very likely + // these tests are missing some edge cases. + } { t.Run(tc.Name, func(t *testing.T) { spans := rangePerDate(tc.Start, tc.Window, tc.Max)