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

weekday cron does not run today when started before execution time #52

Closed
grosser opened this issue Feb 9, 2021 · 5 comments
Closed
Assignees

Comments

@grosser
Copy link
Contributor

grosser commented Feb 9, 2021

fugit 1.4.2

the second Tuesday of the week was today, we started the cron earlier today, but it never executed, because it thinks the next execution is next month and not today ... so seems like the weekday calculation needs to take time of day into account

TZ=utc bundle exec ruby -r bundler/setup -r fugit -e 'puts Time.now'
2021-02-09 17:41:10 +0000
TZ=utc bundle exec ruby -r bundler/setup -r fugit -e 'puts Fugit.do_parse_cron("55 18 * * 2#1").next_time.to_s'
2021-03-02 18:55:00 +0000
  it "calculates weekdays correctly when starting at the same day" do
    Time.stubs(:now).returns(Time.parse("2021-02-02 00:00:00")) # tuesday morning
    Fugit.do_parse_cron("59 23 * * 1").next_time.to_s.must_equal "2021-02-02 23:59:00 -0000"
  end
@jmettraux jmettraux self-assigned this Feb 9, 2021
@jmettraux
Copy link
Member

  it "calculates weekdays correctly when starting at the same day" do
    Time.stubs(:now).returns(Time.parse("2021-02-02 00:00:00")) # tuesday morning
    Fugit.do_parse_cron("59 23 * * 2").next_time.to_s.must_equal "2021-02-02 23:59:00 -0000"
  end

since 2021-02-02 is a Tuesday.

jmettraux added a commit that referenced this issue Feb 9, 2021
@jmettraux
Copy link
Member

The spec you gave me, when adapted, goes green.

OK, if I look at the initial problem explanation, 2021-02-09 is the second Tuesday of the month, not the first. So I think that fugit is right.

At 2021-02-09 17:41:10, given "55 18 * * 2#1", the next first Tuesday of the month at 18:55 is "2021-03-02 18:55".

Did I misunderstand you?

@grosser
Copy link
Contributor Author

grosser commented Feb 9, 2021

my initial case was second tuesday, I tried to dumb it down to make the spec simpler 🤦

2021-02-09 17:41:10 + "55 18 * * 2#1", should come out as is "2021-02-09 18:55" since it is currently the second Tuesday and not yet 18:55

@jmettraux
Copy link
Member

jmettraux commented Feb 9, 2021

2021-02-09 17:41:10 + "55 18 * * 2#1", should come out as is "2021-02-09 18:55" since it is currently the second Tuesday and not yet 18:55

No, "2#1" means "first Tuesday of the month", not "second Tuesday of the month".

https://github.com/floraison/fugit#the-hash-extension

@grosser
Copy link
Contributor Author

grosser commented Feb 9, 2021

yeah you are correct ... so something happened on the first tuesday and I though it was supposed to come today ... thx for looking into it, sorry for the noise 😞

@grosser grosser closed this as completed Feb 9, 2021
jmettraux added a commit that referenced this issue Feb 9, 2021
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

2 participants