Throw ValueError for two digit year dates with dateutil.parser.parse
<p>While doing some data cleaning, I noticed that <code>dateutil.parser.parse</code> 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?</p>

<p>Example:</p>

<pre><code>from dateutil.parser import parse
parse('22-23 February')
</code></pre>

<p>outputs:</p>

<pre><code>datetime.datetime(2022, 2, 23, 0, 0)
</code></pre>

<p>I managed to work around this by passing a custom <code>dateutil.parser.parserinfo</code> object via the <code>parserinfo</code> parameter to <code>dateutil.parser.parse</code>. Luckily, <code>dateutil.parser.parserinfo</code> has a <code>convertyear</code> method that can be overloaded in a derived class in order to perform extra validations on the year.</p>

<pre><code>from dateutil.parser import parse, parserinfo

class NoTwoDigitYearParserInfo(parserinfo):
    def convertyear(self, year, century_specified=False):
        if year &lt; 100 and not century_specified:
            raise ValueError('Two digit years are not supported.')
        return parserinfo.convertyear(self, year, century_specified)

parse('22-23 February', parserinfo = NoTwoDigitYearParserInfo())
</code></pre>

<p>outputs:</p>

<pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/usr/local/lib/python3.5/site-packages/dateutil/parser.py", line 1162, in parse
    return parser(parserinfo).parse(timestr, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/dateutil/parser.py", line 552, in parse
    res, skipped_tokens = self._parse(timestr, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/dateutil/parser.py", line 1055, in _parse
    if not info.validate(res):
  File "/usr/local/lib/python3.5/site-packages/dateutil/parser.py", line 360, in validate
    res.year = self.convertyear(res.year, res.century_specified)
  File "&lt;stdin&gt;", line 4, in convertyear
ValueError: Two digit years are not supported.
</code></pre>

python date parsing python-dateutil 2-digit-year