date: apply the ^ and # case flags per specifier - #14375
Open
harshasiddartha wants to merge 1 commit into
Open
Conversation
GNU applies the case flags inside each conversion, not to the whole rendered string, so `#` reaches only the specifiers that emit a name and there it wins over `^`. uutils instead let `^` cancel `#` and applied both to every specifier, so `%#c` printed `SAT JUN 15 13:05:03 2024` instead of `Sat Jun 15 13:05:03 2024`, `%#r` lower-cased the `PM`, `%^P` printed `PM`, and `%^#p` and `%^#Z` printed `PM` and `UTC` rather than `pm` and `utc`. Honor `#` only for `%a %A %b %B %h %p %P %Z`, let it take precedence over `^`, and keep `%P` lower case whatever the flags ask for. Single flags and `%^#B`/`%^#A` already matched GNU and are unchanged.
|
GNU testsuite comparison: |
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.
GNU applies the
^and#case flags inside each conversion rather than to the whole rendered string.#reaches only the specifiers that emit a name, it is not carried into the recursive expansion of%cand%r, and where it does apply it takes precedence over^.uutils instead let
^cancel#and applied both flags to every specifier, so withTZ=UTC LC_ALL=C -d '2024-06-15 13:05:03'it printedSAT JUN 15 13:05:03 2024for%#c, lower-cased thePMin%#r, and printedPM/UTCfor%^P,%^#pand%^#Zwhere GNU printspm/utc.The fix stops
^from clearing#and gates both flags on the specifier:#is honored for%a %A %b %B %h %p %P %Zand wins over^, and%Pstays lower case whatever the flags ask for. The existing swap-case heuristic already matched GNU for those specifiers in the C locale, so only the gating changed. Single flags and%^#B/%^#Abehave as before.Tested with a table of the
%c %p %P %r %Zflag combinations plus a named-zone case (TZ=America/New_York) intests/by-util/test_date.rs; both new tests fail on main and pass with the change, and the rest of the date suite is unaffected. Every expected value was checked against GNU coreutils 9.11 underTZ=UTC LC_ALL=C. No GNU coreutils source was consulted.One thing this PR does not address: in glibc,
#sets upper-case for%a %A %b %B %hand lower-case for%p %P %Z, rather than swapping case. That is invisible in the C locale, where the names are already mixed or upper case, but it does show elsewhere:LC_ALL=es_ES.UTF-8 date +%#BgivesJUNIOwhere a swap would leavejunioalone. The swap heuristic predates this change and the gating here is correct either way, so I left the locale question for a separate PR.Fixes #14351