[Python-ideas] Reduce platform dependence of date and time related functions

random832 at fastmail.us random832 at fastmail.us
Fri Sep 20 16:46:11 CEST 2013


On Thu, Sep 19, 2013, at 18:00, Andrew Barnert wrote:
> But that API implies that you could call, e.g., d.strftime(fmt, "pt_BR"),
> which I assume isn't something anyone is planning on implementing.

Well, you could implement it by acquiring the GIL, setting the locale
(putenv + setlocale), calling the platform strftime, and then resetting
the locale afterward - all while locked, to prevent exposing the
temporary strftime change to other code. (This also suggests a way to
implement a tzinfo object in terms of native timezones)

Long-term it would be nice to have python ship its own locale data,
and/or to acquire platform-specific locale data via GetLocaleInfo[Ex] on
windows and nl_langinfo on POSIX OSes where it is provided. (Note that
the latter still would require stopping everything and setting the
global locale to acquire the data, but since you've got to translate a
locale name to a handle to use GetLocaleInfo or xlocale, it'd make sense
to encapsulate this in a locale object which does all this upon being
created. With platform strftime as a fallback. The issue with using
platform strftime to populate things in advance is that %O is difficult
and %E may be intractable.


More information about the Python-ideas mailing list