Skip to content

Commit 980fc7f

Browse files
committed
date: fix parse_datetime 0.13 API compatibility issues
1 parent 641e0ef commit 980fc7f

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fuzz/Cargo.lock

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/date/src/date.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,9 @@ fn make_format_string(settings: &Settings) -> &str {
459459
/// - MST: Mountain Standard Time (US) preferred over Malaysia Standard Time
460460
/// - PST: Pacific Standard Time (US) - widely used abbreviation
461461
/// - GMT: Alias for UTC (universal)
462+
/// - Australian timezones: AWST, ACST, AEST (cannot be dynamically discovered)
462463
///
463-
/// All other timezones (AWST, JST, CET, etc.) are dynamically resolved from IANA database. // spell-checker:disable-line
464+
/// All other timezones (JST, CET, etc.) are dynamically resolved from IANA database. // spell-checker:disable-line
464465
static PREFERRED_TZ_MAPPINGS: &[(&str, &str)] = &[
465466
// Universal (no ambiguity, but commonly used)
466467
("UTC", "UTC"),
@@ -476,6 +477,12 @@ static PREFERRED_TZ_MAPPINGS: &[(&str, &str)] = &[
476477
("EDT", "America/New_York"),
477478
// Other highly ambiguous cases
478479
("IST", "Asia/Kolkata"), // Ambiguous: India vs Israel vs Ireland // spell-checker:disable-line
480+
// Australian timezones (cannot be discovered from IANA location names)
481+
("AWST", "Australia/Perth"), // Australian Western Standard Time
482+
("ACST", "Australia/Adelaide"), // Australian Central Standard Time
483+
("ACDT", "Australia/Adelaide"), // Australian Central Daylight Time
484+
("AEST", "Australia/Sydney"), // Australian Eastern Standard Time
485+
("AEDT", "Australia/Sydney"), // Australian Eastern Daylight Time
479486
];
480487

481488
/// Lazy-loaded timezone abbreviation lookup map built from IANA database.
@@ -547,18 +554,15 @@ fn resolve_tz_abbreviation<S: AsRef<str>>(date_str: S) -> String {
547554
// Try to parse the date with UTC first to get timestamp
548555
let date_with_utc = format!("{date_part} +00:00");
549556
if let Ok(parsed) = parse_datetime::parse_datetime(&date_with_utc) {
550-
// Create timestamp from parsed date
551-
if let Ok(ts) = Timestamp::new(
552-
parsed.timestamp(),
553-
parsed.timestamp_subsec_nanos() as i32,
554-
) {
555-
// Get the offset for this specific timestamp in the target timezone
556-
let zoned = ts.to_zoned(tz);
557-
let offset_str = format!("{}", zoned.offset());
558-
559-
// Replace abbreviation with offset
560-
return format!("{date_part} {offset_str}");
561-
}
557+
// Get timestamp from parsed date (which is already a Zoned)
558+
let ts = parsed.timestamp();
559+
560+
// Get the offset for this specific timestamp in the target timezone
561+
let zoned = ts.to_zoned(tz);
562+
let offset_str = format!("{}", zoned.offset());
563+
564+
// Replace abbreviation with offset
565+
return format!("{date_part} {offset_str}");
562566
}
563567
}
564568
}
@@ -585,7 +589,12 @@ fn parse_date<S: AsRef<str> + Clone>(
585589
let resolved = resolve_tz_abbreviation(s.as_ref());
586590

587591
match parse_datetime::parse_datetime(&resolved) {
588-
Ok(date) => Ok(date),
592+
Ok(date) => {
593+
// Convert to system timezone for display
594+
// (parse_datetime 0.13 returns Zoned in the input's timezone)
595+
let timestamp = date.timestamp();
596+
Ok(timestamp.to_zoned(TimeZone::try_system().unwrap_or(TimeZone::UTC)))
597+
}
589598
Err(e) => Err((s.as_ref().into(), e)),
590599
}
591600
}

0 commit comments

Comments
 (0)