alpinweis / cronex

Ruby library that converts cron expressions into human readable strings
Other
78 stars 29 forks source link

Fix zero hour #29

Closed cbartlett closed 1 year ago

cbartlett commented 1 year ago

Prior to this change, both * and 0 were treated the same when in the hour position. That meant that the following string:

*/5 0 * * *

would return the following description:

Every 5 minutes

Which is incorrect. Instead, cron will run that job every 5 minutes only during the 0th hour. Since * means "every hour of the day" but 0 specifically means "the 0th hour" -- midnight, aka 0:00 aka 12:00 AM -- both * and 0 cannot be treated equally when in the hour position.

This fixes the parsing such that 0 will properly return what it actually means -- only during the 12:00 AM hour.

Other libraries on which this gem are based do handle this case properly. For example, the C# version.

With * in hour position

Screen Shot 2023-10-28 at 3 05 40 PM

With 0 in hour position

Screen Shot 2023-10-28 at 3 05 31 PM