floraison / fugit

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

Support character "W" in the cron expression #66

Closed Raaghulsundar closed 2 years ago

Raaghulsundar commented 2 years ago

Issue description

Unable to use cron expression 0 0 12 LW -> At 12:00:00pm, on the last weekday of the month, every month

How to reproduce

The simplest piece of code that reproduces the issue, for example:

require 'fugit'
c = Fugit::Cron.parse("0 0 12 LW * *")
p c.next_time

Error and error backtrace (if any)

NoMethodError: undefined method `next_time' for nil:NilClass

Expected behaviour

Context

Darwin Raaghul-Sundar's-Macbook-Pro 19.6.0 Darwin Kernel Version 19.6.0: Tue Jun 22 19:49:55 PDT 2021; root:xnu-6153.141.35~1/RELEASE_X86_64 x86_64
ruby 2.4.10p364 (2020-03-31 revision 67879) [x86_64-darwin19]
[:env_tz, nil]
(secs:1645426423.385986,utc~:"2022-02-21 06:53:43.3859860897064209",ltz~:"IST")
(etz:nil,tnz:"IST",tziv:"1.2.9",tzidv:nil,rv:"2.4.10",rp:"x86_64-darwin19",win:false,rorv:nil,astz:nil,eov:"1.2.4",eotnz:#<TZInfo::TimezoneProxy: Asia/Calcutta>,eotnfz:"+0530",eotlzn:"Asia/Calcutta",eotnfZ:"IST",debian:nil,centos:nil,osx:"zoneinfo/Asia/Kolkata")
[:fugit, "1.3.6"]
[:now, 2022-02-21 12:24:42 +0530, :zone, "IST"]
jmettraux commented 2 years ago

Unable to use cron expression 0 0 12 LW -> At 12:00:00pm, on the last weekday of the month, every month

Sorry, but this is non-standard and ambiguous.

Non-standard because I know of no "W" in the crontab "standard" man 5 crontab and even if I look at crontab.guru

Ambiguous because when is the last weekday? Friday, Saturday, Sunday? It depends on the organization.

If you want "at 12:00 on the last friday of the month" please use 0 12 * * fri#L as seen in the hash extension.

If you want "at 12:00 on the last day of the month", please use 0 12 L * * as seen in Fugit::Cron's doc

I am closing the issue, but I am not closing the conversation.

King regards.