Repository navigation
ls: honor LC_ALL for locale time-style dates - #16987
Open
kutluhaneth46 wants to merge 3 commits into
Open
kutluhaneth46 wants to merge 3 commits into
kutluhaneth46 wants to merge 3 commits into
Conversation
Default -l dates ignored the locale. Infer day/month order from D_FMT and substitute padded ABMON month names so fr_FR and de_CH match GNU ls with working LC_TIME catalogs.
sylvestre
reviewed
Nov 29, 2026
| at.touch("stamp"); | ||
| let file = at.make_file("stamp"); | ||
| // Fixed recent timestamp so the locale date column is predictable. | ||
| let stamp = SystemTime::UNIX_EPOCH + Duration::from_secs(1_794_991_440); // 2026-11-18 08:44 UTC |
Contributor
There was a problem hiding this comment.
this date stops being "recent" around May 2027 and the test will then fail, could you please base it on now() instead?
| let Some(abbr) = months.get(month_idx) else { | ||
| return Cow::Borrowed(format); | ||
| }; | ||
| Cow::Owned(format.replace("%b", abbr).replace("%h", abbr)) |
Contributor
There was a problem hiding this comment.
this breaks --time-style=+%%b, which should print a literal %b
please handle %% and add a test for it
| not(target_os = "cygwin"), | ||
| not(target_os = "redox") | ||
| ))] | ||
| fn padded_locale_abmons_inner() -> Option<[String; 12]> { |
Contributor
There was a problem hiding this comment.
almost the same code as get_locale_months_inner, could be dedup, no?
| use core::ffi::CStr; | ||
|
|
||
| unsafe { | ||
| libc::setlocale(libc::LC_TIME, c"".as_ptr()); |
Contributor
There was a problem hiding this comment.
please add a SAFETY comment on these unsafe blocks (here and below)
| (Some(day), Some(month)) if day < month => { | ||
| let after_day = &d_fmt[day..]; | ||
| if after_day.starts_with("%d.") || after_day.starts_with("%e.") { | ||
| ("%e. %b %H:%M", "%e. %b %Y") |
Contributor
There was a problem hiding this comment.
the older form has one space and the others have two, so the columns won't line up between old and recent files, no?
Handle %% in month-token expansion, keep older-form year spacing aligned with recent HH:MM, share ABMON reads, add SAFETY notes, and base the locale ls test on now().
Author
|
@sylvestre Thanks for the review. I pushed a follow-up that:
|
Merge identical match arms and use contains for abmon widths. Accept an optional day-dot in the fr_FR locale ls assertion so FreeBSD's D_FMT shape matches.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16979.
ls -lalways printed English month-first dates. GNU uses the locale for both the month abbreviation and the day/month order (18 nov.in French,18. Novin German Swiss).I wire
i18n-datetimeintols, pick the recent/older format fromnl_langinfo(D_FMT)whenLC_TIMEis not C/POSIX, and replace%bwith paddedABMONnames (periods kept, widths aligned like GNU abformat).Added a unix test that checks
fr_FR.UTF-8,de_CH.UTF-8, andCwhen those locales are installed.