While doing some data cleaning, I noticed that dateutil.parser.parse failed to reject a certain malformed date, thinking that the first number in it is a two digit year. Can this library be forced to treat two digit years as invalid?
Example:
from dateutil.parser import parse
parse('22-23 February')
outputs:
datetime.datetime(2022, 2, 23, 0, 0)
I managed to work around this by passing a custom
dateutil.parser.parserinfoobject via theparserinfoparameter todateutil.parser.parse. Luckily,dateutil.parser.parserinfohas aconvertyearmethod that can be overloaded in a derived class in order to perform extra validations on the year.outputs: