Skip to content

Commit 59f645e

Browse files
committed
Don't skip crons when time jumps fwd due to DST
1 parent bc59245 commit 59f645e

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

spec.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,16 @@ WRAP:
140140
added = true
141141
t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), 0, 0, 0, loc)
142142
}
143+
prev := t
143144
t = t.Add(1 * time.Hour)
144-
145+
// ISC cron behavior: If time was adjusted one hour forward, those jobs
146+
// that would have run in the interval that has been skipped will be run
147+
// immediately.
148+
if t.Hour()-prev.Hour() == 2 {
149+
if 1<<uint(t.Hour()-1)&s.Hour > 0 {
150+
break
151+
}
152+
}
145153
if t.Hour() == 0 {
146154
goto WRAP
147155
}

spec_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestNext(t *testing.T) {
111111
{"Mon Jul 9 23:35 2012", "0 0 0 29 Feb ?", "Mon Feb 29 00:00 2016"},
112112

113113
// Daylight savings time 2am EST (-5) -> 3am EDT (-4)
114-
{"2012-03-11T00:00:00-0500", "TZ=America/New_York 0 30 2 11 Mar ?", "2013-03-11T02:30:00-0400"},
114+
{"2012-03-11T00:00:00-0500", "TZ=America/New_York 0 30 2 11 Mar ?", "2012-03-11T03:30:00-0400"},
115115

116116
// hourly job
117117
{"2012-03-11T00:00:00-0500", "TZ=America/New_York 0 0 * * * ?", "2012-03-11T01:00:00-0500"},
@@ -129,8 +129,8 @@ func TestNext(t *testing.T) {
129129
{"2012-03-11T00:00:00-0500", "TZ=America/New_York 0 0 1 * * ?", "2012-03-11T01:00:00-0500"},
130130
{"2012-03-11T01:00:00-0500", "TZ=America/New_York 0 0 1 * * ?", "2012-03-12T01:00:00-0400"},
131131

132-
// 2am nightly job (skipped)
133-
{"2012-03-11T00:00:00-0500", "TZ=America/New_York 0 0 2 * * ?", "2012-03-12T02:00:00-0400"},
132+
// Daylight savings time 2am EST (-5) -> 3am EDT (-4)
133+
{"2012-03-11T00:00:00-0500", "TZ=America/New_York 0 0 2 * * ?", "2012-03-11T03:00:00-0400"},
134134

135135
// Daylight savings time 2am EDT (-4) => 1am EST (-5)
136136
{"2012-11-04T00:00:00-0400", "TZ=America/New_York 0 30 2 04 Nov ?", "2012-11-04T02:30:00-0500"},

0 commit comments

Comments
 (0)