Skip to content

ls: honor LC_TIME for --time-style=locale#11669

Open
sylvestre wants to merge 4 commits intouutils:mainfrom
sylvestre:time-style_locale
Open

ls: honor LC_TIME for --time-style=locale#11669
sylvestre wants to merge 4 commits intouutils:mainfrom
sylvestre:time-style_locale

Conversation

@sylvestre
Copy link
Copy Markdown
Contributor

@sylvestre sylvestre commented Apr 5, 2026

on my system

$ export L="en_US fr_FR ru_RU.KOI8-R fa_IR.UTF-8 am_ET.UTF-8 th_TH.UTF-8 zh_CN.GB18030"; for f in $L; do echo "$f:"; LANG=$f cargo run -q --features unix -- ls -al --time-style=locale Cargo.toml LICENSE; done
en_US:
-rw-rw-r--+  1 sylvestre sylvestre 27798 Apr  5 22:05 Cargo.toml
-rw-r--r--+  1 sylvestre sylvestre  1056 Mar 20  2025 LICENSE
fr_FR:
-rw-rw-r--+  1 sylvestre sylvestre 27798 avr  5 22:05 Cargo.toml
-rw-r--r--+  1 sylvestre sylvestre  1056 mars 20  2025 LICENSE
ru_RU.KOI8-R:
-rw-rw-r--+  1 sylvestre sylvestre 27798 апр  5 22:05 Cargo.toml
-rw-r--r--+  1 sylvestre sylvestre  1056 март 20  2025 LICENSE
fa_IR.UTF-8:
-rw-rw-r--+  1 sylvestre sylvestre 27798 فروردین 16 22:05 Cargo.toml
-rw-r--r--+  1 sylvestre sylvestre  1056 اسفند 30  1403 LICENSE
am_ET.UTF-8:
-rw-rw-r--+  1 sylvestre sylvestre 27798 ኤፕሪ 27 22:05 Cargo.toml
-rw-r--r--+  1 sylvestre sylvestre  1056 ማርች 11  2017 LICENSE
th_TH.UTF-8:
-rw-rw-r--+  1 sylvestre sylvestre 27798 เม.ย  5 22:05 Cargo.toml
-rw-r--r--+  1 sylvestre sylvestre  1056 มี.ค 20  2568 LICENSE
zh_CN.GB18030:
-rw-rw-r--+  1 sylvestre sylvestre 27798 4月  5 22:05 Cargo.toml
-rw-r--r--+  1 sylvestre sylvestre  1056 3月 20  2025 LICENSE

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

GNU testsuite comparison:

GNU test failed: tests/ls/abmon-align. tests/ls/abmon-align is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/seq/seq-epipe is now passing!

@sylvestre sylvestre requested a review from cakebaker April 5, 2026 22:02
@sylvestre
Copy link
Copy Markdown
Contributor Author

GNU test failed: tests/ls/abmon-align. tests/ls/abmon-align is passing on 'main'. Maybe you have to rebase?

looking at this

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

GNU testsuite comparison:

GNU test failed: tests/date/date-thailand. tests/date/date-thailand is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/basenc/bounded-memory is now being skipped but was previously passing.
Note: The gnu test tests/expand/bounded-memory is now being skipped but was previously passing.
Congrats! The gnu test tests/cut/cut-huge-range is now passing!

@sylvestre sylvestre force-pushed the time-style_locale branch from e28448c to c302650 Compare April 6, 2026 08:10
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

GNU testsuite comparison:

GNU test failed: tests/date/date-thailand. tests/date/date-thailand is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/follow-name (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/cut/cut-huge-range is now passing!

@sylvestre sylvestre force-pushed the time-style_locale branch from c302650 to 7856aaf Compare April 6, 2026 09:12
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

GNU testsuite comparison:

Skipping an intermittent issue tests/tty/tty-eof (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/pr/bounded-memory is now passing!
Congrats! The gnu test tests/seq/seq-epipe is now passing!

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/follow-name (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/pr/bounded-memory is now passing!

@sylvestre sylvestre marked this pull request as ready for review April 6, 2026 11:39
@LevitatingBusinessMan
Copy link
Copy Markdown
Contributor

You picked this issue up fast :D

@sylvestre sylvestre force-pushed the time-style_locale branch from 0a9df65 to 893c2ae Compare April 6, 2026 13:48
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

GNU testsuite comparison:

Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tty/tty-eof (passes in this run but fails in the 'main' branch)

@sylvestre
Copy link
Copy Markdown
Contributor Author

@cakebaker
spoiler! After this one, i have --quoting-style=locale/clocale built on top :)

Comment on lines +2458 to +2463
/// Substring that MUST appear in the (lossy UTF-8) stdout. Used for the
/// C-locale sanity case to pin the English output.
must_contain: Option<&'static str>,
/// Substring that must NOT appear in the (lossy UTF-8) stdout. Used to
/// guarantee non-C locales don't fall back to the English format.
must_not_contain: Option<&'static str>,
Copy link
Copy Markdown
Contributor

@cakebaker cakebaker Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about those properties. You only introduce them because of the C-locale. It might make sense to separate the handling of the C-locale from the handling of the special cases, instead of using a "one size fits all" approach.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C locale is already handled separately (lines 2500-2522) with its own dedicated block and C_LOCALE_OUTPUT assertion. The must_contain/must_not_contain properties you were referring to have been removed — the remaining struct fields (script_range, require_high_byte, allow_gregorian_year) are all about differentiating between non-C locales (e.g. KOI8-R vs Persian vs Thai). I think this is addressed now?

@cakebaker
Copy link
Copy Markdown
Contributor

I will finish the review of test_ls.rs and the two uucore files (hopefully) tomorrow.

@sylvestre sylvestre force-pushed the time-style_locale branch from 893c2ae to 36be3f5 Compare April 8, 2026 09:47
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

GNU testsuite comparison:

Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/printf/printf-surprise is now passing!

Comment on lines +118 to +135
struct CachedLocaleNames {
/// `%B` — full month names, raw
month_long: Option<[String; 12]>,
/// `%B` — full month names, padded to uniform display width
month_long_padded: Option<[String; 12]>,
/// `%b` / `%h` — abbreviated month names (trailing dots stripped), raw
month_abbrev: Option<[String; 12]>,
/// `%b` / `%h` — abbreviated month names, padded
month_abbrev_padded: Option<[String; 12]>,
/// `%A` — full weekday names, raw
weekday_long: Option<[String; 7]>,
/// `%A` — full weekday names, padded
weekday_long_padded: Option<[String; 7]>,
/// `%a` — abbreviated weekday names, raw
weekday_short: Option<[String; 7]>,
/// `%a` — abbreviated weekday names, padded
weekday_short_padded: Option<[String; 7]>,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct doesn't feel right. If I understand it correctly, only half of the properties are used, the others are set but never read.

I would remove the "padded" properties so that the remaining properties contain either the padded or raw data, depending on how the struct was filled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both sets are actually read — localize_format_string() takes a NamePadding parameter and selects between _padded and raw variants at each substitution point (see lines 250-290). date calls with Raw, ls calls with Padded, so all 8 fields get used depending on the caller.

That said, I could avoid storing both by keeping only the raw names and applying pad_names() on-the-fly when Padded is requested. The padding cost is negligible (12 or 7 string scans). Would you prefer that approach?

@cakebaker
Copy link
Copy Markdown
Contributor

cakebaker commented Apr 8, 2026

Hm, it looks like one of my previous suggestions doesn't work on OpenBSD as test_ls_abmon_align fails :|

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.
The ls-specific column alignment padding (from abmon-align) was leaking
into date output. Add a `pad` parameter to `localize_format_string` so
ls gets padded names and date gets raw names.
@sylvestre sylvestre force-pushed the time-style_locale branch from 36be3f5 to 4486cc1 Compare April 9, 2026 09:42
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tty/tty-eof (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/cp/link-heap is now passing!
Congrats! The gnu test tests/dd/no-allocate is now passing!
Congrats! The gnu test tests/seq/seq-epipe is now passing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants