Cron Schedule Parser
Prerequisites & Dependencies
- Python 3.10+ (for cron expression parsing)
- No external runtime dependencies; pure-Python cron library optional
Execution Steps
Identify the cron expression format: Determine if the input is a standard 5-part cron (minute hour day month weekday) or 6-part format (including seconds).
Parse the cron expression: Use a cron library or manual parsing to extract the five (or six) time fields: minute, hour, day-of-month, month, day-of-week.
Convert to cron format: If the input is in natural language (e.g., "every hour", "first Monday of the month"), translate it into the standard cron five-part format.
Validate the cron expression: Check that the parsed values are valid (e.g., minute 0-59, hour 0-23, day-of-month 1-31, month 1-12, weekday 0-6).
Output the cron schedule: Produce the cron expression string that can be used in crontab files or scripts.
Example outputs:
- "Every hour" →
0 * * * * - "Daily at 8am" →
0 8 * * * - "First Monday of every month" →
0 0 * * 1 - "Every 15 minutes" →
*/15 * * * *
- "Every hour" →
npm i node-cron
import croniter
from datetime import datetime
base = datetime.now()
schedule = croniter.croniter('0 * * * *', base)
next_time = schedule.get_next(datetime)
CLI Usage
cron-schedule-parser "every hour"
# Output: 0 * * * *