Skip to content

Commit

Permalink
Merge pull request #222 from bpotard/master
Browse files Browse the repository at this point in the history
Fix to sanitize abbreviated months from icu
  • Loading branch information
bear authored Nov 19, 2019
2 parents 0781f52 + 2a8eb5a commit 6943104
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions parsedatetime/pdt_locales/icu.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def merge_weekdays(base_wd, icu_wd):


def get_icu(locale):

def _sanitize_key(k):
import re
return re.sub("\\.(\\||$)", "\\1", k)

from . import base
result = dict([(key, getattr(base, key))
for key in dir(base) if not key.startswith('_')])
Expand All @@ -58,16 +63,16 @@ def get_icu(locale):

# grab ICU list of weekdays, skipping first entry which
# is always blank
wd = [w.lower() for w in symbols.getWeekdays()[1:]]
swd = [sw.lower() for sw in symbols.getShortWeekdays()[1:]]
wd = [_sanitize_key(w.lower()) for w in symbols.getWeekdays()[1:]]
swd = [_sanitize_key(sw.lower()) for sw in symbols.getShortWeekdays()[1:]]

# store them in our list with Monday first (ICU puts Sunday first)
result['Weekdays'] = merge_weekdays(result['Weekdays'],
wd[1:] + wd[0:1])
result['shortWeekdays'] = merge_weekdays(result['shortWeekdays'],
swd[1:] + swd[0:1])
result['Months'] = [m.lower() for m in symbols.getMonths()]
result['shortMonths'] = [sm.lower() for sm in symbols.getShortMonths()]
result['Months'] = [_sanitize_key(m.lower()) for m in symbols.getMonths()]
result['shortMonths'] = [_sanitize_key(sm.lower()) for sm in symbols.getShortMonths()]
keys = ['full', 'long', 'medium', 'short']

createDateInstance = pyicu.DateFormat.createDateInstance
Expand Down

0 comments on commit 6943104

Please sign in to comment.