Debian Codegraph @

t/rt57800.t

raw
1 use strict;
2 use warnings;
3 use Test::More tests => 4;
4 use Date::Parse qw(str2time);
5
6 # RT#57800 (GH#3): str2time fails on numeric m/d/yyyy dates before 1970
7 # str2time('5/1/1960') was returning undef with "Day too big" errors on
8 # 32-bit systems. Root cause: strptime extracts the 2-digit year (60) and
9 # stores century (19) separately. str2time must reconstruct the full 4-digit
10 # year before calling Time::Local to avoid the 2-digit year windowing heuristic
11 # mapping year 60 to 2060 instead of 1960.
12 {
13 my @cases = (
14 [ '5/1/1960', 1960, 5, 1, "m/d/yyyy May 1 1960" ],
15 [ '1/5/1960', 1960, 1, 5, "m/d/yyyy Jan 5 1960" ],
16 [ '12/31/1960', 1960, 12, 31, "m/d/yyyy Dec 31 1960" ],
17 [ '5/1/1901', 1901, 5, 1, "m/d/yyyy May 1 1901" ],
18 );
19
20 for my $c (@cases) {
21 my ($date, $expected_year, $expected_mon, $expected_day, $desc) = @$c;
22
23 SKIP: {
24 skip "pre-1970 dates on Win32", 1 if $^O eq 'MSWin32';
25
26 my $t = str2time($date);
27 if (!defined $t) {
28 fail("RT#57800: str2time('$date') returned undef");
29 next;
30 }
31 my @gm = gmtime($t);
32 my $got_year = 1900 + $gm[5];
33 is($got_year, $expected_year, "RT#57800: $desc parses to year $expected_year");
34 }
35 }
36 }