Skip to content

support the optional years field - #48

Merged
mariusbancila merged 1 commit into
masterfrom
feature/years-field
Aug 12, 2026
Merged

support the optional years field#48
mariusbancila merged 1 commit into
masterfrom
feature/years-field

Conversation

@mariusbancila

Copy link
Copy Markdown
Owner

croncpp's README has documented an optional seventh field, <seconds> <minutes> <hours> <days of month> <months> <days of week> <years>, and even used it in a worked example. The parser accepted exactly six fields. This implements it, as in Quartz and the Oracle format croncpp already follows.

0 15 10 * * ? 2005         10:15 AM every day during 2005
0 15 10 ? * 5L 2002-2006   10:15 AM on the last Friday of every month, 2002 to 2006

The field is optional and takes *, ,, -, and / over the range 1970-2099. An expression whose years have gone by has no next occurrence, so cron_next reports failure rather than returning some later date.

Traits opt in by declaring CRON_MIN_YEARS and CRON_MAX_YEARS, detected at compile time. All three supplied traits do; a traits type written before this change keeps taking six fields and rejects a seventh, so existing custom traits are unaffected. Traits may narrow the range but not widen it — the storage range is fixed because cronexpr isn't a template, and a traits type asking for more now fails to compile with a message saying so.

New test_years.cpp, including two purpose-built traits types, one without the year members, one with a narrower range.

Every expression in the README's examples table now parses, including 0 15 10 * * ? *, which never has.

Fixes #22.

@mariusbancila
mariusbancila merged commit e881f3f into master Aug 12, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

years field not support

1 participant