Skip to content

fix: strptime rejects hours > 12 with AM/PM suffix#116

Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-strptime-ampm-validation
Draft

fix: strptime rejects hours > 12 with AM/PM suffix#116
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-strptime-ampm-validation

Conversation

@Koan-Bot
Copy link
Copy Markdown

@Koan-Bot Koan-Bot commented Apr 19, 2026

What

strptime() now returns empty list when hours > 12 are combined with AM/PM.

Why

strptime("13:30 PM") returned hh=25 (13+12) — an invalid hour value that could propagate silently through downstream code. While str2time() 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

  • New t/ampm-validation.t with 26 tests covering:
    • Invalid inputs rejected (13:00 PM, 14:00 AM, etc.)
    • Valid AM/PM still works (1:30 PM → 13, 12:00 AM → 0)
    • 24-hour format unaffected (13:00, 23:59)
  • Full test suite passes
  • Verified fix propagates to 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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant