[New-bugs-announce] [issue33631] [ValueError] _strptime.py can't handle 12-hr format strings using '0' instead of '12' for noon and midnight

CatPaw Freed report at bugs.python.org
Thu May 24 03:29:39 EDT 2018


New submission from CatPaw Freed <prawarit888 at gmail.com>:

I have to process some data which date was specified in 12-hour format, eg. 9/24/2017 0:39:41 PM.
I call datetime.datetime.strptime with "%m/%d/%Y %I:%M:%S %p" format.
However, it throws me an error [File "C:\Python27\lib\_strptime.py", line 332, in _strptime (data_string, format)) ValueError: time data '9/24/2017 0:39:41 PM' does not match format '%m/%d/%Y %I:%M:%S %p'].
Then, I found out that, in _strptime.py, the regex patterns are defined as below.

            'd': r"(?P<d>3[0-1]|[1-2]\d|0[1-9]|[1-9]| [1-9])",
            'f': r"(?P<f>[0-9]{1,6})",
            'H': r"(?P<H>2[0-3]|[0-1]\d|\d)",
            'I': r"(?P<I>1[0-2]|0[1-9]|[1-9])",
            'j': r"(?P<j>36[0-6]|3[0-5]\d|[1-2]\d\d|0[1-9]\d|00[1-9]|[1-9]\d|0[1-9]|[1-9])",
            'm': r"(?P<m>1[0-2]|0[1-9]|[1-9])",
            'M': r"(?P<M>[0-5]\d|\d)",
            'S': r"(?P<S>6[0-1]|[0-5]\d|\d)",
            'U': r"(?P<U>5[0-3]|[0-4]\d|\d)",
            'w': r"(?P<w>[0-6])",

I'm a newbie in python world. Is it a bug?
I changed regex pattern of 'I' to r"(?P<I>1[0-2]|0[0-9]|[0-9])" and it works.
I would like to know why 0 is excluded.
May be, I have missed something.

----------
messages: 317541
nosy: CatPaw Freed
priority: normal
severity: normal
status: open
title: [ValueError] _strptime.py can't handle 12-hr format strings using '0' instead of '12' for noon and midnight
type: crash

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33631>
_______________________________________


More information about the New-bugs-announce mailing list