Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CronParser#last gives incorrect time #17

Open
jessebs opened this issue May 12, 2014 · 2 comments
Open

CronParser#last gives incorrect time #17

jessebs opened this issue May 12, 2014 · 2 comments

Comments

@jessebs
Copy link

jessebs commented May 12, 2014

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 jessebs changed the title CronParser#Last gives incorrect time CronParser#last gives incorrect time May 12, 2014
@nbalas
Copy link

nbalas commented Jul 18, 2014

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

sodapopcan added a commit to omx/parse-cron that referenced this issue Jul 6, 2017
@jonnynux
Copy link

jonnynux commented Oct 9, 2020

Fixed in pull request #38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants