date: re-zone trailing TZ abbreviation input to local timezone#12327
Merged
sylvestre merged 1 commit intoMay 16, 2026
Conversation
The dedicated abbreviation-aware path `try_parse_with_abbreviation` in
`src/uu/date/src/date.rs` returned a `Zoned` in the input abbreviation
timezone (e.g. `-05` for `EST`). The generic `parse_datetime` fallback
already re-zones to `now.time_zone()` for display, so identical inputs
took two divergent code paths and only one matched GNU `date`.
GNU treats a trailing TZ abbreviation as describing the *input*
timezone; the output is always re-zoned into the local zone (or UTC
under `-u`). For example, under `TZ=UTC`:
$ date -d "2024-01-01 EST" # GNU
Mon Jan 1 05:00:00 UTC 2024
uutils previously emitted `Mon Jan 1 00:00:00 -05 2024`.
Convert the parsed instant to `now.time_zone()` before returning,
matching the fallback path and GNU’s behavior. `-u` still works
because `now` is already zoned to UTC in that case (date.rs:362),
and the final output stage still applies `with_time_zone(TimeZone::UTC)`
when `settings.utc` is set.
Un-ignores the existing regression test for this issue.
Fixes uutils/parse_datetime#281.
|
GNU testsuite comparison: |
Merging this PR will improve performance by 13.71%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | ls_recursive_balanced_tree[(6, 4, 15)] |
50.9 ms | 48.9 ms | +4.01% |
| ⚡ | Memory | cp_recursive_deep_tree[(120, 4)] |
699.2 KB | 562.5 KB | +24.31% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing 0xSoftBoi:fix/281-trailing-tz-abbrev-rezones (3783654) with main (d09f351)
Footnotes
-
46 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. ↩
Contributor
|
nice, thanks |
nonontb
pushed a commit
to nonontb/coreutils
that referenced
this pull request
May 28, 2026
…s#12327) The dedicated abbreviation-aware path `try_parse_with_abbreviation` in `src/uu/date/src/date.rs` returned a `Zoned` in the input abbreviation timezone (e.g. `-05` for `EST`). The generic `parse_datetime` fallback already re-zones to `now.time_zone()` for display, so identical inputs took two divergent code paths and only one matched GNU `date`. GNU treats a trailing TZ abbreviation as describing the *input* timezone; the output is always re-zoned into the local zone (or UTC under `-u`). For example, under `TZ=UTC`: $ date -d "2024-01-01 EST" # GNU Mon Jan 1 05:00:00 UTC 2024 uutils previously emitted `Mon Jan 1 00:00:00 -05 2024`. Convert the parsed instant to `now.time_zone()` before returning, matching the fallback path and GNU’s behavior. `-u` still works because `now` is already zoned to UTC in that case (date.rs:362), and the final output stage still applies `with_time_zone(TimeZone::UTC)` when `settings.utc` is set. Un-ignores the existing regression test for this issue. Fixes uutils/parse_datetime#281.
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.
Summary
try_parse_with_abbreviationinsrc/uu/date/src/date.rsreturned aZonedin the input abbreviation timezone (e.g.-05forEST). The genericparse_datetimefallback already re-zones tonow.time_zone()for display, so identical inputs took two divergent paths and only one matched GNUdate.GNU treats a trailing TZ abbreviation as describing the input timezone; the output is always re-zoned into the local zone (or UTC under
-u). UnderTZ=UTC:What changed
The abbreviation-aware path now does the same
with_time_zone(now.time_zone().clone())re-zoning the generic fallback already does.-ustill produces UTC output becausenowis zoned to UTC in that case (date.rs:362), and the final output stage still applieswith_time_zone(TimeZone::UTC)whensettings.utcis set, so the existing-u+ abbreviation tests (test_date_utc_with_d_flag,test_date_tz_abbreviation_fixed_offset_outside_season) are unchanged.Testing
tests/by-util/test_date.rsalready contained an#[ignore]d regression test for this issue; this PR un-ignores it. Fulluu_datetest suite is green locally:Fixes uutils/parse_datetime#281.