Timezone aware Cron/Quartz parser

1.0.0 · active · verified Thu Apr 16

tzcron is a Python library that provides a way to define schedules using cron/quartz expressions and attach them to specific timezones. It allows users to iterate over a schedule object to get future time occurrences, serving as a powerful cron parser without implementing scheduling capabilities itself. The current version is 1.0.0. The library appears to have a stable, though infrequent, release cadence, with the last update in 2016.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create timezone-aware cron schedules using `tzcron`. It shows how to initialize a schedule with a cron expression and a `pytz` timezone, and then retrieve future occurrences by iterating or using `get_next_occurrence`.

import tzcron
import pytz
from datetime import datetime

# Create a timezone-aware schedule for every minute (using UTC)
schedule_utc = tzcron.Schedule("* * * * * *", pytz.utc)
print(f"UTC Schedule: {str(schedule_utc)}")

# Get the next 3 occurrences in UTC
print("Next 3 UTC occurrences:")
for _ in range(3):
    print(next(schedule_utc))

# Create a schedule for every hour at 30 minutes past the hour, in 'America/New_York' timezone
ny_timezone = pytz.timezone('America/New_York')
schedule_ny = tzcron.Schedule("30 * * * *", ny_timezone)
print(f"NY Schedule: {str(schedule_ny)}")

# Get the next occurrence for the NY schedule after a specific time
# Use a fixed start time for consistent results in tests
start_time = ny_timezone.localize(datetime(2026, 4, 16, 10, 0, 0))
print(f"Next NY occurrence after {start_time}: {schedule_ny.get_next_occurrence(start_time)}")

view raw JSON →