Author gregory.p.smith
Recipients Sriram Rajagopalan, belopolsky, gregory.p.smith
Date 2016-02-29.23:44:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
time.strptime() is "working" (not raising an exception) as it appears not to validate the day of the month when a year is not specified, yet the return value from either of these APIs is a date which has no concept of an ambiguous year.

## Via the admittedly old Python 2.7.6 from Ubuntu 14.04: ##
# 1900 was not a leap year as it is not divisible by 400.
>>> time.strptime("1900 Feb 29", "%Y %b %d")
ValueError: day is out of range for month
>>> time.strptime("Feb 29", "%b %d")
time.struct_time(tm_year=1900, tm_mon=2, tm_mday=29, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=60, tm_isdst=-1)

So what should the validation behavior be?

>>> datetime.datetime.strptime("Feb 29", "%b %d")
ValueError: day is out of range for month
>>> datetime.datetime.strptime("2016 Feb 29", "%Y %b %d")
datetime.datetime(2016, 2, 29, 0, 0)
>>> datetime.datetime.strptime("1900 Feb 29", "%Y %b %d")
ValueError: day is out of range for month
>>> datetime.datetime(year=1900, month=2, day=29)
ValueError: day is out of range for month

datetime objects cannot be constructed with the invalid date (as the time.strptime return value allows).

Changing the API to assume the current year or a +/- 6 months from "now" when no year is parsed is likely to break existing code.
Date User Action Args
2016-02-29 23:44:22gregory.p.smithsetrecipients: + gregory.p.smith, belopolsky, Sriram Rajagopalan
2016-02-29 23:44:22gregory.p.smithsetmessageid: <>
2016-02-29 23:44:22gregory.p.smithlinkissue26460 messages
2016-02-29 23:44:22gregory.p.smithcreate