New submission from Martin Morrison <[email protected]>:
time.strptime without a year fails on Feb 29 with:
>>> time.strptime("Feb 29", "%b %d")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/_strptime.py", line 454, in _strptime_time
return _strptime(data_string, format)[0]
File "/usr/lib/python2.6/_strptime.py", line 440, in _strptime
datetime_date(year, 1, 1).toordinal() + 1
ValueError: day is out of range for month
This is due to the use of "1900" as the default year when parsing. It would be
nice to have an optional "defaults" keyword argument to the strptime function
that can be used to override the defaults, thus allowing leap year dates to be
parsed without specifying the date.
(Note: the code in question attempted to set the year *after* the parse so that
ultimately there is a valid struct_time, but since the parse never succeeds,
this can't work).
----------
components: Library (Lib)
messages: 154621
nosy: Martin.Morrison
priority: normal
severity: normal
status: open
title: time.strptime without a year fails on Feb 29
type: behavior
versions: Python 2.7
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue14157>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com