parser.parse('2014-X') fails during a special time of the month

Bug #1300508 reported by Aaron Krill
8
This bug affects 1 person
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.parse('2014-02')

This will fail if you execute it on a day greater than 29 if the preceding year is a leapyear or not:

parser.parse('2012-02')

These will fail if you execute it on the 31st, regardless of the year:

parser.parse('2014-04')
parser.parse('2014-06')
parser.parse('2014-09')
parser.parse('2014-11')

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://github.com/krillr/python-dateutil/commit/478b5799756a40a1f57a9a8b49a82f0c1e269165

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.

Revision history for this message
Paul G (p-ganssle) wrote :

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

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.