diff options
author | Barry Warsaw <barry@python.org> | 2002-08-29 15:29:49 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2002-08-29 15:29:49 (GMT) |
commit | 2bdb61479d235339dc92505d5eccaa6accf4d94c (patch) | |
tree | fad58509a9f8d8695a01a1d157b42e0d3ecf1a96 /Lib | |
parent | 375e0eeacc23394dfe5f21970070ea50ded1160b (diff) | |
download | cpython-2bdb61479d235339dc92505d5eccaa6accf4d94c.zip cpython-2bdb61479d235339dc92505d5eccaa6accf4d94c.tar.gz cpython-2bdb61479d235339dc92505d5eccaa6accf4d94c.tar.bz2 |
strptime(): The code that was adding 12 to PM hours was incorrect
because it added it to 12 PM too. 12 PM should be hour 12 not hour
24.
Also cleaned up a minor style nit. There are more style problems in
this file that I'll clean up next (but I didn't want them to overwhelm
the substance of this fix).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/_strptime.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Lib/_strptime.py b/Lib/_strptime.py index f7e04cd..6174718 100644 --- a/Lib/_strptime.py +++ b/Lib/_strptime.py @@ -415,12 +415,19 @@ def strptime(data_string, format="%a %b %d %H:%M:%S %Y"): hour = int(found_dict['H']) else: hour = int(found_dict['I']) - if found_dict.has_key('p'): - if found_dict['p'] == locale_time.am_pm[1]: + ampm = found_dict.get('p') + if ampm == locale_time.am_pm[0]: + # We're in AM so the hour is correct unless we're + # looking at 12 midnight. + # 12 midnight == 12 AM == hour 0 + if hour == 12: + hour = 0 + elif ampm == locale_time.am_pm[1]: + # We're in PM so we need to add 12 to the hour unless + # we're looking at 12 noon. + # 12 noon == 12 PM == hour 12 + if hour != 12: hour += 12 - else: - if hour is 12: - hour = 0 elif group_key is 'M': minute = int(found_dict['M']) elif group_key is 'S': |