Conversation
jiff renders %c with the POSIX format, so it came out the same whatever the locale said. GNU date stands %c for the locale's D_T_FMT, which under en_US.UTF-8 means a 12-hour clock and a timezone. Query D_T_FMT beside the existing _DATE_FMT lookup, and expand %c in the format string rather than rendering it directly, so the month and day names it contains still go through the existing ICU localization. Fixes uutils#14679
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
This PR makes date +%c use the locale’s D_T_FMT format on supported Linux systems, matching GNU date.
Changes:
- Adds a cached
D_T_FMTquery throughnl_langinfo. - Expands bare
%cinto the locale format before normal date formatting. - Adds tests for locale-specific
%c, the C locale, and escaped%%c.
| File | Description |
|---|---|
tests/by-util/test_date.rs |
Adds coverage for locale-based %c expansion and escaping. |
src/uu/date/src/locale.rs |
Queries and caches the locale’s D_T_FMT value. |
src/uu/date/src/date.rs |
Substitutes %c with D_T_FMT before formatting. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| /// data, and it is exactly the property that was broken: `%c` used to fall | ||
| /// back to the POSIX format whatever the locale said. | ||
| #[test] | ||
| #[cfg(unix)] |
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 #14679
%ccame out with the POSIX format whatever the locale said, because jiff'sPosixCustomrenders it that way and nothing overrode it. GNUdatestands%cfor the locale'sD_T_FMT, so underen_US.UTF-8it should carry a12-hour clock and the timezone.
A note on the issue title
The issue reads
date -u +%cand blames-u.-uis in fact respected — thehours differ correctly with and without it. What the reporter saw was the
missing
UTCat the end, which comes from%cignoring the locale, so that iswhat this fixes. Under
LC_ALL=Cthe two agreed all along, since the Clocale's
D_T_FMTis the POSIX format.How
locale.rsalready queriednl_langinfofor the default format, so this addsa
D_T_FMTaccessor beside it and factors the sharedsetlocale/nl_langinfoblock into
query_nl_langinfo.date.rsexpands%cin the format string rather than rendering it directly.That keeps the expansion on the normal path, so the month and day names it
contains still go through the existing ICU localization, and the specifiers
inside it still reach jiff.
%%cstays a literal, as it must.A locale whose
D_T_FMTis not valid UTF-8 (legacy charsets such aszh_TW.euctw) leaves%calone rather than forcing a lossy conversion.Platforms
Gated on the same glibc-Linux
cfgas the existing_DATE_FMTquery, sonothing changes elsewhere.
D_T_FMTis POSIX, unlike the_DATE_FMTextension, so the other Unix platforms could be wired up as a follow-up by
someone able to test them.
Testing
Three tests: the
en_US.UTF-8one asserts+%crenders exactly like+"$(locale d_t_fmt)", which is the GNU contract and avoids pinning onedistribution's locale data; the other two cover the C locale and
%%c.Neutralizing the expansion makes the first fail with
left: "Tue Nov 14 23:13:20 2023"againstright: "Tue 14 Nov 2023 11:13:20 PM UTC"— the symptom from the issue — whilethe other two stay green.
Also swept
%c %x %X %r %D %T %F %s %N %Z %z %j %U %G, plusx%cyand%%c%c, against GNU 9.7 underCanden_US.UTF-8: only%xand%Xstilldiffer, which is #11068's territory, untouched here.
Left alone
%^c,%#cand%Ecstill diverge. Those are date: case flags ^ and # don't match GNU on %c %p %P %r %Z #14351 / PR date: apply the ^ and # case flags per specifier #14375, and theyare unchanged by this PR.
fr_FR.UTF-8the month abbreviation prints asnovwhere GNU printsnov.. That gap predates this change — it shows on plaindatewith noformat too — and comes from ICU's abbreviation, not from
%c.