Skip to content

fix: DD-MM-YYYY swap off-by-one for day 13#134

Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-ddmm-swap-off-by-one
Draft

fix: DD-MM-YYYY swap off-by-one for day 13#134
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-ddmm-swap-off-by-one

Conversation

@Koan-Bot
Copy link
Copy Markdown

@Koan-Bot Koan-Bot commented May 3, 2026

What

Fixes strptime failing to parse 13-01-2025 as January 13, returning an invalid month instead.

Why

The DD-MM-YYYY swap logic checks $month > 12 to detect when the first field can't be a month. But $month is 0-indexed ($1 - 1), so when the first field is 13, $month is 12 — which is NOT > 12 and skips the swap. The result is an invalid month that str2time rejects as undef.

This affects any date where the day is exactly 13 in DD-MM-YYYY format (e.g., 13-01-2025, 13-06-2020).

How

One-character fix: change $month > 12 to $month > 11. Valid 0-indexed months are 0-11, so any value > 11 triggers the format disambiguation.

Testing

  • Added 6 regression tests for day-13 and day-14 DD-MM-YYYY formats
  • All 592 existing tests pass
  • Verified str2time("13-01-2025") now returns a defined epoch (previously undef)

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 17 insertions(+), 2 deletions(-)

Code scan: clean

Tests: skipped

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

The date swap logic uses 0-indexed months ($month = $1 - 1) but
checked $month > 12 instead of $month > 11. This meant that when the
first field was exactly 13, $month was 12 (one past December), which
did NOT trigger the swap — so "13-01-2025" was parsed as invalid
month 12 instead of January 13.

Fix: change the boundary check from $month > 12 to $month > 11, so
any value that cannot be a valid month (0-11) triggers the DD-MM-YYYY
or YYYY-MM-DD disambiguation.

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