diff options
author | Michael G Schwern <schwern@pobox.com> | 2008-09-12 17:18:02 -0700 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2009-01-03 18:36:05 +0100 |
commit | a272e669f4b28ef6839df6dcd80d81421a1924dc (patch) | |
tree | d0114ac536208fcdbaff03440cf0e58e7e65f9b7 /t/op | |
parent | b51c85cfecd5519fb69801887d6d6ebf80d9fce4 (diff) | |
download | perl-a272e669f4b28ef6839df6dcd80d81421a1924dc.tar.gz |
Patch in a 64 bit clean gmtime_r() and localtime_r() from the y2038 project. http://y2038.googlecode.com/ so Perl is no longer subject to the y2038 bug.
Use Quad_t for our 64 bit time_t replacement.
Temporarily through out the "broken localtime work around". That will
have to be integrated into localtime64_r().
Fix Time::Local to handle the new expanded date range. "use integer" had
to go as it pegged scalars to 32 bit integers which aren't large enough
to hold the new time range.
There are probably portability issues. timegm, for example, is not portable.
Also the assumption that "long" is 64 bits is probably wrong.
Diffstat (limited to 't/op')
-rwxr-xr-x | t/op/time.t | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/t/op/time.t b/t/op/time.t index 8b2f07d2d3..a67dead9b1 100755 --- a/t/op/time.t +++ b/t/op/time.t @@ -1,14 +1,12 @@ #!./perl -$does_gmtime = gmtime(time); - BEGIN { chdir 't' if -d 't'; @INC = '../lib'; require './test.pl'; } -plan tests => 8; +plan tests => 32; ($beguser,$begsys) = times; @@ -32,7 +30,9 @@ ok($i >= 2_000_000, 'very basic times test'); ($xsec,$foo) = localtime($now); $localyday = $yday; -ok($sec != $xsec && $mday && $year, 'localtime() list context'); +isnt($sec, $xsec), 'localtime() list context'; +ok $mday, ' month day'; +ok $year, ' year'; ok(localtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ] (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ] @@ -56,13 +56,13 @@ $ENV{TZ} = "GMT+5"; ok($hour != $hour2, 'changes to $ENV{TZ} respected'); } -SKIP: { - skip "No gmtime()", 3 unless $does_gmtime; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($beg); ($xsec,$foo) = localtime($now); -ok($sec != $xsec && $mday && $year, 'gmtime() list context'); +isnt($sec, $xsec), 'gmtime() list conext'; +ok $mday, ' month day'; +ok $year, ' year'; my $day_diff = $localyday - $yday; ok( grep({ $day_diff == $_ } (0, 1, -1, 364, 365, -364, -365)), @@ -76,4 +76,49 @@ ok(gmtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ] /x, 'gmtime(), scalar context' ); + + + +# Test gmtime over a range of times. +{ + # gm/localtime is limited by the size of tm_year which might be as small as 16 bits + my %tests = ( + # time_t gmtime list scalar + -2**35 => [52, 13, 20, 7, 2, -1019, 5, 65, 0, "Fri Mar 7 20:13:52 881"], + -2**32 => [44, 31, 17, 24, 10, -67, 0, 327, 0, "Sun Nov 24 17:31:44 1833"], + -2**31 => [52, 45, 20, 13, 11, 1, 5, 346, 0, "Fri Dec 13 20:45:52 1901"], + 0 => [0, 0, 0, 1, 0, 70, 4, 0, 0, "Thu Jan 1 00:00:00 1970"], + 2**30 => [4, 37, 13, 10, 0, 104, 6, 9, 0, "Sat Jan 10 13:37:04 2004"], + 2**31 => [8, 14, 3, 19, 0, 138, 2, 18, 0, "Tue Jan 19 03:14:08 2038"], + 2**32 => [16, 28, 6, 7, 1, 206, 0, 37, 0, "Sun Feb 7 06:28:16 2106"], + 2**39 => [8, 18, 12, 25, 0, 17491, 2, 24, 0, "Tue Jan 25 12:18:08 19391"], + ); + + for my $time (keys %tests) { + my @expected = @{$tests{$time}}; + my $scalar = pop @expected; + + ok eq_array([gmtime($time)], \@expected), "gmtime($time) list context"; + is scalar gmtime($time), $scalar, " scalar"; + } +} + + +# Test localtime +{ + # We pick times which fall in the middle of a month, so the month and year should be + # the same regardless of the time zone. + my %tests = ( + # time_t month, year, scalar + 5000000000 => [5, 228, qr/Jun \d+ .* 2128$/], + 1163500000 => [10, 106, qr/Nov \d+ .* 2006$/], + ); + + for my $time (keys %tests) { + my @expected = @{$tests{$time}}; + my $scalar = pop @expected; + + ok eq_array([(localtime($time))[4,5]], \@expected), "localtime($time) list context"; + like scalar localtime($time), $scalar, " scalar"; + } } |