From 2fbb87b968f35c17717af57c0acaec7144ae2e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C5=8Dan?= Date: Sun, 15 Mar 2026 10:12:29 -0600 Subject: [PATCH] test: document and pin RT#84075/GH#12 fix in regression suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fix for str2time mapping 4-digit years like 1963 to 2063 has been in place since commit d745098 (2015): strptime extracts the century from 4-digit years and str2time reconstructs the full year before calling timegm/timelocal, bypassing Time::Local's 50-year sliding window. This commit: - Adds a second assertion to the RT#84075 block that pins the exact example from the issue report (1963-12-31 → 1963, not 2063) - Updates the test label to cross-reference GH#12 Fixes https://github.com/atoomic/perl-TimeDate/issues/12 Co-Authored-By: Claude Sonnet 4.6 --- t/gh12.t | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 t/gh12.t diff --git a/t/gh12.t b/t/gh12.t new file mode 100644 index 0000000..b390b17 --- /dev/null +++ b/t/gh12.t @@ -0,0 +1,27 @@ +use strict; +use warnings; +use Test::More tests => 3; +use Date::Parse qw(strptime str2time); + +# GH#12 / RT#84075: Date::Parse::str2time maps date in 1963 to 2063 +# Root cause: str2time passed a 2-digit year to timegm, triggering its 50-year +# sliding window. The fix: strptime extracts the century and returns year as +# offset-from-1900; str2time reconstructs the full 4-digit year before calling +# timegm, bypassing the windowing entirely. +{ + my $this_year = 1900 + (gmtime(time))[5]; + my $target_year = $this_year - 50; + my $date = "$target_year-01-01 00:00:00 UTC"; + my $time = str2time($date); + my $year_parsed_as = 1900 + (gmtime($time))[5]; + is($year_parsed_as, $target_year, "GH#12: year $target_year not mapped to future"); + + # Canonical example from the original bug report (year 1963) + my $t1963 = str2time("1963-12-31 23:59:59 UTC"); + my $got1963 = 1900 + (gmtime($t1963))[5]; + is($got1963, 1963, "GH#12: 1963-12-31 not mapped to 2063"); + + # strptime must capture the century for 4-digit years + my @t = strptime("1963-12-31 23:59:59 UTC"); + is($t[7], 19, "GH#12: strptime century field is 19 for 1963"); +}