RE: Untested libraries update
[p5sagit/p5-mst-13.2.git] / lib / Time / Local.t
CommitLineData
1a3850a5 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
1a3850a5 6}
7
8use Time::Local;
9
10# Set up time values to test
11@time =
12 (
13 #year,mon,day,hour,min,sec
9b599b2a 14 [1970, 1, 2, 00, 00, 00],
1a3850a5 15 [1980, 2, 28, 12, 00, 00],
16 [1980, 2, 29, 12, 00, 00],
17 [1999, 12, 31, 23, 59, 59],
18 [2000, 1, 1, 00, 00, 00],
19 [2010, 10, 12, 14, 13, 12],
20 );
21
61bb5906 22# use vmsish 'time' makes for oddness around the Unix epoch
23if ($^O eq 'VMS') { $time[0][2]++ }
24
1a3850a5 25print "1..", @time * 2 + 5, "\n";
26
27$count = 1;
28for (@time) {
29 my($year, $mon, $mday, $hour, $min, $sec) = @$_;
30 $year -= 1900;
31 $mon --;
32 my $time = timelocal($sec,$min,$hour,$mday,$mon,$year);
33 # print scalar(localtime($time)), "\n";
34 my($s,$m,$h,$D,$M,$Y) = localtime($time);
35
36 if ($s == $sec &&
37 $m == $min &&
38 $h == $hour &&
39 $D == $mday &&
40 $M == $mon &&
41 $Y == $year
42 ) {
43 print "ok $count\n";
44 } else {
45 print "not ok $count\n";
46 }
47 $count++;
48
49 # Test gmtime function
50 $time = timegm($sec,$min,$hour,$mday,$mon,$year);
51 ($s,$m,$h,$D,$M,$Y) = gmtime($time);
52
53 if ($s == $sec &&
54 $m == $min &&
55 $h == $hour &&
56 $D == $mday &&
57 $M == $mon &&
58 $Y == $year
59 ) {
60 print "ok $count\n";
61 } else {
62 print "not ok $count\n";
63 }
64 $count++;
65}
66
67#print "Testing that the differences between a few dates makes sence...\n";
68
69timelocal(0,0,1,1,0,90) - timelocal(0,0,0,1,0,90) == 3600
70 or print "not ";
71print "ok ", $count++, "\n";
72
73timelocal(1,2,3,1,0,100) - timelocal(1,2,3,31,11,99) == 24 * 3600
74 or print "not ";
75print "ok ", $count++, "\n";
76
77# Diff beween Jan 1, 1970 and Mar 1, 1970 = (31 + 28 = 59 days)
78timegm(0,0,0, 1, 2, 70) - timegm(0,0,0, 1, 0, 70) == 59 * 24 * 3600
79 or print "not ";
80print "ok ", $count++, "\n";
81
82
83#print "Testing timelocal.pl module too...\n";
84package test;
85require 'timelocal.pl';
86timegm(0,0,0,1,0,70) == main::timegm(0,0,0,1,0,70) or print "not ";
87print "ok ", $main::count++, "\n";
88
89timelocal(1,2,3,4,5,78) == main::timelocal(1,2,3,4,5,78) or print "not ";
90print "ok ", $main::count++, "\n";