[ 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;
$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);
}
}
+
for (@bad_time) {
my($year, $mon, $mday, $hour, $min, $sec) = @$_;
$year -= 1900;
}
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";
}
}
require './test.pl';
}
-plan tests => 32;
+plan tests => 34;
($beguser,$begsys) = times;
# 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";
}
}