Skip to content

Commit 7e83262

Browse files
committed
style: apply cargo fmt formatting
Apply standard Rust formatting to: - Align comments and improve readability in parse_date function - Format test function calls for better parameter visibility - Remove trailing whitespace No functional changes, just code style improvements.
1 parent 2b44c3c commit 7e83262

File tree

2 files changed

+57
-21
lines changed

2 files changed

+57
-21
lines changed

src/uu/date/src/date.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ fn make_format_string(settings: &Settings) -> &str {
451451
/// Parse a `String` into a `DateTime`.
452452
/// If it fails, return a tuple of the `String` along with its `ParseError`.
453453
// TODO: Convert `parse_datetime` to jiff and remove wrapper from chrono to jiff structures.
454-
// NOTE: Currently uses chrono as bandaid fix for issue #8976 (timezone parsing bug).
454+
// NOTE: Currently uses chrono as band-aid fix for issue #8976 (timezone parsing bug).
455455
// This reintroduces chrono dependencies that were removed in jiff migration.
456456
fn parse_date<S: AsRef<str> + Clone>(
457457
s: S,
@@ -460,24 +460,25 @@ fn parse_date<S: AsRef<str> + Clone>(
460460
// This ensures dates without timezone are interpreted as local time for that specific date
461461
// (not the current date's timezone offset)
462462
let formats = [
463-
"%Y-%m-%d %H:%M:%S", // "2025-03-29 8:30:00"
464-
"%Y-%m-%d %H:%M", // "2025-03-29 8:30"
465-
"%Y-%m-%d", // "2025-03-29"
463+
"%Y-%m-%d %H:%M:%S", // "2025-03-29 8:30:00"
464+
"%Y-%m-%d %H:%M", // "2025-03-29 8:30"
465+
"%Y-%m-%d", // "2025-03-29"
466466
];
467-
467+
468468
for format in &formats {
469469
if let Ok(naive) = NaiveDateTime::parse_from_str(s.as_ref(), format) {
470470
// Convert naive datetime to local time, which will use the correct timezone offset
471471
// for that specific date (not the current date's offset)
472472
if let LocalResult::Single(local) = Local.from_local_datetime(&naive) {
473473
let timestamp =
474-
Timestamp::new(local.timestamp(), local.timestamp_subsec_nanos() as i32).unwrap();
474+
Timestamp::new(local.timestamp(), local.timestamp_subsec_nanos() as i32)
475+
.unwrap();
475476
let timezone = TimeZone::try_system().unwrap_or(TimeZone::UTC);
476477
return Ok(Zoned::new(timestamp, timezone));
477478
}
478479
}
479480
}
480-
481+
481482
// Fall back to parse_datetime for more complex parsing (relative dates, etc.)
482483
let ref_time = Local::now();
483484
match parse_datetime::parse_datetime_at_date(ref_time, s.as_ref()) {

tests/by-util/test_date.rs

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ fn test_date_timezone_parsing_fix() {
688688
// Test the fix for issue #8976: dates without timezone should be interpreted as local time
689689
// This test ensures that dates like "2025-03-29 8:30:00" are interpreted as 8:30 in the
690690
// local timezone for that specific date, not as UTC converted to local time.
691-
691+
692692
fn test_tz_parsing(tz: &str, date: &str, expected_time: &str, expected_tz: &str) {
693693
println!("Test with TZ={tz}, date=\"{date}\".");
694694
new_ucmd!()
@@ -702,23 +702,58 @@ fn test_date_timezone_parsing_fix() {
702702

703703
// Test Europe/Prague timezone (CET/CEST) - the timezone from the original issue
704704
// March 29, 2025 is in standard time (CET, UTC+1)
705-
test_tz_parsing("Europe/Prague", "2025-03-29 8:30:00", "2025-03-29 08:30:00", "CET");
706-
707-
// March 30, 2025 is in daylight saving time (CEST, UTC+2)
708-
test_tz_parsing("Europe/Prague", "2025-03-30 8:30:00", "2025-03-30 08:30:00", "CEST");
709-
705+
test_tz_parsing(
706+
"Europe/Prague",
707+
"2025-03-29 8:30:00",
708+
"2025-03-29 08:30:00",
709+
"CET",
710+
);
711+
712+
// March 30, 2025 is in daylight saving time (CEST, UTC+2)
713+
test_tz_parsing(
714+
"Europe/Prague",
715+
"2025-03-30 8:30:00",
716+
"2025-03-30 08:30:00",
717+
"CEST",
718+
);
719+
710720
// October 25, 2025 is still in daylight saving time (CEST, UTC+2)
711-
test_tz_parsing("Europe/Prague", "2025-10-25 8:30:00", "2025-10-25 08:30:00", "CEST");
712-
721+
test_tz_parsing(
722+
"Europe/Prague",
723+
"2025-10-25 8:30:00",
724+
"2025-10-25 08:30:00",
725+
"CEST",
726+
);
727+
713728
// October 26, 2025 is back to standard time (CET, UTC+1)
714-
test_tz_parsing("Europe/Prague", "2025-10-26 8:30:00", "2025-10-26 08:30:00", "CET");
715-
729+
test_tz_parsing(
730+
"Europe/Prague",
731+
"2025-10-26 8:30:00",
732+
"2025-10-26 08:30:00",
733+
"CET",
734+
);
735+
716736
// Test the original issue case
717-
test_tz_parsing("Europe/Prague", "2031-01-26 8:30", "2031-01-26 08:30:00", "CET");
718-
737+
test_tz_parsing(
738+
"Europe/Prague",
739+
"2031-01-26 8:30",
740+
"2031-01-26 08:30:00",
741+
"CET",
742+
);
743+
719744
// Test other timezone to ensure the fix works generally
720-
test_tz_parsing("America/New_York", "2025-03-29 8:30:00", "2025-03-29 08:30:00", "EDT");
721-
test_tz_parsing("America/New_York", "2025-01-15 8:30:00", "2025-01-15 08:30:00", "EST");
745+
test_tz_parsing(
746+
"America/New_York",
747+
"2025-03-29 8:30:00",
748+
"2025-03-29 08:30:00",
749+
"EDT",
750+
);
751+
test_tz_parsing(
752+
"America/New_York",
753+
"2025-01-15 8:30:00",
754+
"2025-01-15 08:30:00",
755+
"EST",
756+
);
722757
}
723758

724759
#[test]

0 commit comments

Comments
 (0)