pub struct Schedule { /* private fields */ }
Expand description
Represents a parsed CRON schedule. It is designed for space efficiency for caching and storage purposes such as in a CRON Scheduler.
Implementations§
Source§impl Schedule
impl Schedule
Sourcepub fn iter_from<'a, Z>(
&'a self,
dt: &DateTime<Z>,
) -> impl DoubleEndedIterator<Item = DateTime<Z>> + 'awhere
Z: TimeZone + 'a,
pub fn iter_from<'a, Z>(
&'a self,
dt: &DateTime<Z>,
) -> impl DoubleEndedIterator<Item = DateTime<Z>> + 'awhere
Z: TimeZone + 'a,
Accepts a DateTime as a placeholder to iterate forwards or backwards for the next time the CRON expression is to run or should have ran.
use chrono::{DateTime, TimeZone, Utc};
use cron_exp::Schedule;
use std::str::FromStr;
// sec min hour day of month month day of week year
let expression = "0 30 9,12,15 1,15 May-Aug Mon,Wed,Fri 2018/2";
let schedule = Schedule::from_str(expression).unwrap();
let mut last: Option<DateTime<Utc>> = None;
let from_date = Utc.ymd(2022, 6, 1).and_hms(8, 40, 1);
// upcoming
for datetime in schedule.iter_from(&from_date).take(10) {
last = Some(datetime);
println!("next -> {:?}", datetime);
}
// previous
for datetime in schedule.iter_from(&last.unwrap()).rev().take(10) {
println!("prev -> {:?}", datetime);
}
Trait Implementations§
impl StructuralPartialEq for Schedule
Auto Trait Implementations§
impl Freeze for Schedule
impl RefUnwindSafe for Schedule
impl Send for Schedule
impl Sync for Schedule
impl Unpin for Schedule
impl UnwindSafe for Schedule
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more