◐ Shell
clean mode source ↗

gh-124529: Fix `_strptime` to make `%c`/`%x` accept a year with fewer digits by zuo · Pull Request #124778 · python/cpython

_strptime.TimeRE has been modified, regarding the %c and %x format
codes, to make datetime.datetime.strptime(), datetime.date.strptime()
and time.strptime() accept inputs that contain year numbers consisting
of fewer digits than usual, i.e., not zero-padded to the usual width
of 2 or 4 (which is appropriate for the format code and current locale).

Thanks to that, now the desired behavior described in gh-124529 should be
consistently observed; certain strftime/strptime round trips (involving
%c/%x and small year numbers) no longer raise ValueError for some
platforms/locales (in particular, this was the case on Linux, for various
locales, including C/C.UTF-8).