Conversation
The period handling added a flat +12 offset whenever the input
contained pm, which breaks both 12 o'clock cases:
>>> parse_time('12:00 PM', locale='en_US')
ValueError: hour must be in 0..23, not 24
>>> parse_time('12:30 AM', locale='en_US')
datetime.time(12, 30) # midnight parsed as half past noon
en_US's own medium time format is 'h:mm:ss a', so parsing noon in the
most common locale crashes and midnight silently lands on the wrong
side of the day. Convert the 12-hour clock properly: 12 AM is 00:00
and 12 PM is 12:00, only 1-11 AM/PM shift by twelve hours.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parse_timeadds a flat+12offset whenever the format contains a period marker and the input containspm, which breaks both 12 o'clock cases:en_US's own medium time format ish:mm:ss a, so parsing noon in the most common locale crashes and midnight silently lands twelve hours off. This converts the 12-hour clock the way it works: 12 AM is 00:00, 12 PM is 12:00, and only hours 1–11 shift by twelve.Verification
test_parse_timecases (12:00 pm,12:00 PM,12:30 am,12 AM,12:00:15 pm) fail on master (theValueError: hour must be in 0..23, not 24and the wrong midnight) and pass with this change; all pre-existing am/pm cases are unaffected.pytest tests/test_dates.py→ 1196 passed; the 5 remaining failures are the same CLDR-data-drift failures present on master in my environment (skeleton/1076/1192/892 — unrelated to time parsing).ruff checkclean.AI Disclosure
This PR was prepared with the assistance of an AI coding agent.
ZCode (GLM-based coding agent)