cronish
cronish copied to clipboard
Incorrect calculation of nextTime
Hi, I'm having this problem with cronish:
scala> val tests = List(
| "every day at 17:30 on Monday to Friday",
| "every day at 17:30"
| ).zipWithIndex.foreach { t =>
| val (test, run) = t
|
| val current = Scalendar.now
| val millis = test.cron.nextFrom(current)
| println("%d (%s): %s" format(run, test, current))
| println("%d (%s): %s" format(run, test, Scalendar(current.time + millis)))
| }
0 (every day at 17:30 on Monday to Friday): 06/10/2013 17:08:09
0 (every day at 17:30 on Monday to Friday): 06/11/2013 17:30:00
1 (every day at 17:30): 06/10/2013 17:08:09
1 (every day at 17:30): 06/10/2013 17:30:00
Given that 06/10 is a Monday, shouldn't the .nextFrom(current)
for the example "0" above actually return 06/10/2013 17:30:00
?
If you look at example "1" which doesn't specify a day of the week, it's calculated correctly.
Yep, that does look incorrect. Thanks for spotting that.
I have traced back the issue to the following line: cron.scala#L193
cal.inWeek(f + 1) > cal
should actually be cal.inWeek(f + 1) >= cal
in order to consider also the current day as a valid candidate.
fixed by #20 but still not release