[New-bugs-announce] [issue14157] time.strptime without a year fails on Feb 29

Martin Morrison report at bugs.python.org
Wed Feb 29 12:57:48 CET 2012


New submission from Martin Morrison <martin.morrison at gmail.com>:

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 <report at bugs.python.org>
<http://bugs.python.org/issue14157>
_______________________________________


More information about the New-bugs-announce mailing list