-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
support AM/PM in date parsing/printing #32308
Conversation
I don't understand what you mean by "of the following day". Wouldn't "2019-03-22 12:00:00 AM" be the first second of 2019-03-22? |
Yes. julia> DateTime("2019-03-22 12:00 AM", dateformat"yyyy-mm-dd II:MM p")
2019-03-22T00:00:00 By the "following" day I mean that 12am belongs to the day after midnight, not to the day before, so it is equivalent to 00:00 in a 24-hour clock for the same date (not 24:00). |
@@ -161,6 +173,11 @@ for (tok, fn) in zip("uU", [monthabbr, monthname]) | |||
end | |||
end | |||
|
|||
function format(io, d::DatePart{'p'}, dt, locale) | |||
ampm = hour(dt) < 12 ? "AM" : "PM" # fixme: locale-specific? |
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.
As far as I can tell from some googling, there are only a handful of english-speaking countries that use AM/PM, so yeah, I'm not quite sure how critical it is to support locale here. For reference (https://www.timeanddate.com/time/am-and-pm.html)
Should be good to merge? |
It would have been good to use |
@omus, the |
Completely reasonable. UTS35 has a standard on what using multiple specifiers in a row does which is a bit different from |
Support AM/PM specifier (
p
dateformat code, andI
code for 12-hour clock) similar to strftime/strptime. Closes #23870.Follows the quasi-standard convention of 12am=midnight (of the following day), 12pm=noon (apparently followed by all other popular libraries and languages, as discussed in #23870).