Struct saffron::Cron [−][src]
A cron value. This can be used to iterate over all future matching times or quickly check if a given time matches.
Example
use saffron::Cron; use chrono::prelude::*; let cron: Cron = "*/10 0 * OCT MON".parse().expect("Couldn't parse expression!"); // check if a given time is contained in an expression assert!(cron.contains(Utc.ymd(2020, 10, 19).and_hms(0, 30, 0))); // iterate over all future matching times for time in cron.clone().iter_from(Utc.ymd(1970, 1, 1).and_hms(0, 0, 0)).take(5) { // Prints // 1970-10-05 00:00:00 UTC // 1970-10-05 00:10:00 UTC // 1970-10-05 00:20:00 UTC // 1970-10-05 00:30:00 UTC // 1970-10-05 00:40:00 UTC println!("{}", time); assert!(cron.contains(time)); }
Implementations
impl Cron
[src]
pub fn new(expr: CronExpr) -> Self
[src]
Simplifies the cron expression into a cron value.
pub fn any(&self) -> bool
[src]
Returns whether this cron value will ever match any giving time.
Some values can never match any given time. If an value matches for a day of the month that's beyond any of the valid days of the months matched then the value can never match.
Example
use saffron::Cron; // Does have any since February has a 29th day on leap years assert!("* * 29 2 *".parse::<Cron>().unwrap().any()); // Does not have any since November does not have a 31st day assert!(!"* * 31 11 *".parse::<Cron>().unwrap().any());
pub fn contains(&self, dt: DateTime<Utc>) -> bool
[src]
Returns whether this cron value matches the given time.
Example
use saffron::Cron; use chrono::prelude::*; let cron: Cron = "*/10 0 * OCT MON".parse().expect("Couldn't parse expression!"); // check if a given time is contained in an expression assert!(cron.contains(Utc.ymd(2020, 10, 19).and_hms(0, 30, 0)));
pub fn iter_from(self, start: DateTime<Utc>) -> CronTimesIterⓘNotable traits for CronTimesIter
impl Iterator for CronTimesIter type Item = DateTime<Utc>;
[src]
Notable traits for CronTimesIter
impl Iterator for CronTimesIter type Item = DateTime<Utc>;
Creates an iterator of date times that match with the cron value.
Example
use saffron::Cron; use chrono::prelude::*; let cron = "*/10 * * * *".parse::<Cron>().expect("Couldn't parse expression!"); for time in cron.iter_from(Utc.ymd(1970, 1, 1).and_hms(0, 0, 0)).take(5) { // Prints // 1970-01-01 00:00:00 UTC // 1970-01-01 00:10:00 UTC // 1970-01-01 00:20:00 UTC // 1970-01-01 00:30:00 UTC // 1970-01-01 00:40:00 UTC println!("{}", time) }
pub fn iter_after(self, start: DateTime<Utc>) -> CronTimesIterⓘNotable traits for CronTimesIter
impl Iterator for CronTimesIter type Item = DateTime<Utc>;
[src]
Notable traits for CronTimesIter
impl Iterator for CronTimesIter type Item = DateTime<Utc>;
Creates an iterator of date times that match with the cron value after the given date.
Example
use saffron::Cron; use chrono::prelude::*; let cron = "*/10 * * * *".parse::<Cron>().expect("Couldn't parse expression!"); for time in cron.iter_after(Utc.ymd(1970, 1, 1).and_hms(0, 0, 0)).take(5) { // Prints // 1970-01-01 00:10:00 UTC // 1970-01-01 00:20:00 UTC // 1970-01-01 00:30:00 UTC // 1970-01-01 00:40:00 UTC // 1970-01-01 00:50:00 UTC println!("{}", time) }
pub fn next_from(&self, date: DateTime<Utc>) -> Option<DateTime<Utc>>
[src]
Returns the next time the cron will match including the given date.
Example
use saffron::Cron; use chrono::prelude::*; let cron = "*/10 * * * *".parse::<Cron>().expect("Couldn't parse expression!"); let date = Utc.ymd(1970, 1, 1).and_hms(0, 0, 0); // the given date matches the expression, so we get the same date back (truncated) assert_eq!(cron.next_from(date), Some(date));
pub fn next_after(&self, date: DateTime<Utc>) -> Option<DateTime<Utc>>
[src]
Returns the next time the cron will match after the given date.
Example
use saffron::Cron; use chrono::prelude::*; let cron = "*/10 * * * *".parse::<Cron>().expect("Couldn't parse expression!"); let date = Utc.ymd(1970, 1, 1).and_hms(0, 0, 0); assert_eq!(cron.next_after(date), date.with_minute(10));
Trait Implementations
impl Clone for Cron
[src]
impl Debug for Cron
[src]
impl Eq for Cron
[src]
impl FromStr for Cron
[src]
type Err = CronParseError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl Hash for Cron
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl PartialEq<Cron> for Cron
[src]
impl StructuralEq for Cron
[src]
impl StructuralPartialEq for Cron
[src]
Auto Trait Implementations
impl RefUnwindSafe for Cron
[src]
impl Send for Cron
[src]
impl Sync for Cron
[src]
impl Unpin for Cron
[src]
impl UnwindSafe for Cron
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,