annotate MoinMoin/support/parsedatetime/pdt_locales/icu.py @ 6098:83b1bc99457c

upgrade parsedatetime from 0.8.7 to 2.1
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 06 Sep 2016 00:09:31 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6098
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 """
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4 pdt_locales
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 All of the included locale classes shipped with pdt.
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7 """
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8 import datetime
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 try:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 range = xrange
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 except NameError:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 pass
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15 try:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 import PyICU as pyicu
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17 except:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 pyicu = None
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 def icu_object(mapping):
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22 return type('_icu', (object,), mapping)
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 def merge_weekdays(base_wd, icu_wd):
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26 result = []
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
27 for left, right in zip(base_wd, icu_wd):
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
28 if left == right:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
29 result.append(left)
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30 continue
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31 left = set(left.split('|'))
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32 right = set(right.split('|'))
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33 result.append('|'.join(left | right))
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34 return result
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37 def get_icu(locale):
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38 from . import base
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39 result = dict([(key, getattr(base, key))
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40 for key in dir(base) if not key.startswith('_')])
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41 result['icu'] = None
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 if pyicu is None:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44 return icu_object(result)
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
46 if locale is None:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
47 locale = 'en_US'
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
48 result['icu'] = icu = pyicu.Locale(locale)
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
50 if icu is None:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 return icu_object(result)
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53 # grab spelled out format of all numbers from 0 to 100
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54 rbnf = pyicu.RuleBasedNumberFormat(pyicu.URBNFRuleSetTag.SPELLOUT, icu)
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
55 result['numbers'].update([(rbnf.format(i), i) for i in range(0, 100)])
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
56
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57 symbols = result['symbols'] = pyicu.DateFormatSymbols(icu)
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
58
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
59 # grab ICU list of weekdays, skipping first entry which
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
60 # is always blank
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61 wd = [w.lower() for w in symbols.getWeekdays()[1:]]
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
62 swd = [sw.lower() for sw in symbols.getShortWeekdays()[1:]]
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
63
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
64 # store them in our list with Monday first (ICU puts Sunday first)
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65 result['Weekdays'] = merge_weekdays(result['Weekdays'],
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66 wd[1:] + wd[0:1])
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
67 result['shortWeekdays'] = merge_weekdays(result['shortWeekdays'],
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
68 swd[1:] + swd[0:1])
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69 result['Months'] = [m.lower() for m in symbols.getMonths()]
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
70 result['shortMonths'] = [sm.lower() for sm in symbols.getShortMonths()]
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71 keys = ['full', 'long', 'medium', 'short']
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
72
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
73 createDateInstance = pyicu.DateFormat.createDateInstance
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
74 createTimeInstance = pyicu.DateFormat.createTimeInstance
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
75 icu_df = result['icu_df'] = {
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
76 'full': createDateInstance(pyicu.DateFormat.kFull, icu),
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
77 'long': createDateInstance(pyicu.DateFormat.kLong, icu),
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78 'medium': createDateInstance(pyicu.DateFormat.kMedium, icu),
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
79 'short': createDateInstance(pyicu.DateFormat.kShort, icu),
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
80 }
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
81 icu_tf = result['icu_tf'] = {
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82 'full': createTimeInstance(pyicu.DateFormat.kFull, icu),
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83 'long': createTimeInstance(pyicu.DateFormat.kLong, icu),
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
84 'medium': createTimeInstance(pyicu.DateFormat.kMedium, icu),
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
85 'short': createTimeInstance(pyicu.DateFormat.kShort, icu),
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
86 }
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
87
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
88 result['dateFormats'] = {}
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89 result['timeFormats'] = {}
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
90 for x in keys:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
91 result['dateFormats'][x] = icu_df[x].toPattern()
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92 result['timeFormats'][x] = icu_tf[x].toPattern()
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94 am = pm = ts = ''
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 # ICU doesn't seem to provide directly the date or time separator
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
97 # so we have to figure it out
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 o = result['icu_tf']['short']
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 s = result['timeFormats']['short']
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
101 result['usesMeridian'] = 'a' in s
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
102 result['uses24'] = 'H' in s
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
103
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104 # '11:45 AM' or '11:45'
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105 s = o.format(datetime.datetime(2003, 10, 30, 11, 45))
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
106
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107 # ': AM' or ':'
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
108 s = s.replace('11', '').replace('45', '')
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
109
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
110 if len(s) > 0:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
111 ts = s[0]
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113 if result['usesMeridian']:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
114 # '23:45 AM' or '23:45'
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
115 am = s[1:].strip()
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116 s = o.format(datetime.datetime(2003, 10, 30, 23, 45))
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
118 if result['uses24']:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
119 s = s.replace('23', '')
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
120 else:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
121 s = s.replace('11', '')
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
122
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
123 # 'PM' or ''
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
124 pm = s.replace('45', '').replace(ts, '').strip()
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
125
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
126 result['timeSep'] = [ts]
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
127 result['meridian'] = [am, pm] if am and pm else []
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
129 o = result['icu_df']['short']
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
130 s = o.format(datetime.datetime(2003, 10, 30, 11, 45))
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131 s = s.replace('10', '').replace('30', '').replace(
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
132 '03', '').replace('2003', '')
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
134 if len(s) > 0:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
135 ds = s[0]
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
136 else:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137 ds = '/'
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
138
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139 result['dateSep'] = [ds]
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
140 s = result['dateFormats']['short']
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
141 l = s.lower().split(ds)
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
142 dp_order = []
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
143
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
144 for s in l:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
145 if len(s) > 0:
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
146 dp_order.append(s[:1])
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
147
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
148 result['dp_order'] = dp_order
83b1bc99457c upgrade parsedatetime from 0.8.7 to 2.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
149 return icu_object(result)