◐ Shell
clean mode source ↗

`datetime.strptime` accepts incompatible arguments

Bug report

Bug description:

If you over-specify a datetime strptime string, it seems that datetime.strptime when encountering a component that has been specified twice, will overwrite earlier values with more recent ones.

>>> datetime.strptime("200099", "%Y%y")
datetime.datetime(1999, 1, 1, 0, 0)

One approach would be to ban over-specified formats, but that would be a problem for someone who wants to, use a format like "%M %B" (e.g. something sortable by month number while also showing month name), so I think we don't want to do that.

Alternatively we could start raising an exception if you get different values from these two things, or possibly a warning.

Or we can just accept that if you use a weird format you should expect weird behavior.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs