[docs] [issue19376] document that strptime() does not support the Feb 29 if the format does not contain the year

Alexander Belopolsky report at bugs.python.org
Thu Oct 24 19:08:23 CEST 2013


Alexander Belopolsky added the comment:

> what's the reason for accepting the time.strptime()
> version as a bug, but not datetime.datetime.strptime()?

In case of time.strptime(), we have an option of returning (1900, 2, 29, ..) which while not being a valid date, is a valid (time)tuple:

>>> time.mktime((1900, 2, 29, 0, 0, 0, 0, 0, 0))
-2203873200.0

The time module treats 1900-02-29 as 1900-03-01:

>>> time.mktime((1900, 3, 1, 0, 0, 0, 0, 0, 0))
-2203873200.0


Datetime is stricter than that:

>>> datetime(1900, 2, 29)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: day is out of range for month


There is no valid datetime value that can reasonably be returned from datetime.strptime('Feb 29', '%b %d').

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19376>
_______________________________________


More information about the docs mailing list