dlt.common.interval
is_cron_expression
def is_cron_expression(s: str) -> bool
Check whether a string is a valid cron expression.
Arguments:
sstr - The string to validate.
Returns:
bool-Trueifsparses as a cron expression.
lag_cron
def lag_cron(cron_expr: str, dt: datetime, count: int) -> datetime
Floor dt to the latest cron tick, then step count ticks into the past.
Ticks are computed on the naive wall clock of dt's timezone, so daily and
sub-daily expressions align correctly across DST transitions.
Arguments:
cron_exprstr - A cron expression defining the tick grid.dtdatetime - The reference time. Its timezone is preserved on the result.countint - Number of ticks to step back.count=0returns the floor tick (dtitself when it falls on a tick); negative values step into the future (count=-1is the first tick strictly after the floor).
Returns:
datetime- The resulting tick, carryingdt's timezone.
lag_interval
def lag_interval(interval: TTimeInterval,
trigger: str,
count: int = 1,
lag_end: bool = False) -> TTimeInterval
Lag the interval start (or end) by count trigger ticks into the past.
count=0 snaps the bound to the tick floor, negative count moves it into the
future. For every: triggers the bound shifts by period * count seconds.
Arguments:
intervalTTimeInterval - The interval to adjust.triggerstr - Aschedule:orevery:trigger, or a bare cron expression.countint - Number of ticks (or periods) to lag; negative moves into the future. Defaults to 1.lag_endbool - WhenTrue, adjusts the end instead of the start. Defaults toFalse.
Returns:
TTimeInterval- The adjusted interval.
Raises:
ValueError- If the adjusted interval is empty or negative, or if the trigger carries no time period (not aschedule:/every:trigger or cron expression).
full_days_interval
def full_days_interval(interval: TTimeInterval) -> TTimeInterval
Widen an interval so it covers whole days.
The start is floored to the midnight at or before it and the end raised to the midnight at or after it, each adjusted in its own timezone.
Arguments:
intervalTTimeInterval - The interval to widen.
Returns:
TTimeInterval- The widened interval.