From: Michael G. Schwern Date: Mon, 29 Sep 2008 16:07:29 +0000 (-0400) Subject: Everything should now work with negative times, so let's pull out all the skips from... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4c91ace1ab7f54d4e52467ee37e480e29b555047;p=p5sagit%2Fp5-mst-13.2.git Everything should now work with negative times, so let's pull out all the skips from the tests. --- diff --git a/lib/Time/Local.t b/lib/Time/Local.t index ef32b40..17e8115 100755 --- a/lib/Time/Local.t +++ b/lib/Time/Local.t @@ -62,17 +62,6 @@ my @years = [ 2100 => 0 ], ); -# Use 3 days before the start of the epoch because with Borland on -# Win32 it will work for -3600 _if_ your time zone is +01:00 (or -# greater). -my $neg_epoch_ok = defined ((localtime(-259200))[0]) ? 1 : 0; - -# use vmsish 'time' makes for oddness around the Unix epoch -if ($^O eq 'VMS') { - $time[0][2]++; - $neg_epoch_ok = 0; # time_t is unsigned -} - my $tests = (@time * 12); $tests += @neg_time * 12; $tests += @bad_time; @@ -88,28 +77,23 @@ for (@time, @neg_time) { $year -= 1900; $mon--; - SKIP: { - skip '1970 test on VOS fails.', 12 - if $^O eq 'vos' && $year == 70; - skip 'this platform does not support negative epochs.', 12 - if $year < 70 && ! $neg_epoch_ok; - - { - my $year_in = $year < 70 ? $year + 1900 : $year; - my $time = timelocal($sec,$min,$hour,$mday,$mon,$year_in); - - my($s,$m,$h,$D,$M,$Y) = localtime($time); - - is($s, $sec, "timelocal second for @$_"); - is($m, $min, "timelocal minute for @$_"); - is($h, $hour, "timelocal hour for @$_"); - is($D, $mday, "timelocal day for @$_"); - is($M, $mon, "timelocal month for @$_"); - is($Y, $year, "timelocal year for @$_"); - } + # Test timelocal() + { + my $year_in = $year < 70 ? $year + 1900 : $year; + my $time = timelocal($sec,$min,$hour,$mday,$mon,$year_in); + + my($s,$m,$h,$D,$M,$Y) = localtime($time); + + is($s, $sec, "timelocal second for @$_"); + is($m, $min, "timelocal minute for @$_"); + is($h, $hour, "timelocal hour for @$_"); + is($D, $mday, "timelocal day for @$_"); + is($M, $mon, "timelocal month for @$_"); + is($Y, $year, "timelocal year for @$_"); } - # Perl has its own gmtime() + + # Test timegm() { my $year_in = $year < 70 ? $year + 1900 : $year; my $time = timegm($sec,$min,$hour,$mday,$mon,$year_in); @@ -125,6 +109,7 @@ for (@time, @neg_time) { } } + for (@bad_time) { my($year, $mon, $mday, $hour, $min, $sec) = @$_; $year -= 1900; diff --git a/lib/Time/localtime.t b/lib/Time/localtime.t index 10df765..8600eff 100644 --- a/lib/Time/localtime.t +++ b/lib/Time/localtime.t @@ -8,30 +8,21 @@ BEGIN { } BEGIN { - my $haslocal; - eval { my $n = localtime 0 }; - $haslocal = 1 unless $@ && $@ =~ /unimplemented/; + @times = (-2**33, -2**31-1, 0, 2**31-1, 2**33, time); + @methods = qw(sec min hour mday mon year wday yday isdst); - skip_all("no localtime") unless $haslocal; -} - -BEGIN { - my @localtime = CORE::localtime 0; # This is the function localtime. + plan tests => (@times * @methods) + 1; - skip_all("localtime failed") unless @localtime; + use_ok Time::localtime; } -BEGIN { plan tests => 37; } - -BEGIN { use_ok Time::localtime; } - # Since Perl's localtime() still uses the system localtime, don't try # to do negative times. The system might not support it. -for my $time (0, 2**31-1, 2**33, time) { +for my $time (@times) { my $localtime = localtime $time; # This is the OO localtime. my @localtime = CORE::localtime $time; # This is the localtime function - for my $method (qw(sec min hour mday mon year wday yday isdst)) { + for my $method (@methods) { is $localtime->$method, shift @localtime, "localtime($time)->$method"; } } diff --git a/t/op/time.t b/t/op/time.t index a67dead..2b9be51 100755 --- a/t/op/time.t +++ b/t/op/time.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan tests => 32; +plan tests => 34; ($beguser,$begsys) = times; @@ -110,15 +110,18 @@ ok(gmtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ] # 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$/], + -8589934592 => [9, -203, qr/Oct \d+ .* 1697$/], + 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"; + my @time = (localtime($time))[4,5]; + ok( eq_array(\@time, \@expected), "localtime($time) list context" ) + or diag("@time"); like scalar localtime($time), $scalar, " scalar"; } }