`datetime.strptime(dt.strftime("%c"), "%c"))` fails when year is <1000.
Bug report
Bug description:
>>> from datetime import datetime >>> datetime.strptime(datetime(1000, 1, 1).strftime("%c"), "%c") datetime.datetime(1000, 1, 1, 0, 0) >>> datetime.strptime(datetime(999, 1, 1).strftime("%c"), "%c") Traceback (most recent call last): File "<python-input-1>", line 1, in <module> datetime.strptime(datetime(999, 1, 1).strftime("%c"), "%c") ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/nlx5/Documents/Programming/Python/cpython/Lib/_strptime.py", line 573, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format) ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^ File "/home/nlx5/Documents/Programming/Python/cpython/Lib/_strptime.py", line 352, in _strptime raise ValueError("time data %r does not match format %r" % (data_string, format)) ValueError: time data 'Tue Jan 1 00:00:00 999' does not match format '%c'
Discovered this when adding some hypothesis tests for strptime/strftime. I doubt this is a real problem anyone is going to have in the real world, but maybe.
I do not know if this is locale-specific or OS specific.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux