| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More tests => 3; |
| 4 |
use Date::Parse qw(strptime str2time); |
| 5 |
|
| 6 |
# GH#12 / RT#84075: Date::Parse::str2time maps date in 1963 to 2063 |
| 7 |
# Root cause: str2time passed a 2-digit year to timegm, triggering its 50-year |
| 8 |
# sliding window. The fix: strptime extracts the century and returns year as |
| 9 |
# offset-from-1900; str2time reconstructs the full 4-digit year before calling |
| 10 |
# timegm, bypassing the windowing entirely. |
| 11 |
{ |
| 12 |
my $this_year = 1900 + (gmtime(time))[5]; |
| 13 |
my $target_year = $this_year - 50; |
| 14 |
my $date = "$target_year-01-01 00:00:00 UTC"; |
| 15 |
my $time = str2time($date); |
| 16 |
my $year_parsed_as = 1900 + (gmtime($time))[5]; |
| 17 |
is($year_parsed_as, $target_year, "GH#12: year $target_year not mapped to future"); |
| 18 |
|
| 19 |
# Canonical example from the original bug report (year 1963) |
| 20 |
my $t1963 = str2time("1963-12-31 23:59:59 UTC"); |
| 21 |
my $got1963 = 1900 + (gmtime($t1963))[5]; |
| 22 |
is($got1963, 1963, "GH#12: 1963-12-31 not mapped to 2063"); |
| 23 |
|
| 24 |
# strptime must capture the century for 4-digit years |
| 25 |
my @t = strptime("1963-12-31 23:59:59 UTC"); |
| 26 |
is($t[7], 19, "GH#12: strptime century field is 19 for 1963"); |
| 27 |
} |