mirror of
https://github.com/muety/wakapi.git
synced 2025-12-05 22:20:24 -08:00
fix: infinite loop caused by timezone weirdness in date range splitting (resolve #779)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -42,6 +42,11 @@ func SplitRangeByDays(from time.Time, to time.Time) [][]time.Time {
|
||||
|
||||
for t1 := from; t1.Before(to); {
|
||||
t2 := datetime.BeginOfDay(t1).AddDate(0, 0, 1)
|
||||
// https://github.com/muety/wakapi/issues/779
|
||||
if t2 == t1 {
|
||||
t1 = datetime.BeginOfDay(t1).Add(24 * time.Hour)
|
||||
continue
|
||||
}
|
||||
if t2.After(to) {
|
||||
t2 = to
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ var (
|
||||
tzUtc *time.Location
|
||||
tzCet *time.Location
|
||||
tzPst *time.Location
|
||||
tzCch *time.Location
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -19,6 +20,7 @@ func init() {
|
||||
tzUtc, _ = time.LoadLocation("UTC")
|
||||
tzCet, _ = time.LoadLocation("Europe/Berlin")
|
||||
tzPst, _ = time.LoadLocation("America/Los_Angeles")
|
||||
tzCch, _ = time.LoadLocation("America/Santiago")
|
||||
}
|
||||
|
||||
func TestDate_SplitRangeByDays(t *testing.T) {
|
||||
@@ -57,3 +59,11 @@ func TestDate_SplitRangeByDays(t *testing.T) {
|
||||
|
||||
assert.Len(t, result4, 0)
|
||||
}
|
||||
|
||||
func TestDate_SplitRangeByDays_DSTBug(t *testing.T) {
|
||||
// https://github.com/muety/wakapi/issues/779
|
||||
df1 := time.Date(2024, time.April, 29, 0, 0, 0, 0, tzCch)
|
||||
dt1 := time.Date(2025, time.April, 30, 2, 8, 25, 645879355, tzCch)
|
||||
result1 := SplitRangeByDays(df1, dt1)
|
||||
assert.Len(t, result1, 367)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user