summaryrefslogtreecommitdiff
path: root/lib/Time
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2001-06-18 04:17:15 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2001-06-18 04:17:15 +0000
commitb695f709e8a342e35e482b0437eb6cdacdc58b6b (patch)
tree2d16192636e6ba806ff7a907f682c74f7705a920 /lib/Time
parentd780cd7a0195e946e636d3ee546f6ef4f21d6acc (diff)
downloadperl-b695f709e8a342e35e482b0437eb6cdacdc58b6b.tar.gz
The Grand Trek: move the *.t files from t/ to lib/ and ext/.
No doubt I made some mistakes like missed some files or misnamed some files. The naming rules were more or less: (1) if the module is from CPAN, follows its ways, be it t/*.t or test.pl. (2) otherwise if there are multiple tests for a module put them in a t/ (3) otherwise if there's only one test put it in Module.t (4) helper files go to module/ (locale, strict, warnings) (5) use longer filenames now that we can (but e.g. the compat-0.6.t and the Text::Balanced test files still were renamed to be more civil against the 8.3 people) installperl was updated appropriately not to install the *.t files or the help files from under lib. TODO: some helper files still remain under t/ that could follow their 'masters'. UPDATE: On second thoughts, why should they. They can continue to live under t/lib, and in fact the locale/strict/warnings helpers that were moved could be moved back. This way the amount of non-installable stuff under lib/ stays smaller. p4raw-id: //depot/perl@10676
Diffstat (limited to 'lib/Time')
-rwxr-xr-xlib/Time/Local.t90
-rw-r--r--lib/Time/gmtime.t57
-rw-r--r--lib/Time/localtime.t57
3 files changed, 204 insertions, 0 deletions
diff --git a/lib/Time/Local.t b/lib/Time/Local.t
new file mode 100755
index 0000000000..100e0768aa
--- /dev/null
+++ b/lib/Time/Local.t
@@ -0,0 +1,90 @@
+#!./perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+}
+
+use Time::Local;
+
+# Set up time values to test
+@time =
+ (
+ #year,mon,day,hour,min,sec
+ [1970, 1, 2, 00, 00, 00],
+ [1980, 2, 28, 12, 00, 00],
+ [1980, 2, 29, 12, 00, 00],
+ [1999, 12, 31, 23, 59, 59],
+ [2000, 1, 1, 00, 00, 00],
+ [2010, 10, 12, 14, 13, 12],
+ );
+
+# use vmsish 'time' makes for oddness around the Unix epoch
+if ($^O eq 'VMS') { $time[0][2]++ }
+
+print "1..", @time * 2 + 5, "\n";
+
+$count = 1;
+for (@time) {
+ my($year, $mon, $mday, $hour, $min, $sec) = @$_;
+ $year -= 1900;
+ $mon --;
+ 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";
+ }
+ $count++;
+
+ # Test gmtime function
+ $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";
+ }
+ $count++;
+}
+
+#print "Testing that the differences between a few dates makes sence...\n";
+
+timelocal(0,0,1,1,0,90) - timelocal(0,0,0,1,0,90) == 3600
+ or print "not ";
+print "ok ", $count++, "\n";
+
+timelocal(1,2,3,1,0,100) - timelocal(1,2,3,31,11,99) == 24 * 3600
+ or print "not ";
+print "ok ", $count++, "\n";
+
+# Diff beween Jan 1, 1970 and Mar 1, 1970 = (31 + 28 = 59 days)
+timegm(0,0,0, 1, 2, 70) - timegm(0,0,0, 1, 0, 70) == 59 * 24 * 3600
+ or print "not ";
+print "ok ", $count++, "\n";
+
+
+#print "Testing timelocal.pl module too...\n";
+package test;
+require 'timelocal.pl';
+timegm(0,0,0,1,0,70) == main::timegm(0,0,0,1,0,70) or print "not ";
+print "ok ", $main::count++, "\n";
+
+timelocal(1,2,3,4,5,78) == main::timelocal(1,2,3,4,5,78) or print "not ";
+print "ok ", $main::count++, "\n";
diff --git a/lib/Time/gmtime.t b/lib/Time/gmtime.t
new file mode 100644
index 0000000000..853ec3b6e3
--- /dev/null
+++ b/lib/Time/gmtime.t
@@ -0,0 +1,57 @@
+#!./perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+}
+
+BEGIN {
+ our $hasgm;
+ eval { my $n = gmtime 0 };
+ $hasgm = 1 unless $@ && $@ =~ /unimplemented/;
+ unless ($hasgm) { print "1..0 # Skip: no gmtime\n"; exit 0 }
+}
+
+BEGIN {
+ our @gmtime = gmtime 0; # This is the function gmtime.
+ unless (@gmtime) { print "1..0 # Skip: gmtime failed\n"; exit 0 }
+}
+
+print "1..10\n";
+
+use Time::gmtime;
+
+print "ok 1\n";
+
+my $gmtime = gmtime 0 ; # This is the OO gmtime.
+
+print "not " unless $gmtime->sec == $gmtime[0];
+print "ok 2\n";
+
+print "not " unless $gmtime->min == $gmtime[1];
+print "ok 3\n";
+
+print "not " unless $gmtime->hour == $gmtime[2];
+print "ok 4\n";
+
+print "not " unless $gmtime->mday == $gmtime[3];
+print "ok 5\n";
+
+print "not " unless $gmtime->mon == $gmtime[4];
+print "ok 6\n";
+
+print "not " unless $gmtime->year == $gmtime[5];
+print "ok 7\n";
+
+print "not " unless $gmtime->wday == $gmtime[6];
+print "ok 8\n";
+
+print "not " unless $gmtime->yday == $gmtime[7];
+print "ok 9\n";
+
+print "not " unless $gmtime->isdst == $gmtime[8];
+print "ok 10\n";
+
+
+
+
diff --git a/lib/Time/localtime.t b/lib/Time/localtime.t
new file mode 100644
index 0000000000..357615c780
--- /dev/null
+++ b/lib/Time/localtime.t
@@ -0,0 +1,57 @@
+#!./perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+}
+
+BEGIN {
+ our $haslocal;
+ eval { my $n = localtime 0 };
+ $haslocal = 1 unless $@ && $@ =~ /unimplemented/;
+ unless ($haslocal) { print "1..0 # Skip: no localtime\n"; exit 0 }
+}
+
+BEGIN {
+ our @localtime = localtime 0; # This is the function localtime.
+ unless (@localtime) { print "1..0 # Skip: localtime failed\n"; exit 0 }
+}
+
+print "1..10\n";
+
+use Time::localtime;
+
+print "ok 1\n";
+
+my $localtime = localtime 0 ; # This is the OO localtime.
+
+print "not " unless $localtime->sec == $localtime[0];
+print "ok 2\n";
+
+print "not " unless $localtime->min == $localtime[1];
+print "ok 3\n";
+
+print "not " unless $localtime->hour == $localtime[2];
+print "ok 4\n";
+
+print "not " unless $localtime->mday == $localtime[3];
+print "ok 5\n";
+
+print "not " unless $localtime->mon == $localtime[4];
+print "ok 6\n";
+
+print "not " unless $localtime->year == $localtime[5];
+print "ok 7\n";
+
+print "not " unless $localtime->wday == $localtime[6];
+print "ok 8\n";
+
+print "not " unless $localtime->yday == $localtime[7];
+print "ok 9\n";
+
+print "not " unless $localtime->isdst == $localtime[8];
+print "ok 10\n";
+
+
+
+