alpinweis / cronex

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

Incorrect description when using last day of month in a range for DoM #19

Closed gee-forr closed 4 years ago

gee-forr commented 4 years ago

Hi there,

I think I've found a bug when parsing cron expressions that use L in the DoM field within a range. Here's a breakdown:

Cron expression: * * 25-L * * Current value: Every minute, between day 25 and L of the month Expected value: Every minute, between day 25 and the last day of the month or something approaching that.

Thanks so much for this great gem, we save schedules for people in a cron format, and make it human-readable for users using this gem.

Let me know if I can help in any way to get this fixed.

alpinweis commented 4 years ago

I'm not sure whether this is a bug or a feature...

The original C#-based implementation this gem is based upon also produces the same output https://bradymholt.github.io/cron-expression-descriptor/?locale=en-US&expression=*+*+25-L++

According to the cron docs, L is one of the non-standard characters and exists only in some cron implementations, such as the Quartz Java scheduler.

From http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html

L (“last”) - has different meaning in each of the two fields in which it is allowed. For example, the value “L” in the day-of-month field means “the last day of the month” - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means “7” or “SAT”. But if used in the day-of-week field after another value, it means “the last xxx day of the month” - for example “6L” means “the last friday of the month”. You can also specify an offset from the last day of the month, such as “L-3” which would mean the third-to-last day of the calendar month. When using the ‘L’ option, it is important not to specify lists, or ranges of values, as you’ll get confusing/unexpected results.

See the piece in bold ^

alpinweis commented 4 years ago

Fixed in #20

gee-forr commented 4 years ago

This is amazing. Thank you so much!

--

Gabriel Fortuna gee.forr@gmail.com On 04 Oct 2020, 20:08 +0200, alpinweis notifications@github.com, wrote:

Closed #19. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.