floraison / fugit

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

cron: mon-thu not respected when L (last day of month) #5

Closed jmettraux closed 6 years ago

jmettraux commented 6 years ago

As reported by @mitnal in https://github.com/jmettraux/rufus-scheduler/issues/270

require 'rufus-scheduler'

#       June 2018
#  Su Mo Tu We Th Fr Sa
#                  1  2
#   3  4  5  6  7  8  9
#  10 11 12 13 14 15 16
#  17 18 19 20 21 22 23
#  24 25 26 27 28 29 30
#
#      July 2018
# Su Mo Tu We Th Fr Sa
#  1  2  3  4  5  6  7
#  8  9 10 11 12 13 14
# 15 16 17 18 19 20 21
# 22 23 24 25 26 27 28
# 29 30 31

p RUBY_VERSION
p RUBY_PLATFORM

ENV['TZ'] = 'Europe/Berlin'

puts
#now = EtOrbi.parse('2018-06-28 18:00:00 Europe/Berlin')
now = Rufus::Scheduler.parse('2018-06-28 18:00:00')
puts "now: " + now.to_s
puts
puts "  '0 9 -2 * *'  9am the second to last day of the month"
puts "3.4.2:  2018-07-29 09:00:00 +0200"
puts "3.5.0:  " + Rufus::Scheduler.parse('0 9 -2 * * Europe/Berlin').next_time(now).to_s
puts
puts "  '0 8 L * mon-thu'  8am the last day of the month (must be a mon or a thu)"
puts "3.4.2:  2018-07-31 08:00:00 +0200"
puts "3.5.0:  " + Rufus::Scheduler.parse('0 8 L * mon-thu Europe/Berlin').next_time(now).to_s
puts
puts "  '0 0 -5 * *' 0am fifth to last day of the month"
puts "3.4.2:  2018-07-26 00:00:00 +0200"
puts "3.5.0:  " + Rufus::Scheduler.parse('0 0 -5 * *').next_time(now).to_s
puts

gives:

"2.4.4"
"x86_64-darwin17"

now: 2018-06-28 18:00:00 +0200

  '0 9 -2 * *'  9am the second to last day of the month
3.4.2:  2018-07-29 09:00:00 +0200
3.5.0:  2018-06-29 09:00:00 +0200

  '0 8 L * * mon-thu'  8am the last day of the month (must be a mon or a thu)
3.4.2:  2018-07-31 08:00:00 +0200
3.5.0:  2018-06-30 08:00:00 +0200

  '0 0 -5 * *' 0am fifth to last day of the month
3.4.2:  2018-07-26 00:00:00 +0200
3.5.0:  2018-07-27 00:00:00 +0200

The second result is wrong. It should give 2018-07-31 08:00:00 +0200 instead (like rufus-scheduler 3.4.2 did).

jmettraux commented 6 years ago

Actually, I am wrong. The new implementation, in fugit, is right and follows man 5 crontab

     Note: The day of a command's execution can be specified by two fields -- day of
     month, and day of week.  If both fields are restricted (ie, are not *), the com-
     mand will be run when either field matches the current time.  For example, ``30 4
     1,15 * 5'' would cause a command to be run at 4:30 am on the 1st and 15th of each
     month, plus every Friday.

Thanks anyway.