This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add new date/time directives to strftime()
Type: enhancement Stage: resolved
Components: Versions:
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, eric.smith, r.david.murray, wwycheuk
Priority: normal Keywords:

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:28adminsetgithub: 58646
2012-03-29 19:11:47eric.smithsetmessages: + msg157086
2012-03-29 19:08:20r.david.murraysetmessages: + msg157085
2012-03-29 18:48:32eric.smithsetnosy: + eric.smith
messages: + msg157084
2012-03-29 15:23:25r.david.murraysetstatus: open -> closed
resolution: out of date
messages: + msg157058

stage: resolved
2012-03-29 15:10:23wwycheuksetmessages: + msg157056
2012-03-29 14:43:02r.david.murraysetmessages: + msg157051
2012-03-29 14:32:17wwycheuksetmessages: + msg157050
2012-03-29 14:14:42r.david.murraysetnosy: + r.david.murray, belopolsky
messages: + msg157049
2012-03-29 14:05:19wwycheukcreate