go-co-op / gocron

Easy and fluent Go cron scheduling. This is a fork from https://github.com/jasonlvhit/gocron
MIT License
5.65k stars 310 forks source link

[FEATURE] - Any plan to support Year field in the cron expression #599

Closed Tochemey closed 1 year ago

Tochemey commented 1 year ago

Is your feature request related to a problem? Please describe

The standard cron expression does accept year field. This for instance helps to schedule tasks to run only once.

From the code I cannot see anything that will help handle that. That means a cron expression like this 0 0 0 4 JUL ? 2014 will fail the parser because I have seen that there is validation done on the cron expression.

reference: https://docs.oracle.com/cd/E12058_01/doc/doc.1014/e12030/cron_expressions.htm

Tochemey commented 1 year ago

@JohnRoesler This is an example:

var cronExpressionParser = cron.NewParser(
    cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor,
)

cronExpression := "0 0 0 4 JUL ? 2014"
spec, err := cronExpressionParser.Parse(cronExpression)

and this the outcome:

expected 5 to 6 fields, found 7: [0 0 0 4 JUL ? 2014]

However this 0 0 0 4 JUL ? 2014 is valid cron expression

JohnRoesler commented 1 year ago

Hey @Tochemey,

Couple things:

What are you trying to accomplish? I imagine there are other ways to achieve it without the year field?

To answer the title question: no, no plans. Cheers!

Tochemey commented 1 year ago

@JohnRoesler Thanks for the reply.

Tochemey commented 1 year ago

@JohnRoesler even on Wikipedia the Cron expression does accept year field. It just not required. https://en.m.wikipedia.org/w/index.php?title=Cron&action=edit&section=9