floraison / fugit

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

Fugit::Nat.parse('every hour') returns nil #37

Closed shaicoleman closed 4 years ago

shaicoleman commented 4 years ago

Fugit::Nat.parse('every hour') returns nil Fugit::Nat.parse('every day') incorrectly returns '0 * * * *' which is every hour It would be great if it could handle some common cases without an explicit number.

require 'fugit'
['second', 'minute', 'hour', 'day', 'week', 'month', 'year'].each do |period|
  puts "every #{period}: #{Fugit::Nat.parse("every #{period}")&.to_cron_s}"
  puts "every 1 #{period}: #{Fugit::Nat.parse("every 1 #{period}")&.to_cron_s}"
end
every second: [MISSING]
every 1 second: * * * * * * [OK]
every minute: [MISSING]
every 1 minute: * * * * * [OK]
every hour: [MISSING]
every 1 hour: 0 * * * * [OK]
every day: 0 * * * * [INCORRECT]
every 1 day: 0 0 * * * [OK]
every week: [MISSING]
every 1 week: [MISSING]
every month: [MISSING]
every 1 month: 0 0 1 * * [OK]
every year: [MISSING]
every 1 year: [MISSING]

For every day/every week/every month/every year, it should mirror the behaviour of cron, i.e.

@yearly        Run once a year, "0 0 1 1 *".
@monthly       Run once a month, "0 0 1 * *".
@weekly        Run once a week, "0 0 * * 0".
@daily         Run once a day, "0 0 * * *".
@hourly        Run once an hour, "0 * * * *".

(above taken from man 5 crontab)

Thanks!

jmettraux commented 4 years ago

@shaicoleman Thanks for pointing out the incorrect "every day" and for underlining the crontab direction.

I will implement that.

jmettraux commented 4 years ago

@shaicoleman Hello, I've just released fugit 1.3.5.

I am closing this issue, but please tell me if there is anything wrong with the change.

Thanks again.