[issue22840] strpdate('20141110', '%Y%m%d%H%S') returns wrong date

Brett Cannon report at bugs.python.org
Tue Nov 11 16:34:18 CET 2014


Brett Cannon added the comment:

strptime very much follows the POSIX standard as I implemented strptime by reading that doc.

If you want to see how the behaviour is implemented you can look at https://hg.python.org/cpython/file/ac0334665459/Lib/_strptime.py#l178 . But the key thing here is that the OP has unused formatters. Since strptime uses regexes underneath the hood, the re module does its best to match the entire format. Since POSIX says that e.g. the leading 0 for %m is optional, the regex goes with the single digit version to let the %H format match _something_ (same goes for %d and %M). So without rewriting strptime to not use regexes to support unused formatters and to stop being so POSIX-compliant, I don't see how to change the behaviour. Plus it would be backwards-incompatible as this is how strptime has worked in 2002.

It's Alexander's call, but I vote to close this as "not a bug".

----------
nosy: +brett.cannon

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22840>
_______________________________________


More information about the Python-bugs-list mailing list