dragonmantank / cron-expression

CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
MIT License
4.57k stars 124 forks source link

DayOfMonth: (how) does LW work? #168

Open Tiscan76 opened 1 year ago

Tiscan76 commented 1 year ago

I was messing with PHP 7.4.3 and v3.3.3 of the library and I'm not entirely sure if i'm doing something wrong or if the calculation is broken.

If i use the cron-expression 0 5 LW * * to calculate 5:00 at the last weekday of the month and then execute getNextRunDate('2023-10-01 00:00:00') I would expect this function to return 2023-10-31 05:00:00 but it returns 2023-10-02 05:00:00.

If i change it to getNextRunDate('2023-10-03 00:00:00') the result changes to 2023-12-30 05:00:00.

Is this a bug or did I misunderstand how LW is supposed to work?

mabar commented 8 months ago

From https://github.com/dragonmantank/cron-expression/blob/102b869b989d2867b5f05248cedbfa6604aa3a0a/src/Cron/DayOfWeekField.php#L16-L17 I guess it means last wednesday and not last weekday as in Quartz Scheduler (in which I found this feature, is it also somewhere else?) Even with that in mind, it looks like a bug, because it does not match last wednesday. Also it is not a standard cron syntax and it's better to not use it.