@@ -113,21 +113,14 @@ func Calculate(now time.Time, schedule config.ScheduleConfig) (time.Time, time.D
113
113
}
114
114
115
115
// Find the hour:minute (within the tolerance) scheduled check-in which contains the current time.
116
- current := now .Format ("15:04" )
117
-
118
116
for idx , hourminute := range times {
119
- low := hourminute .Add (- 1 * tolerance ).Format ("15:04" )
120
- high := hourminute .Add (tolerance ).Format ("15:04" )
121
-
122
117
scheduledCheckIn := time .Date (now .Year (), now .Month (), now .Day (), hourminute .Hour (), hourminute .Minute (), 0 , 0 , now .Location ())
123
118
124
- // If we're before all scheduled check-ins today
125
- if idx == 0 && current < low {
126
- return scheduledCheckIn , scheduledCheckIn .Sub (now ) + tolerance , nil
127
- }
119
+ low := scheduledCheckIn .Add (- 1 * tolerance )
120
+ high := scheduledCheckIn .Add (tolerance )
128
121
129
122
// The current time must be within our scheduled time +/- the tolerance
130
- if low <= current && high >= current {
123
+ if low . Before ( now ) && now . Before ( high ) {
131
124
// Based on the scheduledCheckIn calculate how long to sleep for
132
125
var nextCheckIn time.Time
133
126
if len (times ) > idx + 1 {
@@ -145,9 +138,14 @@ func Calculate(now time.Time, schedule config.ScheduleConfig) (time.Time, time.D
145
138
146
139
return scheduledCheckIn , next .Sub (now ) + tolerance , nil
147
140
}
141
+
142
+ // We've reached the next possible check-in (the low is greater than now)
143
+ if now .Before (low ) {
144
+ return scheduledCheckIn , high .Sub (now ), nil
145
+ }
148
146
}
149
147
150
- // Find the earliest time tomorrow
148
+ // Find the earliest time tomorrow, since we were late to all of them.
151
149
start := time .Date (now .Year (), now .Month (), now .Day (), times [0 ].Hour (), times [0 ].Minute (), 0 , 0 , now .Location ())
152
150
future := time .Date (now .Year (), now .Month (), now .Day (), start .Hour (), start .Minute (), 0 , 0 , now .Location ())
153
151
0 commit comments