pub struct CronExpr { /* private fields */ }Expand description
A parsed cron expression ready for next-run calculations.
Used when upserting chronon_core::Job rows with chronon_core::ScheduleKind::Cron:
set job.cron_expr (and optional timezone); CoordinatorService::upsert_job calls
Self::parse and stores next_run_at.
Syntax: standard five-field cron (minute hour day-of-month month day-of-week). An optional
sixth field enables seconds (CronExpr::has_seconds). Timezone names follow chrono-tz
(e.g. "America/New_York"); omit for UTC.
§Examples
use chronon_scheduler::CronExpr;
let cron = CronExpr::parse("0 2 * * *", Some("UTC")).unwrap();
assert_eq!(cron.expression(), "0 2 * * *");
assert!(!cron.has_seconds());
assert!(cron.next_from_now().is_some());
let with_secs = CronExpr::parse("0 0 2 * * *", None).unwrap();
assert!(with_secs.has_seconds());Implementations§
Source§impl CronExpr
impl CronExpr
Sourcepub fn parse(
expr: &str,
timezone: Option<&str>,
) -> Result<CronExpr, ChrononError>
pub fn parse( expr: &str, timezone: Option<&str>, ) -> Result<CronExpr, ChrononError>
Parse a cron expression with an optional timezone.
§Examples
use chronon_scheduler::CronExpr;
let cron = CronExpr::parse("0 0 * * *", None).unwrap();
assert_eq!(cron.expression(), "0 0 * * *");
assert!(cron.next_from_now().is_some());Sourcepub fn next_after(&self, after: DateTime<Utc>) -> Option<DateTime<Utc>>
pub fn next_after(&self, after: DateTime<Utc>) -> Option<DateTime<Utc>>
Calculate the next run time after the given datetime.
Sourcepub fn next_from_now(&self) -> Option<DateTime<Utc>>
pub fn next_from_now(&self) -> Option<DateTime<Utc>>
Calculate the next run time from now.
Sourcepub fn expression(&self) -> &str
pub fn expression(&self) -> &str
Get the original cron expression.
Sourcepub fn has_seconds(&self) -> bool
pub fn has_seconds(&self) -> bool
Check if the expression uses seconds (6 fields).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CronExpr
impl RefUnwindSafe for CronExpr
impl Send for CronExpr
impl Sync for CronExpr
impl Unpin for CronExpr
impl UnsafeUnpin for CronExpr
impl UnwindSafe for CronExpr
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more