use chrono::Local;
use croner::parser::CronParser;
use croner::describe::lang::swedish::Swedish;
fn main() {
let cron = CronParser::builder()
.seconds(croner::parser::Seconds::Required) .build()
.parse("0 18 * * * FRI")
.expect("Couldn't parse cron string");
let time = Local::now();
let matches = cron.is_time_matching(&time).unwrap();
let next = cron.find_next_occurrence(&time, false).unwrap();
let description = cron.describe();
println!("Description: {description}");
let swedish_description = cron.describe_lang(Swedish); println!("Swedish Description: {swedish_description}");
println!("Current time is: {time}");
println!(
"Pattern \"{}\" does {} time {}",
cron.pattern,
if matches { "match" } else { "not match" },
time
);
println!(
"Pattern \"{}\" will match next time at {}",
cron.pattern, next
);
println!("Next 5 matches:");
for time in cron.clone().iter_after(Local::now()).take(5) {
println!("{time}");
}
println!("Previous 5 matches:");
for time in cron.clone().iter_before(Local::now()).take(5) {
println!("{time}");
}
}