- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6
Closed
Description
Summary
It looks like it's not possible to use the same Cron config to accept both aliases like @hourly or @weekly and standard cron expressions while requiring a seconds specifier.
let get_cron = |pattern: &str| {
    Cron::new(pattern)
        .with_seconds_required()
        .with_dom_and_dow()
        .parse()
};
get_cron("0 0 * * * *")?; -> works as expected
get_cron("@hourly")?; -> fails with `Pattern must consist of six fields, seconds can not be omitted.`I assume it's because of this mapping:
Lines 175 to 182 in 830fc53
| match pattern { | |
| p if eq_ignore_case(p, "@yearly") || eq_ignore_case(p, "@annually") => "0 0 1 1 *", | |
| p if eq_ignore_case(p, "@monthly") => "0 0 1 * *", | |
| p if eq_ignore_case(p, "@weekly") => "0 0 * * 0", | |
| p if eq_ignore_case(p, "@daily") => "0 0 * * *", | |
| p if eq_ignore_case(p, "@hourly") => "0 * * * *", | |
| _ => pattern, | |
| } | 
To support both, consumers of croner essentially have to re-implement the handle_nicknames logic to detect aliases and omit with_seconds_required, or even manually convert to standard syntax if the expression is just passed along to be parsed elsewhere (e.g., when croner is a transitive dependency). I ran into this issue with https://github.com/mvniekerk/tokio-cron-scheduler, which recently switched to croner from cron.
Thanks for the great library!
Hexagon
Metadata
Metadata
Assignees
Labels
No labels