Skip to content

Fix a cron next-fire-time calculator (steps, names, macros, day-of-month OR day-of-week, leap days, strict validation)

Exact prompt

# Task: fix the cron schedule calculator `cron.py` has a function `next_fire(expr, after)` that should return the next time a cron schedule fires, but it gets many schedules wrong and is too slow for rare schedules. Fix it (rewrite freely) so it follows every rule below exactly. Python standard library only. Keep the function name and signature. No network. ## Rules 1. `expr` has exactly 5 whitespace-separated fields: minute (0-59), hour (0-23), day-of-month (1-31), month (1-12), day-of-week (0-7, where both 0 and 7 mean Sunday, 1 = Monday ... 6 = Saturday). Leading/trailing whitespace and multiple spaces between fields are allowed. 2. Each field is a comma-separated list of items. An item is `*`, a number `n`, a range `a-b` (inclusive, requires a <= b), or any of those followed by `/step` (step >= 1): `*/s` = every s-th value starting at the field minimum, `a-b/s` = a, a+s, ... up to b, and `a/s` = a, a+s, ... up to the field maximum. 3. Month names `JAN`-`DEC` and day names `SUN`-`SAT` may be used anywhere a number may be used in the month and day-of-week fields (including in ranges, e.g. `MON-FRI`), case-insensitive. 4. Macros (case-insensitive) replace the whole expression: `@yearly` and `@annually` = `0 0 1 1 *`, `@monthly` = `0 0 1 * *`, `@weekly` = `0 0 * * 0`, `@daily` and `@midnight` = `0 0 * * *`, `@hourly` = `0 * * * *`. 5. Day matching: if BOTH day-of-month and day-of-week are restricted (the field text is not exactly `*`), a day matches when EITHER field matches. If only one of them is restricted, only that one counts. A field like `*/1` or `1-31` counts as restricted. 6. `after` is a naive `datetime`. Return the earliest matching minute STRICTLY after `after`, as a naive `datetime` with seconds and microseconds 0. (If `after` is 10:00:30 and the schedule fires every minute, the answer is 10:01:00.) No time zones, no DST: treat times as plain calendar times. 7. Raise `ValueError` for: wrong number of fields, unknown macro, any value outside the field's range, `a > b` in a range, step 0 or a non-numeric step, empty items (e.g. `1,,2`), unknown names, or any other unparsable text. 8. If the schedule can never fire within 5 years after `after` (e.g. `0 0 31 2 *`), raise `ValueError` instead of looping forever. A schedule that fires only on 29 February must still be found (it is at most ~4 years away). 9. Every call must return (or raise) within 1 second on an ordinary machine, including the leap-day case. The grader runs a hidden unittest suite that checks exactly these rules.

The starting code ANDs day fields, ignores names/macros/7=Sunday, is inclusive of 'after', accepts invalid fields and scans minute by minute (too slow / never terminates for rare schedules). Each rule has exact expected datetimes. Original benchmark task written for usecaserank.com (not based on a specific public post). Headless, offline run on a reproducible fixture. Each run's notes say how its cost was measured (estimates are marked).

Success criteria: 1. All 8 hidden unittest cases pass (strictly-after semantics, lists/ranges/steps incl. a/s, month/day names, 0 and 7 = Sunday, macros, DOM/DOW OR rule incl. */1 as restricted, 18 invalid expressions raise ValueError, never-firing schedule raises within 1 s, 29 Feb found within 1 s).

Best model for this task so far: Claude Haiku 5.5 (effort default (no --effort flag) · thinking on) (success, $0.01, 1m).

Run this on another model

All runs (4)

100% pass rate across 4 eligible runs: 4 pass, 0 partial, 0 fail. Partial and failed runs are listed below with everything else.ⓘ

Runs for this use case
ModelCostTimeStep-insⓘAutonomyOutcomeTrustⓘDateCompare
OGPT-6.1 Soldefault · thinking on$0.061m0Fully autonomouspassTrust 80%2026-10-22
AClaude Haiku 5.5default · thinking on$0.011m0Fully autonomouspassTrust 80%2026-10-19
AClaude Opus 5.5default · thinking on$0.2151s0Fully autonomouspassTrust 80%2026-10-19
AClaude Sonnet 5.5default · thinking on$0.0722s0Fully autonomouspassTrust 80%2026-10-19

Embed this result

A live badge for this use case. It links back here and updates as new runs are published.

UseCaseRank badge for Fix a cron next-fire-time calculator (steps, names, macros, day-of-month OR day-of-week, leap days, strict validation)

Get new runs and ranking changes weekly

Which models got better or cheaper on real tasks like this one.