CronDst
CronDst returns when the next job triggers given a cron expression. Supports time zones and daylight savings time (DST).
Features:
- Built according to Vixie Cron. The popular cron scheduling logic that lives inside *nix systems like Debian, Ubuntu, RHEL and MacOS.
- Lightweight. Single file, zero dependencies.
- 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:
- Clock changes backwards. Jobs triggered during ambiguous time are not repeated after the clock change.
- Clock changes forwards. Jobs scheduled to trigger during missing time are triggered immediately after the clock change.
- 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)
| File | Size | Uploaded | |
|---|---|---|---|
| crondst-1.0.3.tar.gz | 15.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|