crondst


Namecrondst JSON
Version 1.0.2 PyPI version JSON
download
home_page
SummaryReturns when the next job triggers given a cron expression. Supports DST.
upload_time2024-01-13 03:00:19
maintainerCalvin Law
docs_urlNone
authorCalvin Law
requires_python>=3.9
licenseMIT
keywords cron crontab schedule
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # CronDst

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`

Or simply copy the `crondst.py` file to your project directory.

## 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": "",
    "name": "crondst",
    "maintainer": "Calvin Law",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "cron,crontab,schedule",
    "author": "Calvin Law",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/a7/ed/bb20eb9f1c1049008d16fb080de24689b0c4ca4e5b53285b775ff095bcad/crondst-1.0.2.tar.gz",
    "platform": null,
    "description": "# CronDst\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\nOr simply copy the `crondst.py` file to your project directory.\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.2",
    "project_urls": {
        "Homepage": "https://github.com/lawcal/crondst"
    },
    "split_keywords": [
        "cron",
        "crontab",
        "schedule"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "17135f5ac754ea45d26af9127e42c349f5001137556b83f35458b14196b62829",
                "md5": "68a717069a5a47e03d221929575fdeaf",
                "sha256": "4cb5d0a10840e78635d061ce5807c2d5f70b318edca2ed43aeaf6779e298d4fc"
            },
            "downloads": -1,
            "filename": "crondst-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "68a717069a5a47e03d221929575fdeaf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 8077,
            "upload_time": "2024-01-13T03:00:17",
            "upload_time_iso_8601": "2024-01-13T03:00:17.790245Z",
            "url": "https://files.pythonhosted.org/packages/17/13/5f5ac754ea45d26af9127e42c349f5001137556b83f35458b14196b62829/crondst-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a7edbb20eb9f1c1049008d16fb080de24689b0c4ca4e5b53285b775ff095bcad",
                "md5": "3f29a5347e297d94eaced4b0f068a86f",
                "sha256": "25c08165c89040eb09fa72065c1e524b31265b2fad2fd653be25e8e2546b9e10"
            },
            "downloads": -1,
            "filename": "crondst-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "3f29a5347e297d94eaced4b0f068a86f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 7320,
            "upload_time": "2024-01-13T03:00:19",
            "upload_time_iso_8601": "2024-01-13T03:00:19.708859Z",
            "url": "https://files.pythonhosted.org/packages/a7/ed/bb20eb9f1c1049008d16fb080de24689b0c4ca4e5b53285b775ff095bcad/crondst-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-13 03:00:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lawcal",
    "github_project": "crondst",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "crondst"
}
        
Elapsed time: 0.16345s