|
@@ -8,6 +8,7 @@ import (
|
|
|
// traditional crontab specification. It is computed initially and stored as bit sets.
|
|
// traditional crontab specification. It is computed initially and stored as bit sets.
|
|
|
type SpecSchedule struct {
|
|
type SpecSchedule struct {
|
|
|
Second, Minute, Hour, Dom, Month, Dow uint64
|
|
Second, Minute, Hour, Dom, Month, Dow uint64
|
|
|
|
|
+ Location *time.Location
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// bounds provides a range of acceptable values (plus a map of name to value).
|
|
// bounds provides a range of acceptable values (plus a map of name to value).
|
|
@@ -63,6 +64,11 @@ func (s *SpecSchedule) Next(t time.Time) time.Time {
|
|
|
// of the field list (since it is necessary to re-verify previous field
|
|
// of the field list (since it is necessary to re-verify previous field
|
|
|
// values)
|
|
// values)
|
|
|
|
|
|
|
|
|
|
+ // Convert the given time into the schedule's timezone.
|
|
|
|
|
+ // Save the original timezone so we can convert back after we find a time.
|
|
|
|
|
+ origLocation := t.Location()
|
|
|
|
|
+ t = t.In(s.Location)
|
|
|
|
|
+
|
|
|
// Start at the earliest possible time (the upcoming second).
|
|
// Start at the earliest possible time (the upcoming second).
|
|
|
t = t.Add(1*time.Second - time.Duration(t.Nanosecond())*time.Nanosecond)
|
|
t = t.Add(1*time.Second - time.Duration(t.Nanosecond())*time.Nanosecond)
|
|
|
|
|
|
|
@@ -84,7 +90,7 @@ WRAP:
|
|
|
if !added {
|
|
if !added {
|
|
|
added = true
|
|
added = true
|
|
|
// Otherwise, set the date at the beginning (since the current time is irrelevant).
|
|
// Otherwise, set the date at the beginning (since the current time is irrelevant).
|
|
|
- t = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
|
|
|
|
|
|
|
+ t = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, s.Location)
|
|
|
}
|
|
}
|
|
|
t = t.AddDate(0, 1, 0)
|
|
t = t.AddDate(0, 1, 0)
|
|
|
|
|
|
|
@@ -98,7 +104,7 @@ WRAP:
|
|
|
for !dayMatches(s, t) {
|
|
for !dayMatches(s, t) {
|
|
|
if !added {
|
|
if !added {
|
|
|
added = true
|
|
added = true
|
|
|
- t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
|
|
|
|
|
|
|
+ t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, s.Location)
|
|
|
}
|
|
}
|
|
|
t = t.AddDate(0, 0, 1)
|
|
t = t.AddDate(0, 0, 1)
|
|
|
|
|
|
|
@@ -110,7 +116,7 @@ WRAP:
|
|
|
for 1<<uint(t.Hour())&s.Hour == 0 {
|
|
for 1<<uint(t.Hour())&s.Hour == 0 {
|
|
|
if !added {
|
|
if !added {
|
|
|
added = true
|
|
added = true
|
|
|
- t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), 0, 0, 0, t.Location())
|
|
|
|
|
|
|
+ t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), 0, 0, 0, s.Location)
|
|
|
}
|
|
}
|
|
|
t = t.Add(1 * time.Hour)
|
|
t = t.Add(1 * time.Hour)
|
|
|
|
|
|
|
@@ -122,7 +128,7 @@ WRAP:
|
|
|
for 1<<uint(t.Minute())&s.Minute == 0 {
|
|
for 1<<uint(t.Minute())&s.Minute == 0 {
|
|
|
if !added {
|
|
if !added {
|
|
|
added = true
|
|
added = true
|
|
|
- t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), 0, 0, t.Location())
|
|
|
|
|
|
|
+ t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), 0, 0, s.Location)
|
|
|
}
|
|
}
|
|
|
t = t.Add(1 * time.Minute)
|
|
t = t.Add(1 * time.Minute)
|
|
|
|
|
|
|
@@ -134,7 +140,7 @@ WRAP:
|
|
|
for 1<<uint(t.Second())&s.Second == 0 {
|
|
for 1<<uint(t.Second())&s.Second == 0 {
|
|
|
if !added {
|
|
if !added {
|
|
|
added = true
|
|
added = true
|
|
|
- t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
|
|
|
|
|
|
+ t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), 0, s.Location)
|
|
|
}
|
|
}
|
|
|
t = t.Add(1 * time.Second)
|
|
t = t.Add(1 * time.Second)
|
|
|
|
|
|
|
@@ -143,7 +149,7 @@ WRAP:
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return t
|
|
|
|
|
|
|
+ return t.In(origLocation)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// dayMatches returns true if the schedule's day-of-week and day-of-month
|
|
// dayMatches returns true if the schedule's day-of-week and day-of-month
|