Repository navigation
feat(core): time zone rules with a replaceable source (#580, part 1) - #641
Merged
Merged
Conversation
The zone layer for per-job time zones, with no embedded data and no new dependency. Schedules do not use it yet (part 2). - tz::Zone: UTC, a fixed offset (at most 14 hours) or rules from TZif bytes (RFC 8536 versions 1 to 4, including the POSIX TZ footer that slim zoneinfo files use for every future date) or a POSIX TZ string. - Zone::from_local maps a wall-clock time to one instant, the first instant after a DST gap, or both instants of an overlap. - ZoneSource is a trait. OffsetOnly takes no data and refuses IANA names with the remedy; ZoneinfoDir reads the host's zoneinfo at run time, follows alias links only inside the directory, requires a regular file of at most 512 KiB and never waits on a FIFO. - Invalid names, offsets and TZif data are errors with a remedy, never a panic; leap-second zones are refused.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Part 1 of #580: the time-zone layer in
tole-core(tz), with no embedded zone data and no new dependency. Schedules do not use it yet. Part 2 wires per-job time zones into the schedules, the ledger (eachfirerecords its zone and DST case), the CLI (--timezone,cron.timezone,cron.tz_source,listin local and UTC) and the docs.Why
Jobs must fire at the owner's wall-clock time (09:00 Asia/Jakarta) without silently assuming UTC and without forcing a tz database into every binary (#580, design §4). The full change is about 1,900 lines, so it is split at the cleanest seam: the self-contained zone layer here, then its use.
Changes
How a zone is resolved
tz::Zoneis one of:+HH:MM/-HH:MM(at most 14 hours);EST5EDT,M3.2.0,M11.1.0).TZif: the listed transitions are used, then the POSIX TZ footer for every later instant. That matters: slim zoneinfo files, the default since tzdata 2020b, describe all future DST changes only through the footer. The footer supports
Mm.w.d,Jnandndates, signed times up to 167 hours (TZif v3) and southern-hemisphere rules (DST across the new year).Zone::from_local(wall_clock)returns one of:Single(t): exactly one instant;Gap(t): the time does not exist, andtis the first instant after the gap. It is found by binary search on the offset, so no next-transition logic is needed;Ambiguous(first, second): the time happens twice.Part 2's schedule fires a gap time at
tand an ambiguous time only atfirst, which gives at-most-once.ZoneSourceis the replaceable source, a trait:OffsetOnly(default, no data) refuses every IANA name with the remedy: use UTC or+07:00, or setcron.tz_source = "system".ZoneinfoDirreads/usr/share/zoneinfo(or any directory) at run time, so rules follow OS tzdata updates at zero binary cost. It follows the directory's own alias links (US/Eastern), but never a link that leads out of it. It requires a regular file of at most 512 KiB and opens withO_NONBLOCK, so a FIFO is refused instead of waited on.tz::resolve(source, name)handlesUTCand offsets itself. It refuses an invalid name before any disk access: 1 to 64 bytes,/-separated components of[A-Za-z0-9_+-], none empty or starting with.. Only then does it ask the source. Every error names the zone, says what is wrong and gives a remedy.Robustness: TZif parsing is bounds-checked with checked arithmetic. Counts, type indices, transition order and offsets (±26 h) are validated, and the footer must parse. Leap-second (
right/) zones are refused. Bad data is an error, never a panic, and evaluation saturates instead of overflowing.Decisions to check
bundledis not built. The issue lists atz-bundledcargo feature. A bundled database is just anotherZoneSource, so it can come later as a separate feature or crate. Nothing is embedded in core now, and there is no binary-size delta to report. The issue's measurement belongs with that feature.Cargo.tomlorCargo.lockchange. Unique crates fromcargo tree -e normal --prefix none | sort -u:tole-core --no-default-featuresstays at 50 andtole-cliat 207, so the delta is 0.libcwas already a dependency; it is used forO_NONBLOCKundercfg(unix)only.+HH:MM.+7,+0700and07:00are refused with the expected form.M3.2.0,M11.1.0) is used, as glibc does. Real zoneinfo footers always carry a rule.Docs
docs/automation-design.md§4: an "as implemented, part 1" note.[Unreleased]/ Added.Testing
New
crates/tole-core/tests/tz_rules.rs(8 tests):from_localfor a normal time, a gap (02:30 on 2026-03-08 → 07:00Z) and an overlap (01:30 on 2026-11-01 → 05:30Z and 06:30Z);+07:00remedy, offset-only naming its source and the fix, path-like names refused before disk access, and a missing zone naming the directory;America/New_Yorkfile);ZoneSourceserves names, its errors pass through, and offsets and validation stay the same.The tests were written before the code; they could not compile until the API existed, so each rule's proof is a deliberate break, restored after each:
names_and_offsets_are_validated_with_a_remedybroken_tzif_data_is_an_error_never_a_panicbroken_tzif_data_is_an_error_never_a_panictzif_transitions_then_the_footer_rulenames_and_offsets_are_validated_with_a_remedya_zoneinfo_dir_stays_inside_itself_and_never_blocksO_NONBLOCK(FIFO blocks)a_zoneinfo_dir_stays_inside_itself_and_never_blocksoffsets_follow_the_rule_around_both_changeslocal_times_map_to_one_instant_a_gap_or_two_instantslocal_times_map_to_one_instant_a_gap_or_two_instantsThe schedule-level DST tests (wall-clock
0 9 * * *across both changes, a skipped 02:30 firing once at 03:00, a repeated 01:30 firing once,*/30across the gap and the overlap, starting inside the repeated hour) and the ledger tests are written and pass on the part 2 work, with their own deliberate breaks. They come with part 2.Gates:
cargo fmt --allcargo clippy --workspace --all-targets --all-features -- -D warningscargo clippy -p tole-core --no-default-features --all-targets -- -D warningscargo test --workspace: 1627 passedcargo test -p tole-core --no-default-features: 574 passedcora review --no-llm --staged: no issues