Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dst bug in rangePerDates #15

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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