Revision 1515
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/xml_func.py | ||
---|---|---|
240 | 240 |
items = dict(conv_items(str, items)) # get *once* from iter and check types |
241 | 241 |
try: str_ = items['date'] |
242 | 242 |
except KeyError: |
243 |
items = dict(conv_items(int, items.iteritems()))
|
|
244 |
try: items['year'] # year is required
|
|
243 |
# Year is required
|
|
244 |
try: items['year'] |
|
245 | 245 |
except KeyError, e: |
246 | 246 |
if items == {}: return None # entire date is empty |
247 | 247 |
else: raise SyntaxException(e) |
248 |
|
|
249 |
# Convert month name to number |
|
250 |
try: month = items['month'] |
|
251 |
except KeyError: pass |
|
252 |
else: |
|
253 |
if not month.isdigit(): # month is name |
|
254 |
items['month'] = str(dates.strtotime(month).month) |
|
255 |
|
|
256 |
items = dict(conv_items(int, items.iteritems())) |
|
248 | 257 |
items.setdefault('month', 1) |
249 | 258 |
items.setdefault('day', 1) |
250 | 259 |
try: date = datetime.date(**items) |
Also available in: Unified diff
xml_func.py: _date: month: Convert month names to numbers before casting everything to int