fix: align Date::Language::str2time year handling with Date::Parse#138
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
Conversation
Date::Language::str2time was missing two pieces of year normalization that Date::Parse::str2time applies: 1. Century restoration — when strptime returns a $century value (from 4-digit year input), the year must be restored via $year += 1900. Without this, Language.pm relied on Time::Local treating small values as years-since-1900, which works but is fragile. 2. Two-digit year POSIX normalization — Date::Parse uses a fixed threshold (69-99 → 1900s, 00-68 → 2000s) matching POSIX strptime conventions. Language.pm delegated this to Time::Local's sliding window, which on Time::Local >= 1.28 centers on the current year, producing different results for years 69-76 (e.g., "1 Jun 69" resolves to 2069 via Language but 1969 via Parse). Also adds explicit fractional-second handling ($frac separation and re-addition) to match Date::Parse::str2time's approach, instead of relying on Time::Local accepting float seconds. 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
Adds missing year normalization to
Date::Language::str2timeso itproduces the same results as
Date::Parse::str2timefor two-digit years.Why
Date::Language::str2timedelegated two-digit year interpretation entirelyto
Time::Local, whose sliding-window algorithm diverges from the fixedPOSIX threshold that
Date::Parse::str2timeapplies. On modernTime::Local(>= 1.28), years 69–76 resolve to the 2000s via Languagebut the 1900s via Parse — e.g.,
"1 Jun 69 GMT"gives 2069 vs 1969.Users switching between the two APIs (Parse for English, Language for
localized dates) would get different results for the same input string.
How
$centuryfrom strptime return (8th element, previously ignored)$year += 1900)timegmand re-add to resultTesting
t/lang-str2time.twith two-digit year consistency testscovering the full range (0, 1, 26, 50, 68, 69, 70, 75, 95, 99)
prove -l t/— all tests green)🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 69 insertions(+), 2 deletions(-)
Code scan: clean
Tests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline