Skip to content

Commit

Permalink
fix dst bug in rangePerDates (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
matslina authored Jan 2, 2024
1 parent e0fa6c6 commit cdba1e2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions static.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
26 changes: 25 additions & 1 deletion whitebox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cdba1e2

Please sign in to comment.