Trait clockwork_cron::TimeUnitSpec
source · pub trait TimeUnitSpec {
// Required methods
fn includes(&self, ordinal: u32) -> bool;
fn count(&self) -> u32;
fn is_all(&self) -> bool;
}
Expand description
Methods exposing a schedule’s configured ordinals for each individual unit of time.
§Example
use clockwork_cron::{Schedule,TimeUnitSpec};
use std::ops::Bound::{Included,Excluded};
use std::str::FromStr;
let expression = "* * * * * * 2015-2044";
let schedule = Schedule::from_str(expression).expect("Failed to parse expression.");
// Membership
assert_eq!(true, schedule.years().includes(2031));
assert_eq!(false, schedule.years().includes(1969));
// Number of years specified
assert_eq!(30, schedule.years().count());
Required Methods§
sourcefn includes(&self, ordinal: u32) -> bool
fn includes(&self, ordinal: u32) -> bool
Returns true if the provided ordinal was included in the schedule spec for the unit of time being described.
§Example
use clockwork_cron::{Schedule,TimeUnitSpec};
use std::str::FromStr;
let expression = "* * * * * * 2015-2044";
let schedule = Schedule::from_str(expression).expect("Failed to parse expression.");
// Membership
assert_eq!(true, schedule.years().includes(2031));
assert_eq!(false, schedule.years().includes(2004));
sourcefn count(&self) -> u32
fn count(&self) -> u32
Returns the number of ordinals included in the associated schedule
§Example
use clockwork_cron::{Schedule,TimeUnitSpec};
use std::str::FromStr;
let expression = "* * * 1,15 * * *";
let schedule = Schedule::from_str(expression).expect("Failed to parse expression.");
assert_eq!(2, schedule.days_of_month().count());
sourcefn is_all(&self) -> bool
fn is_all(&self) -> bool
Checks if this TimeUnitSpec is defined as all possibilities (thus created with a ‘*’, ‘?’ or in the case of weekdays ‘1-7’)
§Example
use clockwork_cron::{Schedule,TimeUnitSpec};
use std::str::FromStr;
let expression = "* * * 1,15 * * *";
let schedule = Schedule::from_str(expression).expect("Failed to parse expression.");
assert_eq!(false, schedule.days_of_month().is_all());
assert_eq!(true, schedule.months().is_all());