Does This Cron Schedule Fire Now?

hard
Checkpoint challenge
Solve this to show you know the material and jump straight to Unit 24. Everything before it counts as cleared.

Cron expressions schedule jobs: "*/15 9-17 * * 1-5" means every 15 minutes from 9am to 5pm on weekdays. Implement the five-field version.

cron_matches(expr, dt) returns True if the datetime dt matches. The fields are minute (0–59), hour (0–23), day of month (1–31), month (1–12) and day of week (0–6, with 0 = Sunday). Each field supports:

  • *: any value
  • numbers and comma lists: 5, 1,15,30
  • ranges: 9-17
  • steps: */15 or 10-50/20 (every 20 within 10–50)

Use the simple rule that all five fields must match. Raise ValueError for malformed expressions or out-of-range values. Then implement next_run(expr, after): the first matching minute strictly after after (with seconds and microseconds zeroed), searching at most one year ahead and returning None if nothing matches.

#parsing#scheduling#datetime2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Does This Cron Schedule Fire Now? · TechGradify