Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,11 +853,17 @@ fn try_parse_with_abbreviation<S: AsRef<str>>(date_str: S, now: &Zoned) -> Optio

if let Some(tz) = tz {
let date_part = s.trim_end_matches(last_word).trim();
// Parse in the target timezone so "10:30 EDT" means 10:30 in EDT
// Parse in the target timezone so "10:30 EDT" means 10:30 in EDT.
if let Ok(parsed) = parse_datetime::parse_datetime_at_date(now.clone(), date_part) {
let dt = parsed.datetime();
if let Ok(zoned) = dt.to_zoned(tz) {
return Some(zoned);
// The trailing abbreviation only describes the *input*
// timezone. For display, re-zone to the system timezone
// (i.e. `now`'s zone, which is UTC under `-u`). This
// matches GNU `date` and keeps this path consistent
// with the generic `parse_datetime` fallback below,
// which already re-zones via `to_zoned(now.time_zone())`.
return Some(zoned.with_time_zone(now.time_zone().clone()));
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions tests/by-util/test_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1873,10 +1873,12 @@ fn test_date_input_hhmm_ampm() {
}

#[test]
#[ignore = "https://github.com/uutils/parse_datetime/issues/281 — GNU date re-zones input with trailing TZ abbreviation (e.g. `2024-01-01 EST`) into the local TZ; uutils keeps the input TZ on output."]
fn test_date_input_trailing_tz_abbrev_rezones() {
// `TZ=UTC+1 date -d '2024-01-01 EST'` should display the instant in UTC+1
// (GNU: 04:00:00 UTC), not leave it in EST (uutils: 00:00:00 -05).
// (GNU: 04:00:00 -01:00), not leave it in EST (the pre-fix uutils
// behavior was 00:00:00 -05). The trailing abbreviation only specifies
// the input timezone; output should be re-zoned to local.
// Regression test for https://github.com/uutils/parse_datetime/issues/281.
new_ucmd!()
.env("LC_ALL", "C")
.env("TZ", "UTC+1")
Expand Down
Loading