Skip to content

Commit 72c782f

Browse files
authored
date: fix double periods in Hungarian month abbreviations (#10945)
ICU's DateTimeFormatter with fieldsets::M::medium() returns month abbreviations with trailing periods (e.g., "febr." for Hungarian). When the Hungarian locale format string contains "%Y. %b. %d" (with periods after year and month), the ICU output resulted in double periods: "febr.." This fix strips trailing periods from ICU month abbreviations to match the standard C/POSIX locale behavior. Also adds a new test case for abbreviated month names across multiple locales to prevent regression. Fixes #10921 Co-authored-by: naoNao89 <naoNao89@users.noreply.github.com>
1 parent eb69f20 commit 72c782f

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/uucore/src/lib/features/i18n/datetime.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55

6-
// spell-checker:ignore fieldsets prefs
6+
// spell-checker:ignore fieldsets prefs febr
77

88
//! Locale-aware datetime formatting utilities using ICU and jiff-icu
99
@@ -111,7 +111,13 @@ pub fn localize_format_string(format: &str, date: JiffDate) -> String {
111111
}
112112
if fmt.contains("%b") || fmt.contains("%h") {
113113
if let Ok(f) = DateTimeFormatter::try_new(locale_prefs, fieldsets::M::medium()) {
114+
// ICU's medium format may include trailing periods (e.g., "febr." for Hungarian),
115+
// which when combined with locale format strings that also add periods after
116+
// %b (e.g., "%Y. %b. %d") results in double periods ("febr..").
117+
// The standard C/POSIX locale via nl_langinfo returns abbreviations
118+
// WITHOUT trailing periods, so we strip them here for consistency.
114119
let month_abbrev = f.format(&iso_date).to_string();
120+
let month_abbrev = month_abbrev.trim_end_matches('.').to_string();
115121
fmt = fmt
116122
.replace("%b", &month_abbrev)
117123
.replace("%h", &month_abbrev);

tests/by-util/test_date.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55
//
6-
// spell-checker: ignore: AEDT AEST EEST NZDT NZST Kolkata Iseconds févr février janv janvier mercredi samedi sommes juin décembre Januar Juni Dezember enero junio diciembre gennaio giugno dicembre junho dezembro lundi dimanche Montag Sonntag Samstag sábado
6+
// spell-checker: ignore: AEDT AEST EEST NZDT NZST Kolkata Iseconds févr février janv janvier mercredi samedi sommes juin décembre Januar Juni Dezember enero junio diciembre gennaio giugno dicembre junho dezembro lundi dimanche Montag Sonntag Samstag sábado febr
77

88
use std::cmp::Ordering;
99

@@ -2056,6 +2056,29 @@ fn test_locale_month_names() {
20562056
}
20572057
}
20582058

2059+
#[test]
2060+
#[cfg(unix)]
2061+
fn test_locale_abbreviated_month_names() {
2062+
// %b abbreviated month names: Feb, Jun, Dec for each locale
2063+
// This test ensures we don't get double periods in locales like Hungarian
2064+
// where ICU returns "febr." but the format string also adds a period after %b
2065+
for (loc, feb, jun, dec) in [
2066+
("fr_FR.UTF-8", "févr", "juin", "déc"),
2067+
("de_DE.UTF-8", "Feb", "Jun", "Dez"),
2068+
("es_ES.UTF-8", "feb", "jun", "dic"),
2069+
("it_IT.UTF-8", "feb", "giu", "dic"),
2070+
("pt_BR.UTF-8", "fev", "jun", "dez"),
2071+
("ja_JP.UTF-8", "2月", "6月", "12月"),
2072+
("zh_CN.UTF-8", "2月", "6月", "12月"),
2073+
// Hungarian locale - the fix ensures no double periods
2074+
("hu_HU.UTF-8", "febr", "jún", "dec"),
2075+
] {
2076+
check_date(loc, "2026-02-12", "+%b", feb);
2077+
check_date(loc, "2026-06-14", "+%b", jun);
2078+
check_date(loc, "2026-12-09", "+%b", dec);
2079+
}
2080+
}
2081+
20592082
#[test]
20602083
#[cfg(unix)]
20612084
fn test_locale_day_names() {

0 commit comments

Comments
 (0)