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

Last Friday of the last day of a month #114

Closed infinitum11 closed 2 years ago

infinitum11 commented 3 years ago

I would like to get next 5 dates of the "last Friday of the last day of a month". I use following expression: 0 0 L * FRIL

$expression = "0 0 L * FRIL"; 
$next = new CronExpression($expression);
$next->getMultipleRunDates(5);

The dragonmantank/cron-expression implementation provides following result:

1 | 2021-05-28 00:00:00
2 | 2021-05-31 00:00:00
3 | 2021-06-25 00:00:00
4 | 2021-06-30 00:00:00
5 | 2021-07-30 00:00:00

Which is incorrect. The result contains either "last Friday of a month" or "last day of a month", but not the "last Friday of the last day of a month".

The mtdowling/cron-expression implementation works as expected:

1 | 2021-12-31 00:00:00
2 | 2022-09-30 00:00:00
3 | 2023-03-31 00:00:00
4 | 2023-06-30 00:00:00
5 | 2024-05-31 00:00:00
dragonmantank commented 2 years ago

The original mtdowling implementation was actually incorrect. When both the Day of Week and Day of Month options are supplied, either field of may satisfy the check as an OR check versus an AND check, according to the original C implementation. This was one of the bugs later fixed. So unfortunately there's not a really good way to write such an expression