Skip to content

A cron weekday written as a number reads as standard cron, so 1-5 syncs Monday to Friday instead of Sunday to Thursday - #1399

Open
rudycelekli wants to merge 2 commits into
deeplethe:devfrom
rudycelekli:fix/cron-standard-weekdays
Open

rudycelekli wants to merge 2 commits into
deeplethe:devfrom
rudycelekli:fix/cron-standard-weekdays

Conversation

@rudycelekli

Copy link
Copy Markdown
Contributor

Why

The Advanced schedule field links to crontab.guru, and validate_cron documents itself as taking a standard 5-field cron expression. The cron crate (0.12.1) that evaluates it numbers weekdays Quartz-style: 1 = Sunday … 7 = Saturday, and 0 is out of range. So a source saved with Advanced 0 9 * * 1-5 ("weekdays at 09:00" on crontab.guru) syncs Sunday to Thursday, and 0 9 * * 0 (Sundays) is rejected as invalid. The Weekly picker is unaffected because it already writes weekday names.

What changes

crates/utopia-store/src/sources.rs: before validating, validate_cron rewrites a numeric weekday field using standard cron semantics (0–7, where 0 and 7 are both Sunday; lists, ranges and /step) into weekday names, which both readings agree on. That is what gets stored: 1-5 becomes Mon,Tue,Wed,Thu,Fri. A field without digits, or one it cannot read, is passed to the cron crate unchanged. Rows already saved with numeric weekdays keep their current reading until they are saved again.

How it was checked

  • New unit test cron_weekday_numbers_read_as_standard_cron covers 1-5, 0 and 5-7.
  • I could not build the whole utopia-store crate locally (the disk is full). So I compiled the exact validate_cron region of this file, plus both tests, in a scratch crate pinned to cron = "=0.12.1":
    • Before the fix: cron_validation passes and the new test fails (left: "0 9 * * 1-5"). A schedule built from the stored 0 9 * * 1-5 and started on Saturday 2026-10-24 next fires on a Sunday.
    • After the fix: all pass, and the same Saturday start next fires on Monday. Clippy -D warnings is clean on that crate, and rustfmt --check is clean on sources.rs.
  • I have not run cargo test --workspace locally. CI covers it.

Before review

  • Every commit is signed off (git commit -s)
  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings and cargo test --workspace pass (left to CI; see above)

@WaylandYang WaylandYang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, thanks: the cron crate counts weekdays from 1 = Sunday, so 0 9 * * 1-5 runs Sunday to Thursday today. Please apply the same rewrite in cron_next_after (or add a migration), so sources already saved with 1-5 don't keep running Sunday to Thursday.

…cs Monday to Friday instead of Sunday to Thursday

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>
…on, so a stored 1-5 stops running Sunday to Thursday

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>
@rudycelekli
rudycelekli force-pushed the fix/cron-standard-weekdays branch from ce4f4fb to 27e17ff Compare November 5, 2026 03:17
@rudycelekli

Copy link
Copy Markdown
Contributor Author

cron_next_after now applies the same weekday rewrite before it parses a stored expression, so a source saved earlier with 0 9 * * 1-5 next runs on Monday rather than Sunday; a_source_saved_with_weekday_numbers_runs_on_standard_cron_days covers it. Rebased on dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants