summaryrefslogtreecommitdiff
path: root/lib/Time/Local.t
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-12-20 21:21:50 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-12-20 21:21:50 +0000
commit823a69961924ac9218a5eb5cbdeedc3389c85b19 (patch)
tree2535d4aa3e2938f0c673b60943941dd0e5b1d1f2 /lib/Time/Local.t
parenta50752f9a67249b5bcecc4771bbaacc13beb2cf9 (diff)
downloadperl-823a69961924ac9218a5eb5cbdeedc3389c85b19.tar.gz
Upgrade to Time::Local 1.07_94
p4raw-id: //depot/perl@21935
Diffstat (limited to 'lib/Time/Local.t')
-rwxr-xr-xlib/Time/Local.t148
1 files changed, 88 insertions, 60 deletions
diff --git a/lib/Time/Local.t b/lib/Time/Local.t
index 809dd92e1d..c4b7827e66 100755
--- a/lib/Time/Local.t
+++ b/lib/Time/Local.t
@@ -7,12 +7,15 @@ BEGIN {
}
}
+use strict;
+
+use Test;
use Time::Local;
# Set up time values to test
-@time =
+my @time =
(
- #year,mon,day,hour,min,sec
+ #year,mon,day,hour,min,sec
[1970, 1, 2, 00, 00, 00],
[1980, 2, 28, 12, 00, 00],
[1980, 2, 29, 12, 00, 00],
@@ -30,73 +33,57 @@ use Time::Local;
# use vmsish 'time' makes for oddness around the Unix epoch
if ($^O eq 'VMS') { $time[0][2]++ }
-my $tests = @time * 2 + 4;
+my $tests = (@time * 12) + 6;
$tests += 2 if $ENV{PERL_CORE};
+$tests += 3 if $ENV{MAINTAINER};
-print "1..$tests\n";
+plan tests => $tests;
-$count = 1;
for (@time) {
my($year, $mon, $mday, $hour, $min, $sec) = @$_;
$year -= 1900;
- $mon --;
- if ($^O eq 'vos' && $count == 1) {
- print "ok $count -- skipping 1970 test on VOS.\n";
+ $mon--;
+
+ if ($^O eq 'vos' && $year == 70) {
+ skip(1, "skipping 1970 test on VOS.\n") for 1..6;
} else {
- my $time = timelocal($sec,$min,$hour,$mday,$mon,$year);
- # print scalar(localtime($time)), "\n";
- my($s,$m,$h,$D,$M,$Y) = localtime($time);
-
- if ($s == $sec &&
- $m == $min &&
- $h == $hour &&
- $D == $mday &&
- $M == $mon &&
- $Y == $year
- ) {
- print "ok $count\n";
- } else {
- print "not ok $count\n";
- }
+ my $time = timelocal($sec,$min,$hour,$mday,$mon,$year);
+
+ my($s,$m,$h,$D,$M,$Y) = localtime($time);
+
+ ok($s, $sec, 'second');
+ ok($m, $min, 'minute');
+ ok($h, $hour, 'hour');
+ ok($D, $mday, 'day');
+ ok($M, $mon, 'month');
+ ok($Y, $year, 'year');
}
- $count++;
- # Test gmtime function
- if ($^O eq 'vos' && $count == 2) {
- print "ok $count -- skipping 1970 test on VOS.\n";
+ if ($^O eq 'vos' && $year == 70) {
+ skip(1, "skipping 1970 test on VOS.\n") for 1..6;
} else {
- $time = timegm($sec,$min,$hour,$mday,$mon,$year);
- ($s,$m,$h,$D,$M,$Y) = gmtime($time);
-
- if ($s == $sec &&
- $m == $min &&
- $h == $hour &&
- $D == $mday &&
- $M == $mon &&
- $Y == $year
- ) {
- print "ok $count\n";
- } else {
- print "not ok $count\n";
- }
+ my $time = timelocal($sec,$min,$hour,$mday,$mon,$year);
+
+ my($s,$m,$h,$D,$M,$Y) = localtime($time);
+
+ ok($s, $sec, 'second');
+ ok($m, $min, 'minute');
+ ok($h, $hour, 'hour');
+ ok($D, $mday, 'day');
+ ok($M, $mon, 'month');
+ ok($Y, $year, 'year');
}
- $count++;
}
-#print "Testing that the differences between a few dates makes sense...\n";
-
-timelocal(0,0,1,1,0,90) - timelocal(0,0,0,1,0,90) == 3600
- or print "not ";
-print "ok ", $count++, "\n";
+ok(timelocal(0,0,1,1,0,90) - timelocal(0,0,0,1,0,90), 3600,
+ 'one hour difference between two calls to timelocal');
-timelocal(1,2,3,1,0,100) - timelocal(1,2,3,31,11,99) == 24 * 3600
- or print "not ";
-print "ok ", $count++, "\n";
+ok(timelocal(1,2,3,1,0,100) - timelocal(1,2,3,31,11,99), 24 * 3600,
+ 'one day difference between two calls to timelocal');
# Diff beween Jan 1, 1980 and Mar 1, 1980 = (31 + 29 = 60 days)
-timegm(0,0,0, 1, 2, 80) - timegm(0,0,0, 1, 0, 80) == 60 * 24 * 3600
- or print "not ";
-print "ok ", $count++, "\n";
+ok(timegm(0,0,0, 1, 2, 80) - timegm(0,0,0, 1, 0, 80), 60 * 24 * 3600,
+ '60 day difference between two calls to timegm');
# bugid #19393
# At a DST transition, the clock skips forward, eg from 01:59:59 to
@@ -107,17 +94,58 @@ print "ok ", $count++, "\n";
my $hour = (localtime(timelocal(0, 0, 2, 7, 3, 102)))[2];
# testers in US/Pacific should get 3,
# other testers should get 2
- print "not " unless $hour == 2 || $hour == 3;
- print "ok ", $main::count++, "\n";
+ ok($hour == 2 || $hour == 3, 1, 'hour should be 2 or 3');
+}
+
+# round trip was broken for edge cases
+ok(sprintf('%x', timegm(gmtime(0x7fffffff))), sprintf('%x', 0x7fffffff),
+ '0x7fffffff round trip through gmtime then timegm');
+
+ok(sprintf('%x', timelocal(localtime(0x7fffffff))), sprintf('%x', 0x7fffffff),
+ '0x7fffffff round trip through localtime then timelocal');
+
+if ($ENV{MAINTAINER}) {
+ eval { require POSIX; POSIX::tzset() };
+ if ($@) {
+ skip("Cannot call POSIX::tzset() on this platform\n") for 1..3;
+ }
+ else {
+ local $ENV{TZ} = 'Europe/Vienna';
+ POSIX::tzset();
+
+ # 2001-10-28 02:30:00 - could be either summer or standard time,
+ # prefer earlier of the two, in this case summer
+ my $time = timelocal(0, 30, 2, 28, 9, 101);
+ ok($time, 1004229000,
+ 'timelocal prefers earlier epoch in the presence of a DST change');
+
+ local $ENV{TZ} = 'America/Chicago';
+ POSIX::tzset();
+
+ # Same local time in America/Chicago. There is transition here as
+ # well.
+ $time = timelocal(0, 30, 1, 28, 9, 101);
+ ok($time, 1004250600,
+ 'timelocal prefers earlier epoch in the presence of a DST change');
+
+ local $ENV{TZ} = 'Australia/Sydney';
+ POSIX::tzset();
+
+ # 2001-03-25 02:30:00 in Australia/Sydney. This is the transition
+ # _to_ summer time. The southern hemisphere transitions are
+ # opposite those of the northern.
+ $time = timelocal(0, 30, 2, 25, 2, 101);
+ ok($time, 985447800,
+ 'timelocal prefers earlier epoch in the presence of a DST change');
+ }
}
if ($ENV{PERL_CORE}) {
- #print "Testing timelocal.pl module too...\n";
package test;
require 'timelocal.pl';
- timegm(0,0,0,1,0,80) == main::timegm(0,0,0,1,0,80) or print "not ";
- print "ok ", $main::count++, "\n";
+ ::ok(timegm(0,0,0,1,0,80), main::timegm(0,0,0,1,0,80),
+ 'timegm in timelocal.pl');
- timelocal(1,2,3,4,5,88) == main::timelocal(1,2,3,4,5,88) or print "not ";
- print "ok ", $main::count++, "\n";
+ ::ok(timelocal(1,2,3,4,5,88), main::timelocal(1,2,3,4,5,88),
+ 'timelocal in timelocal.pl');
}