fix: str2time rejects epoch -1 (Dec 31, 1969 23:59:59 UTC)#112
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: str2time rejects epoch -1 (Dec 31, 1969 23:59:59 UTC)#112Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
The epoch -1 detection logic compares parsed date components against a hardcoded string to distinguish the legitimate -1 return value from timegm/timelocal errors. However, since two-digit years are now normalized to four-digit years before the timegm call, the comparison always fails — the join produces "59592331111969" (year=1969) but the check expected "595923311169" (year=69). Fix: update the UTC check to use the 4-digit year string, and adjust the local-time check to add 1900 to the localtime(-1) year component. 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
str2timereturnsundeffor any date string representing epoch -1 (December 31, 1969 23:59:59 UTC).Why
The epoch -1 detection logic compares
join("", $ss, $mm, $hh, $day, $month, $year)against a hardcoded reference string to distinguish the legitimate-1return fromtimegm/timelocalerrors. Since the year normalization code (two-digit → four-digit) was added,$yearis always1969at the comparison point — but the reference string still used69. The join produces"59592331111969"(14 chars) while the check expected"595923311169"(12 chars), so the comparison always fails andstr2timeincorrectly returnsundef.How
"595923311169"to"59592331111969"localtime(-1)returns year=69 (years since 1900), so added+= 1900to match the normalized$yearTesting
t/edge-cases.tcovering ISO 8601, RFC 2822, 2-digit year, and space-separated formats🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 24 insertions(+), 2 deletions(-)
Code scan: clean
Tests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline