floraison / fugit

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

Incorrect #rough_frequency and #brute_frequency for '0 */5 * * *' #58

Closed mscrivo closed 3 years ago

mscrivo commented 3 years ago

Issue description

Parsing of the above cron schedule can't seem to be parsed properly:

Rufus::Scheduler.parse('0 */5 * * *').rough_frequency
=> 14400
# even if we try `brute_schedule` it's off:
Rufus::Scheduler.parse('0 */5 * * *').brute_frequency
=> #<Fugit::Cron::Frequency:0x0000000124f5f440 @delta_max=21600, @delta_min=14400, @occurrences=1822, @span=31482000.0, @span_years=0.9982876712328768, @yearly_occurrences=1825.1252144082332>

value should be: 18000

Parsing of 0 */3 * * *, 0 */4 * * * and 0 */6 * * * work fine it seems.

How to reproduce

See above

Expected behaviour

Seems like a simple cron schedule like this, should be able to be parsed properly? If neither of these methods work, what other way is there to get an accurate frequency?

jmettraux commented 3 years ago

0 */5 * * * means it will run at 00:00, 05:00, 10:00, 15:00, 20:00. There is a 4 hours interval between 20:00 and 04:00. 4 * 60 * 60 = 14_400.

It parses properly and it gives good enough frequencies.