parser.parse('2014-X') fails during a special time of the month
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
dateutil |
New
|
Undecided
|
Unassigned |
Bug Description
More specifically, this will fail if you execute it on a day greater than 28 if the preceding year is a non-leapyear:
parser.
This will fail if you execute it on a day greater than 29 if the preceding year is a leapyear or not:
parser.
These will fail if you execute it on the 31st, regardless of the year:
parser.
parser.
parser.
parser.
This is because the default for parse() uses today's date, then replaces certain attributes. With these timestamps, there is no day to be replaced, so it defaults to today's date. If today's day is say, 31 -- but the month you're trying to change to is a 30-day month, datetime will raise a ValueError.
There is a tentative fix for this on my github account here: https:/
It is without tests, as your tests.py is huge and unwieldy and I didn't have time to work through it and find the right spot.
This bug was also reported on the github issue tracker: https:/ /github. com/dateutil/ dateutil/ issues/ 25
I submitted a PR some time ago to at least partially deal with this by adding a "smart parser" option, which attempts to make a more reasonable choice of default dates if unspecified. Comments on the approach would be appreciated: https:/ /github. com/dateutil/ dateutil/ pull/30