parse-cron icon indicating copy to clipboard operation
parse-cron copied to clipboard

CronParser#last gives incorrect time

Open jessebs opened this issue 10 years ago • 2 comments

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"

jessebs avatar May 12 '14 19:05 jessebs

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

nbalas avatar Jul 18 '14 21:07 nbalas

Fixed in pull request #38

jonnynux avatar Oct 09 '20 09:10 jonnynux