parse-cron
parse-cron copied to clipboard
CronParser#last gives incorrect time
The following produces an incorrect last time:
cron_parser = CronParser.new('* * * * *')
p "Now: #{Time.now}"
p "Last: #{cron_parser.last}"
p "Next: #{cron_parser.next}"
The output is
"Now: 2014-05-12 13:15:42 -0600"
"Last: 2014-05-12 13:14:00 -0600"
"Next: 2014-05-12 13:16:00 -0600"
But would expect the output to be (notice 13:15:00 in the "Last:" line)
"Now: 2014-05-12 13:15:42 -0600"
"Last: 2014-05-12 13:15:00 -0600"
"Next: 2014-05-12 13:16:00 -0600"
I had this same issue and I fixed it with the following diff. From what I can tell it works fine.
--- a/lib/cron_parser.rb
+++ b/lib/cron_parser.rb
@@ -126,7 +126,10 @@ class CronParser
end
# always nudge the minute
- nudge_minute(t, :last)
+ unless time_specs[:minute][0].include?(t.min)
+ nudge_minute(t, :last)
+ end
+
t.to_time
t = t.to_time
if num > 1
Fixed in pull request #38