pub struct Crontab { /* private fields */ }
Expand description
A data struct representing the crontab expression.
Implementations§
Source§impl Crontab
impl Crontab
Sourcepub fn iter_after<T>(&self, start: T) -> Result<CronTimesIter, Error>
pub fn iter_after<T>(&self, start: T) -> Result<CronTimesIter, Error>
Create an infinite iterator over next timestamps after start
.
§Errors
This returns an error if fail to make timestamp from the input of start
.
For more usages, see the top-level documentation.
Sourcepub fn find_next<T>(&self, timestamp: T) -> Result<Zoned, Error>
pub fn find_next<T>(&self, timestamp: T) -> Result<Zoned, Error>
Find the next timestamp after the given timestamp.
§Errors
This returns an error if fail to make timestamp from the input of timestamp
. Or fail to
advance the timestamp.
For more usages, see the top-level documentation.
Sourcepub fn matches<T>(&self, timestamp: T) -> Result<bool, Error>
pub fn matches<T>(&self, timestamp: T) -> Result<bool, Error>
Returns whether this crontab matches the given timestamp.
The function checks each cron field (minutes, hours, day of month, month) against the
provided timestamp
to determine if it aligns with the crontab expression. Each field is
checked for a match, and all fields must match for the entire pattern to be considered a
match.
§Errors
This returns an error if fail to make timestamp from the input of timestamp
. Or fail to
advance the timestamp.
If you’re sure the input is valid, you can treat the error as false
.
let crontab = cronexpr::parse_crontab("*/10 0 * OCT MON UTC").unwrap();
assert!(crontab.matches("2020-10-19T00:20:00Z").unwrap());
assert!(crontab.matches("2020-10-19T00:30:00Z").unwrap());
assert!(!crontab.matches("2020-10-20T00:31:00Z").unwrap());
assert!(!crontab.matches("2020-10-20T01:30:00Z").unwrap());
assert!(!crontab.matches("2020-10-20T00:30:00Z").unwrap());
For more usages, see the top-level documentation.