fix: strptime rejects hours > 12 with AM/PM suffix#116
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: strptime rejects hours > 12 with AM/PM suffix#116Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
strptime("13:30 PM") returned hh=25 (13+12) instead of signaling
invalid input. The meridian arithmetic unconditionally added 12 for
PM without checking that the hour was in valid 12-hour range (1-12).
Add early return when AM/PM is specified with hours > 12, and
regression tests covering both rejection and valid AM/PM parsing.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
What
strptime()now returns empty list when hours > 12 are combined with AM/PM.Why
strptime("13:30 PM")returnedhh=25(13+12) — an invalid hour value that could propagate silently through downstream code. Whilestr2time()caught this at validation,strptime()callers had no protection.How
Added early return before the meridian arithmetic when
$merid != 24(AM/PM was specified) and$hh > 12. The sentinel value 24 means "no meridian specified" — only actual AM/PM triggers the check.Testing
t/ampm-validation.twith 26 tests covering:Date::Language::strptime(generated from same template)🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 63 insertions(+)
Code scan: clean
Tests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline