mtdowling / cron-expression

CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
http://mtdowling.com/blog/2012/06/03/cron-expressions-in-php/
MIT License
4.9k stars 335 forks source link

Weekday-Hash for Saturday and Sunday doesn't seem to work #20

Closed sebknzl closed 10 years ago

sebknzl commented 11 years ago

Hello!

First off, thanks for the great library!!

I wonder why something like "0 22 ? * SUN#1 *" doesn't work, though... in DayOfWeekField:66 it forces weekday to be within [1,5]. Commenting out that part results in a "Impossible CRON expression" later.

Also, I noticed that the test-line "0 0 0 ? 1/2 FRI#2 *" from your blog doesn't work, probably there's an extra 0.

Thanks

mtdowling commented 11 years ago

According to the wikipedia article, the hash only allows numbers between 1-5: http://en.wikipedia.org/wiki/Cron#Special_characters. Do other implementations differ from that?

Also, I noticed that the test-line "0 0 0 ? 1/2 FRI#2 *" from your blog doesn't work, probably there's an extra 0.

Thanks, I get that updated.

sebknzl commented 11 years ago

I can't really find an implementation supporting this hash-thing. Any discussion mentioning it seems to reference the Wikipedia-article (e.g. http://serverfault.com/questions/395262/weekly-alternating-cronjob-with-step-values) Normal cron wouldn't support that, as hashes start comments. It's useful nevertheless, but I don't see why it should support only Mon through Fri? For normal cron, stuff like e.g. "0 0 1-7 * 0" would be used instead of SUN#1.

mtdowling commented 11 years ago

I'd be fine with this if you want to submit a PR.

gorhill commented 11 years ago

Normal cron wouldn't support that, as hashes start comments.

Only if the hash sign is preceded by blank characters.

"0 0 1-7 * 0" would be used instead of SUN#1

That doesn't work: the day-of-month and day-of-week fields are ORed, not ANDed together. So the above would result in the event being triggered for each day between the first and seventh day of the month and for every sunday.