Skip to content
Draft
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
29 changes: 15 additions & 14 deletions src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,24 +708,25 @@ fn format_date_with_locale_aware_months(
config: &Config<PosixCustom>,
skip_localization: bool,
) -> Result<String, String> {
// First check if format string has GNU modifiers (width/flags) and format if present
// This optimization combines detection and formatting in a single pass
if let Some(result) =
format_modifiers::format_with_modifiers_if_present(date, format_string, config)
{
// Apply locale-aware name substitution (month/day names) before modifier
// processing, so that formats like "%-e" don't bypass localization of "%b"/"%A".
let localized;
let fmt = if !skip_localization && should_use_icu_locale() {
localized = localize_format_string(format_string, date.date());
&localized
} else {
format_string
};

// Check if format string has GNU modifiers (width/flags) and format if present
if let Some(result) = format_modifiers::format_with_modifiers_if_present(date, fmt, config) {
return result.map_err(|e| e.to_string());
}

let broken_down = BrokenDownTime::from(date);

let result = if !should_use_icu_locale() || skip_localization {
broken_down.to_string_with_config(config, format_string)
} else {
let fmt = localize_format_string(format_string, date.date());
broken_down.to_string_with_config(config, &fmt)
};

result.map_err(|e| e.to_string())
broken_down
.to_string_with_config(config, fmt)
.map_err(|e| e.to_string())
}

/// Return the appropriate format string for the given settings.
Expand Down
40 changes: 40 additions & 0 deletions tests/by-util/test_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,45 @@
}
}

#[test]
fn test_date_locale_hu_hungarian() {
// Test Hungarian locale (hu_HU.UTF-8) behavior
// Hungarian typically uses 24-hour format and may have localized day/month names

let result = new_ucmd!()
.env("LC_ALL", "hu_HU.UTF-8")
.env("TZ", "UTC")
.arg("-d")
.arg("2025-12-14T13:00:00")
.succeeds();

let stdout = result.stdout_str();

// Hungarian locale should use 24-hour format (no AM/PM)
assert!(
!stdout.contains("AM") && !stdout.contains("PM"),
"Hungarian locale should use 24-hour format (no AM/PM), got: {stdout}"
);

// Should have 13:00 (not 1:00)
assert!(
stdout.contains("13:00"),
"Hungarian locale should show 13:00 for 1 PM, got: {stdout}"
);

// Timezone should be included (our implementation adds %Z if missing)
assert!(
stdout.contains("UTC") || stdout.contains("+00") || stdout.contains('Z'),
"Output should include timezone information, got: {stdout}"
);

// Check proper formatting (no double dots, day name, etc.) of entire output
assert!(
stdout == "2025. dec. 14., vasárnap, 13:00:00 UTC\n",

Check failure on line 1656 in tests/by-util/test_date.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

ERROR: `cspell`: Unknown word 'vasárnap' (file:'tests/by-util/test_date.rs', line:1656)
"Incorrect Hungarian output format, got: {stdout}"
);
}

#[test]
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
fn test_date_locale_fr_french() {
Expand Down Expand Up @@ -2149,6 +2188,7 @@
("es_ES.UTF-8", "enero", "junio", "diciembre"),
("it_IT.UTF-8", "gennaio", "giugno", "dicembre"),
("pt_BR.UTF-8", "janeiro", "junho", "dezembro"),
("hu_HU.UTF-8", "január", "június", "december"),

Check failure on line 2191 in tests/by-util/test_date.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

ERROR: `cspell`: Unknown word 'június' (file:'tests/by-util/test_date.rs', line:2191)

Check failure on line 2191 in tests/by-util/test_date.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

ERROR: `cspell`: Unknown word 'január' (file:'tests/by-util/test_date.rs', line:2191)
("ja_JP.UTF-8", "1月", "6月", "12月"),
("zh_CN.UTF-8", "一月", "六月", "十二月"),
] {
Expand Down
Loading