Skip to main content

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.

Metadata

Release files for crondst 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crondst 1.0.3
File Size Uploaded
crondst-1.0.3.tar.gz 15.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for crondst 1.0.3
File Interpreter ABI Platform
crondst-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 23.6 kB

Release files / crondst-1.0.3.tar.gz

Download URL crondst-1.0.3.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ffe0a4319976a35717e8c3b94b0be7863595460a5cf4a8882f29b63811273d1e
BLAKE2b-256 checksum
How to use checksums
a3a808239f9434d2baf1979dab7521b61027c8e5aa5dae2defbcbc4b34c35600
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.2

Release files / crondst-1.0.3-py3-none-any.whl

Download URL crondst-1.0.3-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3bc1267147d000241426eab1af448b2633ec737653f172b676ef0e9836608a6c
BLAKE2b-256 checksum
How to use checksums
4755db4614104619f687e7bcb0138b3a60687102b8152c4f094589ec5245680a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page