oncalendar
A systemd OnCalendar expression parser and evaluator. Requires Python 3.11+.
oncalendar is written for and being used in Healthchecks (a scheduled task monitoring service).
This package provides three iterators:
-
oncalendar.BaseIterator(expression: str, start: datime): supports expressions without timezone (example: "Mon, 12:34"). Accepts both naive and timezone-aware datetimes as the start time.
-
oncalendar.TzIterator(expression: str, start: datetime): supports expressions with and without timezone. (example: "Mon, 12:34 Europe/Riga"). Requires the start datetime to be timezone-aware.
-
oncalendar.OnCalendar(expressions:str, start: datetime): supports multiple expressions with or without timezones, separated by newlines. Requires the start datetime to be timezone-aware. Example:
2020-01-01 12:34 Europe/Riga
Installation
pip install oncalendar
Usage
from datetime import datetime
from oncalendar import BaseIterator
it = BaseIterator("Mon, 12:34", datetime.now())
for x in range(0, 10):
print(next(it))
Produces:
2023-12-11 12:34:00
2023-12-18 12:34:00
2023-12-25 12:34:00
2024-01-01 12:34:00
2024-01-08 12:34:00
2024-01-15 12:34:00
2024-01-22 12:34:00
2024-01-29 12:34:00
2024-02-05 12:34:00
2024-02-12 12:34:00
If oncalendar receives an invalid expression, it raises oncalendar.OnCalendarError
exception:
from datetime import datetime
from oncalendar import BaseIterator
BaseIterator("Mon, 123:456", datetime.now())
Produces:
oncalendar.OnCalendarError: Bad hour
If oncalendar hits year 2200 while iterating, it stops iteration by raising
StopIteration:
from datetime import datetime
from oncalendar import BaseIterator
# 2199 is not leap year, and we stop at 2200
print(next(BaseIterator("2199-2-29", datetime.now())))
Produces:
StopIteration
Known Limitations
- Does not support decimals in the second field.
Metadata
Release files for oncalendar 1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| oncalendar-1.2-py3-none-any.whl | Python 3 | none | any | Details for oncalendar-1.2-py3-none-any.whl |
Release files / oncalendar-1.2-py3-none-any.whl
| Download URL | oncalendar-1.2-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eee6b0367e9758486ba278940e6e9a0fc66cebd87e9a85de5d66baf40cf54d95
|
|
BLAKE2b-256 checksum How to use checksums |
55c204c775ef59d378a5ae4b1ffc60a0b4fefb99393fabe3c9a8b632c424f5f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for oncalendar 1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.