floraison / fugit

time tools (cron, parsing, durations, ...) for Ruby, rufus-scheduler, and flor
MIT License
355 stars 29 forks source link

cron #previous_time loop breaker issue: modulo plus offset #47

Closed ticky closed 3 years ago

ticky commented 3 years ago

Issue description

I am not fully confident in what the combination of these two syntaxes is supposed to mean, and the +2 syntax isn’t documented fully in the README, but I believe this user input would be interpreted as every odd Tuesday but only after the first two odd Tuesdays of a month? Which seems to mean “never,” and thus warrant an out of range error.

How to reproduce

require 'fugit'
c = Fugit.parse('0 8 * * 1%2+2')
p c.next_time

Error and error backtrace (if any)

(This should look like:

Traceback (most recent call last):
       16: from /Users/ticky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
       15: from /Users/ticky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
       14: from /Users/ticky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
       13: from /Users/ticky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
       12: from /Users/ticky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
       11: from /Users/ticky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
       10: from /Users/ticky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
        9: from /Users/ticky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
        8: from /Users/ticky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
        7: from /Users/ticky/.rbenv/versions/2.6.5/bin/irb:23:in `<top (required)>'
        6: from /Users/ticky/.rbenv/versions/2.6.5/bin/irb:23:in `load'
        5: from /Users/ticky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/irb-1.2.3/exe/irb:11:in `<top (required)>'
        4: from (irb):4
        3: from /Users/ticky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fugit-1.4.1/lib/fugit/cron.rb:242:in `next_time'
        2: from /Users/ticky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fugit-1.4.1/lib/fugit/cron.rb:242:in `loop'
        1: from /Users/ticky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fugit-1.4.1/lib/fugit/cron.rb:244:in `block in next_time'
RuntimeError (too many loops for "0 8 * * 1%2+2" #next_time, breaking, cron expression most likely invalid (Feb 30th like?), please fill an issue at https://git.io/fjJC9)

)

Expected behaviour

It ought to either return a valid value, or give a descriptive error rather than the loop error.

Context

Darwin Kinzie.home.drac.at 20.1.0 Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:11 PDT 2020; root:xnu-7195.50.7~2/RELEASE_X86_64 x86_64
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
[:env_tz, nil]
(secs:1606760366.633137,utc~:"2020-11-30 18:19:26.6331369876861572",ltz~:"MST")
(etz:nil,tnz:"PST",tziv:"1.2.8",tzidv:nil,rv:"2.6.5",rp:"x86_64-darwin18",win:false,rorv:nil,astz:nil,eov:"1.2.4",eotnz:#<TZInfo::TimezoneProxy: America/Dawson>,eotnfz:"-0700",eotlzn:"America/Dawson",eotnfZ:"MST",debian:nil,centos:nil,osx:"zoneinfo/America/Vancouver")
"1.4.1"

Additional context

Like #30, this is from in-the-wild user input. 😃

jmettraux commented 3 years ago

Thanks a ton for the report!

Give me a few days to ponder a better interception/information. Year end crunch :-(

jmettraux commented 3 years ago

Sorry, I forgot about this one. One of your contractors reminded me of it. I will look into it again.

jmettraux commented 3 years ago

I think I solved the problem. I will release 1.4.5 tomorrow, unless you point me at corner cases I have overlooked.

Please accept my apologies for forgetting your issue.

cc @karensawrey

jmettraux commented 3 years ago

Released 1.4.5

Thanks a lot!

karensawrey commented 3 years ago

Thank you, @jmettraux! Highly appreciated! Thank you kindly for working on fugit and for dedicating your time to solving this issue.

ticky commented 3 years ago

All good @jmettraux, I very much appreciate your help on these! :)