Skip to content

fix(builder): handle wall-clock times in a DST gap like GNU date - #346

Open
jayhemnani9910 wants to merge 2 commits into
uutils:mainfrom
jayhemnani9910:reject-nonexistent-local-time
Open

jayhemnani9910 wants to merge 2 commits into
uutils:mainfrom
jayhemnani9910:reject-nonexistent-local-time

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

Two problems with times in a DST gap (New York skips 02:00-03:00 on 2024-03-10):

$ TZ=America/New_York gnudate -d '2024-03-10 02:30'          # GNU coreutils 9.7
gnudate: invalid date '2024-03-10 02:30'
parse_datetime:                                               2024-03-10T03:30:00-04:00

$ TZ=America/New_York gnudate -u -d '2024-03-10 02:30 UTC' +%FT%TZ
2024-03-10T02:30:00Z
parse_datetime:                                               2024-03-10T03:30:00+00:00

The first is a time that doesn't exist; jiff's default disambiguation moves it past the gap, and GNU rejects it. The second is wrong by an hour: the date and time are first placed in the local zone, where 02:30 doesn't exist and becomes 03:30, and only then is the written zone applied to that wall clock. 02:30Z and T02:30:00Z are affected too; 02:30 +00:00 was already right because the time's own offset is applied first.

build_in_range now keeps the wall-clock time the input asked for. If the local zone moved it, the input named a time in a gap and is rejected. If the input carries a zone (UTC, Z, an offset), that zone is applied to the requested wall-clock time instead of the locally resolved one. A relative item that lands in a gap (2018-11-03 +1 day in Sao Paulo) still moves past it, as GNU does, and times in the repeated hour still take the first offset.

Tests: test_local_time_in_dst_gap_is_invalid, test_dst_gap_neighbours and test_relative_item_moves_past_dst_gap in tests/date.rs; 5 of the 9 cases fail on main. cargo test: 491 passed; clippy and fmt clean. 22 inputs in 6 zones (New York, Sao Paulo, Berlin, Lord Howe, Kolkata, UTC), covering gaps, the repeated hour, written zones and offsets, weekdays and relative items, give the same instant or error as GNU date 9.7.

Copilot AI balanced review requested due to automatic review settings October 27, 2026 06:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codspeed

codspeed Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 4.62%

3 warnings

⚠️ 16 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 4 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 4 benchmarks with a significant change ran in a different software environment

Their base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the changes might come from this difference rather than from the code. Open an affected benchmark to see what changed.

See affected benchmarks

❌ 4 regressed benchmarks
✅ 17 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ parse_epoch_timestamp 11.1 µs 11.9 µs -6.46%
❌ parse_date_only 26.9 µs 28.2 µs -4.62%
❌ parse_date_slash_format 26.4 µs 27.5 µs -3.93%
❌ parse_weekday 41 µs 42.5 µs -3.44%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing jayhemnani9910:reject-nonexistent-local-time (07e99b4) with main (6148e76)

Open in CodSpeed

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.98%. Comparing base (6148e76) to head (07e99b4).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #346   +/-   ##
=======================================
  Coverage   98.97%   98.98%           
=======================================
  Files          21       21           
  Lines        4698     4716   +18     
  Branches      143      144    +1     
=======================================
+ Hits         4650     4668   +18     
  Misses         47       47           
  Partials        1        1           
Flag Coverage Δ
macos_latest 98.98% <100.00%> (?)
ubuntu_latest 98.98% <100.00%> (+<0.01%) ⬆️
windows_latest 12.46% <40.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/items/builder.rs Outdated
let (offset, hour_adjustment) = offset.normalize();
dt = dt.checked_add(Span::new().hours(hour_adjustment))?;
dt = dt.datetime().to_zoned((&offset).try_into()?)?;
if need_midnight {

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.

when need_midnight is false there is no date/time/weekday, so wanted == dt.datetime() here
both branches do the same thing, just keep the wanted one, no?

Comment thread src/items/builder.rs Outdated

// A date or time that names a moment the time zone skips does not
// exist; jiff would move it past the gap.
if need_midnight && !fixed_offset && dt.datetime() != wanted {

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.

a date or a time already implies need_midnight, is this part of the condition needed?

Comment thread src/items/builder.rs Outdated
// A date or time that names a moment the time zone skips does not
// exist; jiff would move it past the gap.
if need_midnight && !fixed_offset && dt.datetime() != wanted {
return Err("invalid date: the local time does not exist in this time zone".into());

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.

the other errors don't have an "invalid date:" prefix, and coreutils already prints invalid date '...'
maybe just "local time does not exist in this time zone"?

Comment thread tests/date.rs
#[case::z(
r#"TZ="America/New_York" 2024-03-10T02:30:00Z"#,
"2024-03-10 02:30:00+00:00"
)]

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.

please also add 2024-03-10 02:30 +00:00 (already right but not tested) and 02:30Z without the T, they are both in the description

@jayhemnani9910

Copy link
Copy Markdown
Contributor Author

All four in 3ceb7bc:

  • builder.rs:373: kept only the wanted branch.
  • builder.rs:320: dropped need_midnight &&. Without a date or time, wanted is still the base's wall-clock time there, so the check can't fire.
  • builder.rs:321: the message is now local time does not exist in this time zone.
  • tests/date.rs:515: added 2024-03-10 02:30Z and 2024-03-10 02:30 +00:00 to test_dst_gap_neighbours. GNU date 9.7 gives 02:30:00+00:00 for both. On main, 02:30Z fails and 02:30 +00:00 already passes, as the description says.

cargo test, cargo fmt --check and cargo clippy --all-targets -- -D warnings are clean.

Copilot AI balanced review requested due to automatic review settings November 11, 2026 07:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

A date or time that falls in the local zone's DST gap was moved past the
gap by jiff (2024-03-10 02:30 in New York became 03:30). GNU date
rejects it as an invalid date, so do the same. A time written with its
own zone ("2024-03-10 02:30 UTC", "...T02:30:00Z") was built in the
local zone first and so came out an hour late; apply the zone to the
wall-clock time as written. A relative item that lands in a gap still
moves past it, as in GNU.
Without a date, time or weekday the wanted wall-clock time is the
base's, so the need_midnight checks change nothing. Shorten the error
message and test 02:30Z and 02:30 +00:00 in the gap.
@jayhemnani9910
jayhemnani9910 force-pushed the reject-nonexistent-local-time branch from 3ceb7bc to 07e99b4 Compare November 18, 2026 10:37
Copilot AI balanced review requested due to automatic review settings November 18, 2026 10:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@jayhemnani9910

Copy link
Copy Markdown
Contributor Author

On the CodSpeed flags: none of the 4 inputs has an offset (1997-01-01, 05/07/1987, @1613371067, wednesday), and the gap check is already skipped when there is one. parse_epoch_timestamp returns before any of the new code runs, and CodSpeed notes these ran on different hardware than the base.

Local cargo bench, mean, main vs this branch (two runs):

bench main PR PR
date_only 480 ns 499 ns 507 ns
date_slash 456 ns 464 ns 465 ns
epoch 154 ns 165 ns 155 ns
weekday 786 ns 858 ns 817 ns

Run-to-run noise is about ±5% here. What's left looks like a 2-5% cost from checking for the DST gap on local times, which I think is worth it for correct results. Happy to try a cheaper check if you'd rather not take it.

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.

3 participants