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