[I18n-sig] problem strptime and locale

Adrien LEMAIRE lemaire.adrien at gmail.com
Wed Jul 4 01:57:13 CEST 2012


Hi there,

First of all, please forgive me if I wrote to the wrong mailing-list, I'd
appreciate if you could redirect me to the correct one.


I'm working on a software in Japan, and need to handle dates in Gregorian
format as well as japanese emperor
date<http://www.i18nguy.com/l10n/emperor-date.html>
.
Because I saw in the locale
doc<http://docs.python.org/library/locale.html?highlight=locale#locale>
the
following:

locale.ERA
> Get a string that represents the era used in the current locale.
> Most locales do not define this value. An example of a locale which does
> define this value is the Japanese one. In Japan, the traditional
> representation of dates includes the name of the era corresponding to the
> then-emperor’s reign.

 <http://docs.python.org/library/locale.html?highlight=locale#locale.ERA>

After searching for a way to use that ERA with strftime, I finally managed
to get something: http://sprunge.us/QFdJ?py

The problem, as you can see in my paste, is that strftime will properly
work using a %E directive, but strptime doesn't support that directive.
Effectively, when looking at the _strptime module, I can see that the
TimeRE class doesn't have a E key in his base.__init__ dictionary.
I tried to go and read the locale C code to understand what is this E
directive and how I could add it in the list, but couldn't get any result.

This is really surprising that I'm able to convert gregorian to emperor
date, but that the contrary isn't possible.
I wonder if a patch couldn't be written for that. Or if I missed something
that allow to convert emperor dates to gregorian without strptime.
I Tried dateutil.parser, but it doesn't work as well, giving a ValueError:
unknown string format for parser.parse("昭和60")

Any help would be appreciated, thanks in advance for your time.

-- 
Cheers,
Adrien LEMAIRE
Engineer @Aquasys
Google+ <http://gplus.to/Fandekasp>  CV <http://vizualize.me/adrien.lemaire>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/i18n-sig/attachments/20120704/0b86a4a8/attachment.html>


More information about the I18n-sig mailing list