Skip to main content

Returns when the next job triggers given a cron expression. Supports DST.

Project description

CronDst

Test

CronDst returns when the next job triggers given a cron expression. Supports time zones and daylight savings time (DST).

Features:

  1. Built according to Vixie Cron. The popular cron scheduling logic that lives inside *nix systems like Debian, Ubuntu, RHEL and MacOS.
  2. Lightweight. Single file, zero dependencies.
  3. Efficient. Most expressions require just one constant-time step per iteration.

Install

pip install crondst

Usage

from datetime import datetime
from zoneinfo import ZoneInfo
from crondst import CronDst

# :00 and :01 at 2am and 3am in Pacific Time
tz = ZoneInfo('America/Los_Angeles')
it = CronDst('0-1 2,3 * * *').iter(datetime(2077, 12, 10, 2, 0, tzinfo=tz))

next(it) # datetime(2077, 12, 10, 2, 1)
next(it) # datetime(2077, 12, 10, 3, 0)
next(it) # datetime(2077, 12, 10, 3, 1)
next(it) # datetime(2077, 12, 11, 2, 0)

Supported Cron Expressions

All valid Vixie Cron expressions are supported.

         field:
┌───────────── minute       (0–59)
│ ┌─────────── hour         (0–23)
│ │ ┌───────── day of month (1–31)
│ │ │ ┌─────── month        (1–12 or Jan-Dec)
│ │ │ │ ┌───── day of week  (0–6 or Sun-Sat, 7 or Sun)
│ │ │ │ │
* * * * *
Syntax Name Applicable Field(s)
<number> number all
* wildcard all
- range all
, list all
/ step all

Daylight Savings Time (DST)

DST behavior follows Vixie Cron:

  1. Clock changes backwards. Jobs triggered during ambiguous time are not repeated after the clock change.
  2. Clock changes forwards. Jobs scheduled to trigger during missing time are triggered immediately after the clock change.
  3. Above rules only apply to fixed-time (non-wildcard) jobs. Wildcard jobs are scheduled normally.

Wildcard jobs are where the hour or minute fields of a cron expression start with *.

CronDst iterates through each timestamp only once even if multiple jobs can be triggered for a timestamp.

Day of Month and Day of Week

When the day of month or day of week fields start with *, the matching days are based on the intersection (AND) of both fields. Otherwise the union (OR) is taken.

This also aligns with Vixie Cron behavior.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crondst-1.0.3.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

crondst-1.0.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file crondst-1.0.3.tar.gz.

File metadata

  • Download URL: crondst-1.0.3.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.2

File hashes

Hashes for crondst-1.0.3.tar.gz
Algorithm Hash digest
SHA256 ffe0a4319976a35717e8c3b94b0be7863595460a5cf4a8882f29b63811273d1e
MD5 08f56ed9fc272b613d49000ea33123ba
BLAKE2b-256 a3a808239f9434d2baf1979dab7521b61027c8e5aa5dae2defbcbc4b34c35600

See more details on using hashes here.

File details

Details for the file crondst-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: crondst-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.2

File hashes

Hashes for crondst-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3bc1267147d000241426eab1af448b2633ec737653f172b676ef0e9836608a6c
MD5 deb44f7cdf4eea1db015a65e4100e620
BLAKE2b-256 4755db4614104619f687e7bcb0138b3a60687102b8152c4f094589ec5245680a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page