Cron Expression Generator
Build cron expressions visually with presets and next execution times.
0 0 * * *
Human-readable description
Runs every day at midnight
Frequently Asked Questions
Code Implementation
import re
def describe_cron(expression: str) -> str:
"""Parse a cron expression and return a plain-text description."""
parts = expression.strip().split()
if len(parts) != 5:
raise ValueError("Expected 5 fields: minute hour day month weekday")
minute, hour, day, month, weekday = parts
def field(val, unit):
if val == "*": return f"every {unit}"
if val.startswith("*/"):
return f"every {val[2:]} {unit}s"
if "," in val:
return f"{unit}s {val}"
if "-" in val:
lo, hi = val.split("-")
return f"from {unit} {lo} to {hi}"
return f"at {unit} {val}"
months = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
parts_desc = [
field(minute, "minute"),
field(hour, "hour"),
field(day, "day-of-month"),
field(month, "month"),
field(weekday, "weekday"),
]
return ", ".join(parts_desc)
# Examples
print(describe_cron("0 9 * * 1-5")) # Every weekday at 9 AM
print(describe_cron("*/15 * * * *")) # Every 15 minutes
print(describe_cron("0 0 1 * *")) # First day of every month at midnightComments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.