Skip to content

Commit ca89c8c

Browse files
committed
ls: honor LC_TIME for --time-style=locale via uucore helper
Add format_system_time_locale_aware in uucore::time that runs the format string through i18n::datetime::localize_format_string when a non-C LC_TIME locale is active, and route ls's display_date through it. Fixes month names and alternate-calendar years (Persian, Buddhist, Ethiopian) matching GNU. Also generalize uutests' is_locale_available to derive the expected charmap from the locale suffix so non-UTF-8 locales work, and consolidate the ls locale tests into a single data-driven case.
1 parent 41ac7e7 commit ca89c8c

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/uu/ls/src/display.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use uucore::{
5656
os_str_as_bytes_lossy,
5757
quoting_style::{QuotingStyle, locale_aware_escape_dir_name, locale_aware_escape_name},
5858
show,
59-
time::{FormatSystemTimeFallback, format_system_time_locale_aware},
59+
time::{FormatSystemTimeFallback, NamePadding, format_system_time_locale_aware},
6060
};
6161

6262
use crate::colors::{StyleManager, color_name};
@@ -620,7 +620,13 @@ fn display_date(
620620
_ => &config.time_format_recent,
621621
};
622622

623-
format_system_time_locale_aware(out, time, fmt, FormatSystemTimeFallback::Integer)
623+
format_system_time_locale_aware(
624+
out,
625+
time,
626+
fmt,
627+
FormatSystemTimeFallback::Integer,
628+
NamePadding::Padded,
629+
)
624630
}
625631

626632
fn display_len_or_rdev(metadata: &Metadata, config: &Config) -> SizeOrDeviceId {

src/uucore/src/lib/features/time.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ use std::time::{SystemTime, UNIX_EPOCH};
1616
use crate::error::{UResult, USimpleError};
1717
use crate::show_error;
1818

19+
#[cfg(feature = "i18n-datetime")]
20+
pub use crate::i18n::datetime::NamePadding;
21+
22+
/// Controls whether locale name lookups return raw or padded names.
23+
///
24+
/// Without the `i18n-datetime` feature the parameter is accepted but ignored.
25+
#[cfg(not(feature = "i18n-datetime"))]
26+
#[derive(Clone, Copy)]
27+
pub enum NamePadding {
28+
/// Raw names with no trailing padding — for `date` and similar utilities.
29+
Raw,
30+
/// Names padded to uniform display width — for columnar output like `ls`.
31+
Padded,
32+
}
33+
1934
/// Format the given date according to this time format style.
2035
fn format_zoned<W: Write>(out: &mut W, zoned: Zoned, fmt: &str) -> UResult<()> {
2136
let tm = BrokenDownTime::from(&zoned);
@@ -108,6 +123,7 @@ pub fn format_system_time_locale_aware<W: Write>(
108123
time: SystemTime,
109124
fmt: &str,
110125
mode: FormatSystemTimeFallback,
126+
padding: NamePadding,
111127
) -> UResult<()> {
112128
#[cfg(feature = "i18n-datetime")]
113129
{

0 commit comments

Comments
 (0)