date: Fix %x, %X, %r to respect locale settings#11068
date: Fix %x, %X, %r to respect locale settings#11068abendrothj wants to merge 4 commits intouutils:mainfrom
Conversation
|
Please |
462cb08 to
032b444
Compare
oops, forgot prehook doesnt work on mac currently |
aa1ee97 to
0146bba
Compare
- Add locale.rs functions to query nl_langinfo for D_FMT, T_FMT, T_FMT_AMPM - Add expand_locale_specifiers() to replace %x, %X, %r with locale formats - Integrate locale specifier expansion before jiff formatting - Un-ignore and extend locale tests with graceful degradation
0710de3 to
81b15f0
Compare
|
GNU testsuite comparison: |
…e test from check to assertion
|
GNU testsuite comparison: |
tests/by-util/test_date.rs
Outdated
| .stdout_is("19/01/1997\n"); | ||
| .stdout_is("19.01.1997\n"); |
There was a problem hiding this comment.
I think the new assert is incorrect (it fails on my machine) and the original assert was correct.
Here is the output I get from GNU date:
$ TZ=UTC LC_ALL=fr_FR.UTF-8 date -d "1997-01-19 08:17:48" "+%x"
19/01/1997
There was a problem hiding this comment.
should be all inline to GNU now
| if !locale_is_available("fr_FR.UTF-8") { | ||
| println!("Skipping French locale %X test — fr_FR.UTF-8 not available"); | ||
| return; | ||
| } | ||
| new_ucmd!() | ||
| .env("TZ", "UTC") | ||
| .env("LC_ALL", "fr_FR.UTF-8") | ||
| .arg("-d") | ||
| .arg("1997-01-19 08:17:48") | ||
| .arg("+%X") | ||
| .succeeds() | ||
| .stdout_is("08:17:48\n"); |
There was a problem hiding this comment.
I would use a locale with a different time format like en_US.UTF-8, for which the output should be 08:17:48 AM.
There was a problem hiding this comment.
I'm sorry, my bad. I meant to use en_US.UTF-8 here in test_date_format_big_x_locale_aware (and not in test_date_format_r_locale_aware) because the expected outputs for the C and fr_FR.UTF-8 locales are identical.
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
653a995 to
9a5b0e9
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
|
GNU testsuite comparison: |
| new_ucmd!() | ||
| .env("TZ", "UTC") | ||
| .env("LC_ALL", "fr_FR.UTF-8") | ||
| .arg("-d") | ||
| .arg("1997-01-19 08:17:48") | ||
| .arg("+%r") | ||
| .succeeds() | ||
| .stdout_is(expected); |
There was a problem hiding this comment.
While the test looks good, it fails on Linux because the implementation doesn't output the expected value.
Here is the output of the program:
$ TZ=UTC LC_ALL=fr_FR.UTF-8 cargo run -q date -d "1997-01-19 08:17:48" "+%r"
08:17:48 AM
And here is the expected output from GNU date:
$ TZ=UTC LC_ALL=fr_FR.UTF-8 date -d "1997-01-19 08:17:48" "+%r"
08:17:48
Fixes #10284
Previously these format specifiers were hardcoded to US/POSIX defaults, ignoring LC_TIME and LC_ALL. Now they call nl_langinfo to get the locale's actual format strings.
Changes:
now for ci...