problem strptime and locale

Adrien LEMAIRE <[email protected]> Wed, 4 Jul 2012 08:57:13 +0900
Newsgroups gmane.comp.python.internationalization
Message-ID <CALqn52MyvTaKkW3AgiuV6iXdYSH++NcPpuz56sqtWQOyioz28A@mail.gmail.com>
--===============1218572700==
Content-Type: multipart/alternative; boundary=e89a8f2357d7cfaf7e04c3f5ae3a

--e89a8f2357d7cfaf7e04c3f5ae3a
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

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=3Dlocale#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=E2=80=99s reign.

 <http://docs.python.org/library/locale.html?highlight=3Dlocale#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("=E6=98=AD=E5=92=8C60")

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

--=20
Cheers,
Adrien LEMAIRE
Engineer @Aquasys
Google+ <http://gplus.to/Fandekasp>  CV <http://vizualize.me/adrien.lemaire=
>

--e89a8f2357d7cfaf7e04c3f5ae3a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<span style=3D"color:rgb(34,34,34);font-size:13px;font-family:arial,sans-se=
rif">Hi there,</span><div style=3D"color:rgb(34,34,34);font-size:13px;font-=
family:arial,sans-serif">
<br></div><div style=3D"color:rgb(34,34,34);font-size:13px;font-family:aria=
l,sans-serif">First of all, please forgive me if I wrote to the wrong maili=
ng-list, I&#39;d appreciate if you could redirect me to the correct one.</d=
iv>



<div style=3D"color:rgb(34,34,34);font-size:13px;font-family:arial,sans-ser=
if"><br></div><div style=3D"color:rgb(34,34,34);font-size:13px;font-family:=
arial,sans-serif"><br></div><div style=3D"color:rgb(34,34,34);font-size:13p=
x;font-family:arial,sans-serif">


I&#39;m working on a software in Japan, and need to handle dates in Gregori=
an format as well as=C2=A0<a href=3D"http://www.i18nguy.com/l10n/emperor-da=
te.html" style=3D"color:rgb(17,85,204)" target=3D"_blank">japanese emperor =
date</a>.</div>



<div style=3D"color:rgb(34,34,34);font-size:13px;font-family:arial,sans-ser=
if">Because I saw in the=C2=A0<a href=3D"http://docs.python.org/library/loc=
ale.html?highlight=3Dlocale#locale" style=3D"color:rgb(17,85,204)" target=
=3D"_blank">locale doc</a>=C2=A0the following:</div>



<div style=3D"color:rgb(34,34,34);font-size:13px;font-family:arial,sans-ser=
if"><br></div><div style=3D"color:rgb(34,34,34);font-size:13px;font-family:=
arial,sans-serif">
<blockquote class=3D"gmail_quote" style=3D"margin-top:0px;margin-right:0px;=
margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color=
:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><tt style=3D"ba=
ckground-color:transparent;padding-top:0px;padding-right:1px;padding-bottom=
:0px;padding-left:1px;font-size:0.95em">locale</tt>.<tt style=3D"background=
-color:transparent;padding-top:0px;padding-right:1px;padding-bottom:0px;pad=
ding-left:1px;font-size:1.2em;font-weight:bold">ERA<br>



</tt>Get a string that represents the era used in the current=C2=A0locale.<=
br>Most=C2=A0locales do not define this value. An example of a locale which=
 does define this value is the Japanese one. In Japan, the traditional repr=
esentation of dates includes the name of the era corresponding to the then-=
emperor=E2=80=99s reign.</blockquote>



<dt style=3D"line-height:20px;text-align:justify"><font face=3D"sans-serif"=
><span style=3D"font-size:0.8em"><a href=3D"http://docs.python.org/library/=
locale.html?highlight=3Dlocale#locale.ERA" title=3D"Permalink to this defin=
ition" style=3D"color:rgb(198,15,15);text-decoration:none;font-size:0.8em;p=
adding-top:0px;padding-right:4px;padding-bottom:0px;padding-left:4px" targe=
t=3D"_blank"></a></span></font></dt>



<div><br></div><div>After searching for a way to use that ERA with strftime=
, I finally managed to get something:=C2=A0<a href=3D"http://sprunge.us/QFd=
J?py" style=3D"color:rgb(17,85,204)" target=3D"_blank">http://sprunge.us/QF=
dJ?py</a></div>



<div><br></div><div>The problem, as you can see in my paste, is that strfti=
me will properly work using a %E directive, but strptime doesn&#39;t suppor=
t that directive.=C2=A0</div><div>Effectively, when looking at the _strptim=
e module, I can see that the TimeRE class doesn&#39;t have a E key in his b=
ase.__init__ dictionary.=C2=A0</div>

<div>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&#39;t get any resu=
lt.</div>

<div><br></div><div>This is really surprising that I&#39;m able to convert =
gregorian to emperor date, but that the contrary isn&#39;t possible.=C2=A0<=
/div><div>I wonder if a patch couldn&#39;t be written for that. Or if I mis=
sed something that allow to convert emperor dates to gregorian without strp=
time.=C2=A0</div>

<div>I Tried dateutil.parser, but it doesn&#39;t work as well, giving a Val=
ueError: unknown string format for=C2=A0parser.parse(&quot;=E6=98=AD=E5=92=
=8C60&quot;)</div>

<div><br></div><div>Any help would be appreciated, thanks in advance for yo=
ur time.</div></div><div><br></div>-- <br>Cheers,<br>Adrien LEMAIRE<div>Eng=
ineer @Aquasys<br><div><a href=3D"http://gplus.to/Fandekasp" target=3D"_bla=
nk">Google+</a>=C2=A0=C2=A0<a href=3D"http://vizualize.me/adrien.lemaire" t=
arget=3D"_blank">CV</a></div>



<div><br></div></div><br>

--e89a8f2357d7cfaf7e04c3f5ae3a--

--===============1218572700==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
I18n-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/i18n-sig

--===============1218572700==--