Name | crondst JSON |
Version |
1.0.3
JSON |
| download |
home_page | None |
Summary | Returns when the next job triggers given a cron expression. Supports DST. |
upload_time | 2024-05-26 01:52:03 |
maintainer | Calvin Law |
docs_url | None |
author | Calvin Law |
requires_python | >=3.9 |
license | MIT |
keywords |
cron
crontab
schedule
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# CronDst
[![Test](https://github.com/lawcal/crondst/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/lawcal/crondst/actions/workflows/test.yml)
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](https://github.com/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.
Raw data
{
"_id": null,
"home_page": null,
"name": "crondst",
"maintainer": "Calvin Law",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "cron, crontab, schedule",
"author": "Calvin Law",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/a3/a8/08239f9434d2baf1979dab7521b61027c8e5aa5dae2defbcbc4b34c35600/crondst-1.0.3.tar.gz",
"platform": null,
"description": "# CronDst\n\n[![Test](https://github.com/lawcal/crondst/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/lawcal/crondst/actions/workflows/test.yml)\n\nCronDst returns when the next job triggers given a cron expression. Supports time zones and daylight savings time (DST).\n\nFeatures:\n1. **Built according to [Vixie Cron](https://github.com/vixie/cron).** The popular cron scheduling logic that lives inside *nix systems like Debian, Ubuntu, RHEL and MacOS.\n2. **Lightweight.** Single file, zero dependencies.\n3. **Efficient.** Most expressions require just one constant-time step per iteration.\n\n## Install\n`pip install crondst`\n\n## Usage\n```\nfrom datetime import datetime\nfrom zoneinfo import ZoneInfo\nfrom crondst import CronDst\n\n# :00 and :01 at 2am and 3am in Pacific Time\ntz = ZoneInfo('America/Los_Angeles')\nit = CronDst('0-1 2,3 * * *').iter(datetime(2077, 12, 10, 2, 0, tzinfo=tz))\n\nnext(it) # datetime(2077, 12, 10, 2, 1)\nnext(it) # datetime(2077, 12, 10, 3, 0)\nnext(it) # datetime(2077, 12, 10, 3, 1)\nnext(it) # datetime(2077, 12, 11, 2, 0)\n```\n\n## Supported Cron Expressions\n\nAll valid Vixie Cron expressions are supported.\n\n```\n field:\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 minute (0\u201359)\n\u2502 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 hour (0\u201323)\n\u2502 \u2502 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 day of month (1\u201331)\n\u2502 \u2502 \u2502 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500 month (1\u201312 or Jan-Dec)\n\u2502 \u2502 \u2502 \u2502 \u250c\u2500\u2500\u2500\u2500\u2500 day of week (0\u20136 or Sun-Sat, 7 or Sun)\n\u2502 \u2502 \u2502 \u2502 \u2502\n* * * * *\n```\n\n| Syntax | Name | Applicable Field(s) |\n| --------- | -------- | ------------------- |\n| \\<number> | number | all |\n| `*` | wildcard | all |\n| `-` | range | all |\n| `,` | list | all |\n| `/` | step | all |\n\n## Daylight Savings Time (DST)\n\nDST behavior follows Vixie Cron:\n1. **Clock changes backwards.** Jobs triggered during ambiguous time are not repeated after the clock change.\n2. **Clock changes forwards.** Jobs scheduled to trigger during missing time are triggered immediately after the clock change.\n3. Above rules only apply to fixed-time (non-wildcard) jobs. Wildcard jobs are scheduled normally.\n\nWildcard jobs are where the hour or minute fields of a cron expression start with `*`.\n\nCronDst iterates through each timestamp only once even if multiple jobs can be triggered for a timestamp.\n\n## Day of Month and Day of Week\n\nWhen 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.\n\nThis also aligns with Vixie Cron behavior.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Returns when the next job triggers given a cron expression. Supports DST.",
"version": "1.0.3",
"project_urls": {
"Homepage": "https://github.com/lawcal/crondst"
},
"split_keywords": [
"cron",
" crontab",
" schedule"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4755db4614104619f687e7bcb0138b3a60687102b8152c4f094589ec5245680a",
"md5": "deb44f7cdf4eea1db015a65e4100e620",
"sha256": "3bc1267147d000241426eab1af448b2633ec737653f172b676ef0e9836608a6c"
},
"downloads": -1,
"filename": "crondst-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "deb44f7cdf4eea1db015a65e4100e620",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 8294,
"upload_time": "2024-05-26T01:52:01",
"upload_time_iso_8601": "2024-05-26T01:52:01.390006Z",
"url": "https://files.pythonhosted.org/packages/47/55/db4614104619f687e7bcb0138b3a60687102b8152c4f094589ec5245680a/crondst-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a3a808239f9434d2baf1979dab7521b61027c8e5aa5dae2defbcbc4b34c35600",
"md5": "08f56ed9fc272b613d49000ea33123ba",
"sha256": "ffe0a4319976a35717e8c3b94b0be7863595460a5cf4a8882f29b63811273d1e"
},
"downloads": -1,
"filename": "crondst-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "08f56ed9fc272b613d49000ea33123ba",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 15302,
"upload_time": "2024-05-26T01:52:03",
"upload_time_iso_8601": "2024-05-26T01:52:03.179844Z",
"url": "https://files.pythonhosted.org/packages/a3/a8/08239f9434d2baf1979dab7521b61027c8e5aa5dae2defbcbc4b34c35600/crondst-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-26 01:52:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lawcal",
"github_project": "crondst",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "crondst"
}