Skip to content

Commit c1f7270

Browse files
committed
tests: add more daylight savings time tests
1 parent 11cf7cf commit c1f7270

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

job_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ func TestDurationJob_next(t *testing.T) {
4444
}
4545

4646
func TestDailyJob_next(t *testing.T) {
47+
americaChicago, err := time.LoadLocation("America/Chicago")
48+
require.NoError(t, err)
49+
4750
tests := []struct {
4851
name string
4952
interval uint
@@ -84,6 +87,16 @@ func TestDailyJob_next(t *testing.T) {
8487
time.Date(2000, 1, 3, 5, 30, 0, 0, time.UTC),
8588
41 * time.Hour,
8689
},
90+
{
91+
"daily at time with daylight savings time",
92+
1,
93+
[]time.Time{
94+
time.Date(0, 0, 0, 5, 30, 0, 0, americaChicago),
95+
},
96+
time.Date(2023, 3, 11, 5, 30, 0, 0, americaChicago),
97+
time.Date(2023, 3, 12, 5, 30, 0, 0, americaChicago),
98+
23 * time.Hour,
99+
},
87100
}
88101

89102
for _, tt := range tests {
@@ -101,6 +114,9 @@ func TestDailyJob_next(t *testing.T) {
101114
}
102115

103116
func TestWeeklyJob_next(t *testing.T) {
117+
americaChicago, err := time.LoadLocation("America/Chicago")
118+
require.NoError(t, err)
119+
104120
tests := []struct {
105121
name string
106122
interval uint
@@ -132,6 +148,17 @@ func TestWeeklyJob_next(t *testing.T) {
132148
time.Date(2000, 1, 10, 5, 30, 0, 0, time.UTC),
133149
4 * 24 * time.Hour,
134150
},
151+
{
152+
"last run before daylight savings time, next run after",
153+
1,
154+
[]time.Weekday{time.Saturday},
155+
[]time.Time{
156+
time.Date(0, 0, 0, 5, 30, 0, 0, americaChicago),
157+
},
158+
time.Date(2023, 3, 11, 5, 30, 0, 0, americaChicago),
159+
time.Date(2023, 3, 18, 5, 30, 0, 0, americaChicago),
160+
7*24*time.Hour - time.Hour,
161+
},
135162
}
136163

137164
for _, tt := range tests {

0 commit comments

Comments
 (0)