dateutil.parser used to parse a given string and convert it to a datetime.datetime object. It handles ambiguous dates, such as "2-5-2013", allowing the dayfirst and yearfirst parameters to use case in a specific format.
Is it possible for the parser to throw an error if it encounters an ambiguous date? I assume that for this you will need to change the source code ( parser.py ) around lines 675/693/696 , but if there is a way that does not require literal editing of the source code and instead simply involves redefining certain functions, this will also be great .
Current behavior:
>>> from dateutil import parser >>> parser.parse("02-03-2013") datetime.datetime(2013, 2, 3, 0, 0)
Desired behavior:
>>> from dateutil import parser >>> parser.parse("02-03-2013") Traceback (most recent call last): .. ValueError: The date was ambiguous...<some text>
source share