fix: DD-MM-YYYY swap off-by-one for day 13#134
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: DD-MM-YYYY swap off-by-one for day 13#134Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
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>
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
Fixes
strptimefailing to parse13-01-2025as January 13, returning an invalid month instead.Why
The DD-MM-YYYY swap logic checks
$month > 12to detect when the first field can't be a month. But$monthis 0-indexed ($1 - 1), so when the first field is 13,$monthis 12 — which is NOT> 12and skips the swap. The result is an invalid month thatstr2timerejects asundef.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 > 12to$month > 11. Valid 0-indexed months are 0-11, so any value > 11 triggers the format disambiguation.Testing
str2time("13-01-2025")now returns a defined epoch (previouslyundef)🤖 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