-
Notifications
You must be signed in to change notification settings - Fork 549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix locale formatting for %c
and %r
#988
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the clippy issue!
} | ||
} | ||
|
||
pub(crate) fn t_fmt_ampm(locale: Locale) -> &'static str { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should get a clear comment to explain in high-level terms what it's trying to achieve, as that is pretty unclear to me. I'm not sure I agree that the stacked macro approach is the best option here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright, i think description for it would be similar to locale_match_ampm!
macro, but will try splitting it up for high and low level terms.
as with the stacked macro, do you mean using both locale_match_ampm
and expand_ampm
macro? i too am not sure about whether it's best approach. however locale_match
wouldn't work due to chronotope/pure-rust-locales#4 so i guess we're probably stuck with this solution for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added more docstring at 3f0aafd. could you take a look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @scarf005
@@ -65,7 +65,7 @@ The following specifiers are available both to formatting and parsing. | |||
| `%R` | `00:34` | Hour-minute format. Same as `%H:%M`. | | |||
| `%T` | `00:34:60` | Hour-minute-second format. Same as `%H:%M:%S`. | | |||
| `%X` | `00:34:60` | Locale's time representation (e.g., 23:13:48). | | |||
| `%r` | `12:34:60 AM` | Hour-minute-second format in 12-hour clocks. Same as `%I:%M:%S %p`. | | |||
| `%r` | `12:34:60 AM` | Locale's 12 hour clock time. (e.g., 11:11:04 PM) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we ever want to have a possible non-localized %r
equivalent? Or do we think that it is probably not as useful as the localized version and hence it makes most sense to have the localized version only?
Reading the referenced issue, notice the comment in chronotope/pure-rust-locales#4 (comment):
It looks to me like the current setup here ends up referencing a long list of locales in our code, meaning that all of those will essentially be compiled into the chrono library if the localization feature is enabled. So I don't think this is the right approach. |
iirc #[macro_export]
macro_rules! locale_match {
($locale:expr => $($item:ident)::+) => {{
match $locale {
$crate::Locale::POSIX => $crate::POSIX::$($item)::+,
$crate::Locale::aa_DJ => $crate::aa_DJ::$($item)::+,
$crate::Locale::aa_ER => $crate::aa_ER::$($item)::+,
(...around 290 items more) the difference between
|
looks like rust msrv is too low to support 2021, should i raise it? |
|
thanks. i'll rebase the PR once msrv issue is fixed. |
The time has come 😄 |
`%c`: did not take account of `%x` and `%X` `%r`: did not use locale's format and used `%I:%M:%S %p`
feature parity with gnu date
t_fmt_ampm should be lower than t_fmt
Actually, this PR targets main, which doesn't have the MSRV bump yet. |
So is there as reason this cannot target 0.4.x? |
oh, i see, should've made a PR to |
Summary
ko_KR
) #985Breaking changes
%c
uses locale's date and time (%x
,%X
,%r
)%r
uses locale's 12 hour clock timeLibrary changes
new macro:
locale_match_ampm!
uses hardcoded list of locales to find
T_FMT_AMPM
due to chronotope/pure-rust-locales#4new tests:
test_strftime_localized_korean
andtest_strftime_localized_japanese
will test some common locale related strftime format specifiers.