From 5dcdba102e2c4dc8ce83778b804ced06a3e9ac47 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 14 Feb 2026 20:39:45 +0100 Subject: [PATCH] date: fix RFC-822 format to always use English names (#10932) fixed gnu rfc822-1 RFC-822/RFC-2822/RFC-5322 formats must use English day and month names regardless of locale per RFC specification. Previously, these formats were being localized (e.g., "So" instead of "Sun" with de_DE locale). --- src/uu/date/src/date.rs | 12 ++++++++++-- tests/by-util/test_date.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index 56b6ee37c..acdbbce2c 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -478,7 +478,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } else { date }; - match format_date_with_locale_aware_months(&date, format_string, &config) { + let skip_localization = + matches!(settings.format, Format::Rfc5322 | Format::Rfc3339(_)); + match format_date_with_locale_aware_months( + &date, + format_string, + &config, + skip_localization, + ) { Ok(s) => writeln!(stdout, "{s}").map_err(|e| { USimpleError::new(1, translate!("date-error-write", "error" => e)) })?, @@ -622,10 +629,11 @@ fn format_date_with_locale_aware_months( date: &Zoned, format_string: &str, config: &Config, + skip_localization: bool, ) -> Result { let broken_down = BrokenDownTime::from(date); - if !should_use_icu_locale() { + if !should_use_icu_locale() || skip_localization { return broken_down.to_string_with_config(config, format_string); } diff --git a/tests/by-util/test_date.rs b/tests/by-util/test_date.rs index bddbbaf78..e88d4f5d0 100644 --- a/tests/by-util/test_date.rs +++ b/tests/by-util/test_date.rs @@ -86,6 +86,32 @@ fn test_date_email_multiple_aliases() { .succeeds(); } +#[test] +#[cfg(unix)] +fn test_date_rfc_822_uses_english() { + // RFC-822/RFC-2822/RFC-5322 formats should always use English day/month names + // regardless of locale (per RFC specification) + let scene = TestScenario::new(util_name!()); + + // Test with German locale - should still output "Sun" not "So" + scene + .ucmd() + .env("LC_ALL", "de_DE.UTF-8") + .env("TZ", "UTC") + .args(&["-R", "-d", "1997-01-19 08:17:48 +0"]) + .succeeds() + .stdout_contains("Sun, 19 Jan 1997"); + + // Test with French locale - should still output "Sun" not "dim." + scene + .ucmd() + .env("LC_ALL", "fr_FR.UTF-8") + .env("TZ", "UTC") + .args(&["-R", "-d", "1997-01-19 08:17:48 +0"]) + .succeeds() + .stdout_contains("Sun, 19 Jan 1997"); +} + #[test] fn test_date_rfc_3339() { let scene = TestScenario::new(util_name!());