Skip to content

Commit da0fec0

Browse files
committed
date: fix RFC-822 format to always use English names
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).
1 parent e4b3b5c commit da0fec0

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/uu/date/src/date.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
487487
} else {
488488
date
489489
};
490-
match format_date_with_locale_aware_months(&date, format_string, &config) {
490+
let skip_localization =
491+
matches!(settings.format, Format::Rfc5322 | Format::Rfc3339(_));
492+
match format_date_with_locale_aware_months(
493+
&date,
494+
format_string,
495+
&config,
496+
skip_localization,
497+
) {
491498
Ok(s) => writeln!(stdout, "{s}").map_err(|e| {
492499
USimpleError::new(1, translate!("date-error-write", "error" => e))
493500
})?,
@@ -631,10 +638,11 @@ fn format_date_with_locale_aware_months(
631638
date: &Zoned,
632639
format_string: &str,
633640
config: &Config<PosixCustom>,
641+
skip_localization: bool,
634642
) -> Result<String, jiff::Error> {
635643
let broken_down = BrokenDownTime::from(date);
636644

637-
if !should_use_icu_locale() {
645+
if !should_use_icu_locale() || skip_localization {
638646
return broken_down.to_string_with_config(config, format_string);
639647
}
640648

tests/by-util/test_date.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,32 @@ fn test_date_email_multiple_aliases() {
8686
.succeeds();
8787
}
8888

89+
#[test]
90+
#[cfg(unix)]
91+
fn test_date_rfc_822_uses_english() {
92+
// RFC-822/RFC-2822/RFC-5322 formats should always use English day/month names
93+
// regardless of locale (per RFC specification)
94+
let scene = TestScenario::new(util_name!());
95+
96+
// Test with German locale - should still output "Sun" not "So"
97+
scene
98+
.ucmd()
99+
.env("LC_ALL", "de_DE.UTF-8")
100+
.env("TZ", "UTC")
101+
.args(&["-R", "-d", "1997-01-19 08:17:48 +0"])
102+
.succeeds()
103+
.stdout_contains("Sun, 19 Jan 1997");
104+
105+
// Test with French locale - should still output "Sun" not "dim."
106+
scene
107+
.ucmd()
108+
.env("LC_ALL", "fr_FR.UTF-8")
109+
.env("TZ", "UTC")
110+
.args(&["-R", "-d", "1997-01-19 08:17:48 +0"])
111+
.succeeds()
112+
.stdout_contains("Sun, 19 Jan 1997");
113+
}
114+
89115
#[test]
90116
fn test_date_rfc_3339() {
91117
let scene = TestScenario::new(util_name!());

0 commit comments

Comments
 (0)