Arrow: "a" token for am/pm is not being processed in get() when using Spanish locale

Created on 8 Jul 2019  路  4Comments  路  Source: arrow-py/arrow

I have been parsing some dates in Spanish and found out that the a token for am/pm does not get applied with the locale es.

See for example this date in English. It gets parsed properly by doing 8 pm -> 20 h.

>>> arrow.get('June 30, 2019 - 08:00 pm', "MMMM DD, YYYY - hh:mm a")                                          
<Arrow [2019-06-30T20:00:00+00:00]>

However, in Spanish it does not work:

>>> arrow.get('Junio 30, 2019 - 08:00 pm', "MMMM DD, YYYY - hh:mm a", locale="es")                            
<Arrow [2019-06-30T08:00:00+00:00]>

In fact, anything can be put in the a token!

>>> arrow.get('Junio 30, 2019 - 08:00 pasdfasdfm', "MMMM DD, YYYY - hh:mm a", locale="es")                    
<Arrow [2019-06-30T08:00:00+00:00]>
bug

Most helpful comment

@systemcatch would this be fixed by simply getting translations for meridians = {"am": "", "pm": "", "AM": "", "PM": ""}?

All 4 comments

Hi @NestorTejero thanks for reporting this, I can reproduce it on the master branch.

From a quick glance at https://github.com/crsmithdev/arrow/blob/master/arrow/locales.py#L359 it looks like the Spanish locale is inheriting the meridians class variable from the base locale, meaning they are blank.

@systemcatch would this be fixed by simply getting translations for meridians = {"am": "", "pm": "", "AM": "", "PM": ""}?

@jadchaar yup that would fix it, I'll do a PR.

This has been fixed in: https://github.com/crsmithdev/arrow/pull/610. This change should ship with arrow 0.14.3.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewmwilson picture andrewmwilson  路  7Comments

systemcatch picture systemcatch  路  5Comments

Kirkman picture Kirkman  路  5Comments

liosha picture liosha  路  7Comments

systemcatch picture systemcatch  路  8Comments