...
1 package cron
2
3 import "time"
4
5
6
7 type ConstantDelaySchedule struct {
8 Delay time.Duration
9 }
10
11
12
13
14 func Every(duration time.Duration) ConstantDelaySchedule {
15 if duration < time.Second {
16 duration = time.Second
17 }
18 return ConstantDelaySchedule{
19 Delay: duration - time.Duration(duration.Nanoseconds())%time.Second,
20 }
21 }
22
23
24
25 func (schedule ConstantDelaySchedule) Next(t time.Time) time.Time {
26 return t.Add(schedule.Delay - time.Duration(t.Nanosecond())*time.Nanosecond)
27 }
28
View as plain text