Skip to content

date: parse a trailing zone abbreviation in its own zone - #16148

Open
unsound-mint wants to merge 1 commit into
uutils:mainfrom
unsound-mint:date-abbrev-dst-gap
Open

unsound-mint wants to merge 1 commit into
uutils:mainfrom
unsound-mint:date-abbrev-dst-gap

Conversation

@unsound-mint

@unsound-mint unsound-mint commented Nov 2, 2026 •

Copy link
Copy Markdown

TZ=America/New_York date -d 'Sun, 10 Mar 2024 02:30:00 GMT' +%s prints 1710041400 (03:30 GMT) instead of 1710037800. 02:30 doesn't exist in New York that day, and try_parse_with_abbreviation() parsed the time against the local now before applying GMT, so the local DST rule moved it forward an hour. Relative hour items (24 hours, 2 hours ago) were counted on the local time line as well.

It now parses against now's local date and time placed in the abbreviation's zone, so the default date still comes from local time as in GNU. Because the mismatch check now compares against the abbreviation's zone, names_zone also counts a word with an odd number of - (12:00-0500 EST, 12-0500 EST), which GNU rejects.

Tests: gap and relative cases (including 2 hours ago and a fall-back crossing) under TZ=America/New_York, -f under Europe/Berlin, and the two rejections.

One result differs from GNU, as the issue notes: 2024-03-09 02:30:00 1 day GMT under TZ=America/New_York now gives 1710037800 (02:30 GMT). GNU 9.10 applies day units in local time and gives 1710041400.

Not covered here, because the zone is resolved inside the parse_datetime crate and not in this function: 2024-03-10T02:30:00Z, Sun Mar 10 02:30:00 UTC 2024 and touch -d. They are the subject of uutils/parse_datetime#346. I built coreutils against that branch and all three give 1710037800 there, same as GNU. That is why this says Refs and not Closes.

@cakebaker
cakebaker force-pushed the date-abbrev-dst-gap branch from b2399e0 to 0bdb3bd Compare November 3, 2026 09:21
@codspeed

codspeed Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 2 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

✅ 12 untouched benchmarks
⏩ 464 skipped benchmarks1


Comparing unsound-mint:date-abbrev-dst-gap (ef01a0d) with main (a68dc1e)2

Open in CodSpeed

Footnotes

  1. 464 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (76b9401) during the generation of this report, so a68dc1e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Comment thread src/uu/date/src/date.rs Outdated
// Parse in the target timezone so "10:30 EDT" means 10:30 in EDT. Parsing
// against the local `now` would move a wall-clock time that falls into a
// local DST gap forward before the abbreviation is applied.
let now_in_tz = now.with_time_zone(tz.clone());

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.

this also changes the default date: with TZ=Asia/Tokyo at 08:00, -d '10:30 UTC' now gets yesterday's date (it's still the previous day in UTC).
GNU takes the date from local time. Could you use now.datetime().to_zoned(tz.clone()) instead, to keep the local wall clock?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done: the default date now comes from now.datetime().to_zoned(tz), so -d '10:30 UTC' under TZ=Asia/Tokyo keeps the local date, same as GNU.

Comment thread tests/by-util/test_date.rs Outdated
fn test_date_abbreviation_in_local_dst_gap() {
// 02:30 does not exist in America/New_York on 2024-03-10, but the input
// names GMT, so the local DST rules must not shift it.
for input in ["Sun, 10 Mar 2024 02:30:00 GMT", "2024-03-10 02:30:00 UTC"] {

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.

could you please also add the relative case from the issue, e.g. 2024-03-09 12:00 24 hours GMT?

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.

also, can you use rstest?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added 2024-03-09 12:00 24 hours GMT, and the cases are now rstest cases.

Comment thread src/uu/date/src/date.rs
if zoned.time_zone() != now_in_tz.time_zone() {
return None;
}

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.

this comment is now stale: the comparison is against now_in_tz, not now

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Comment updated.

@anastygnome

Copy link
Copy Markdown
Contributor

@unsound-mint nice, can you use rstest in your PR?

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/env/printenv is no longer failing!

#[rstest]
#[case::rfc2822_gmt("Sun, 10 Mar 2024 02:30:00 GMT", "1710037800\n")]
#[case::iso_utc("2024-03-10 02:30:00 UTC", "1710037800\n")]
#[case::relative_hours("2024-03-09 12:00 24 hours GMT", "1710072000\n")]

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.

could you please also add the other direction from the issue, 2024-03-10 04:00 2 hours ago GMT?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added 2024-03-10 04:00 2 hours ago GMT (1710036000), plus the fall-back case from the issue and -f under Europe/Berlin.

try_parse_with_abbreviation() split off the abbreviation and parsed the
rest against `now` in the local zone. A wall-clock time that falls into a
local DST gap was therefore moved forward an hour before the abbreviation
was applied, so e.g. with TZ=America/New_York,
`date -d "Sun, 10 Mar 2024 02:30:00 GMT" +%s` printed 03:30 GMT. Relative
hour items were counted on the local time line too.

Parse against `now`'s local date and time placed in the abbreviation's
zone instead, which is what the existing comment says the code does. The
default date still comes from local time, as in GNU.

The zone-mismatch check now compares against the abbreviation's zone, so
an offset glued to the time ("12:00-0500 EST") no longer looks like the
abbreviation's own zone; detect it by an odd number of '-' in a word.

Refs uutils#15772

This branch has not been deployed

No deployments
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