Issue 14441: Add new date/time directives to strftime() (original) (raw)

Created on 2012-03-29 14:05 by wwycheuk, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (9)
msg157048 - (view) Author: Walter Cheuk (wwycheuk) Date: 2012-03-29 14:05
Please add new directives for decimal-number month, day and hour that have neither leading zero nor leading space. Currently %m, %d and %I are used, but they have leading zeroes and are not suitable for some languages such as Chinese. GNOME provides %e and %l for day and hour, but they have leading space instead and are not good enough also.
msg157049 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-03-29 14:14
We pretty much follow the posix standard on strftime. I doubt that we would introduce non-standard specifiers. Are there any in widespread use for your use case?
msg157050 - (view) Author: Walter Cheuk (wwycheuk) Date: 2012-03-29 14:32
Yes, this is standard in all Chinese locales, including China, Taiwan, Hong Kong, Macau and Singapore.
msg157051 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-03-29 14:43
I'm asking if there are specific % codes commonly used for this case. (Even if there are there is no guarantee we are going to add them, but it makes it possible to make a case for it.)
msg157056 - (view) Author: Walter Cheuk (wwycheuk) Date: 2012-03-29 15:10
Usually %m, %d and %I are used instead, but the result is not satisfactory.
msg157058 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-03-29 15:23
It turns out that there is standard way to do this (well, a de-facto standard, anyway). glibc (and apparently others) support 'modifiers', of which the '-' modifier will suppress 0 padding. Furthermore, since we pass the format string through to glibc, Python *already* supports this on glibc based platforms, though it isn't documented: >>> t.strftime("%m") '03' >>> t.strftime("%-m") '3'
msg157084 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2012-03-29 18:48
Can we change this to a documentation bug? I was unaware of the use of '-', and I think most other people are, too. Although having just checked, it doesn't work under Windows :(. So maybe we shouldn't document it. Thinking out loud: I've often thought we should write our own strptime/strftime. I think cross-platform consistency here would be a win.
msg157085 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-03-29 19:08
I think there may even be an issue for that, but with the currently broken issue search I'm not sure. Issue 3173 *might* be what I'm thinking of (thanks, google). And yes, the fact that stuff like this is not cross-platform is why it isn't documented, and why I said "on glibc based platforms" :) (I think there is a doc note about additional directives possibly being defined by the platform.)
msg157086 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2012-03-29 19:11
Heh. You're correct about 3173. And I'm even nosy on that issue!
History
Date User Action Args
2022-04-11 14:57:28 admin set github: 58646
2012-03-29 19:11:47 eric.smith set messages: +
2012-03-29 19:08:20 r.david.murray set messages: +
2012-03-29 18:48:32 eric.smith set nosy: + eric.smithmessages: +
2012-03-29 15:23:25 r.david.murray set status: open -> closedresolution: out of datemessages: + stage: resolved
2012-03-29 15:10:23 wwycheuk set messages: +
2012-03-29 14:43:02 r.david.murray set messages: +
2012-03-29 14:32:17 wwycheuk set messages: +
2012-03-29 14:14:42 r.david.murray set nosy: + r.david.murray, belopolskymessages: +
2012-03-29 14:05:19 wwycheuk create