Commit | Line | Data |
1a3850a5 |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
20822f61 |
5 | @INC = '../lib'; |
1a3850a5 |
6 | } |
7 | |
8 | use 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], |
371d6415 |
20 | [2020, 2, 29, 12, 59, 59], |
21 | [2030, 7, 4, 17, 07, 06], |
22 | [2038, 1, 17, 23, 59, 59], # last full day in any tz |
1a3850a5 |
23 | ); |
24 | |
61bb5906 |
25 | # use vmsish 'time' makes for oddness around the Unix epoch |
26 | if ($^O eq 'VMS') { $time[0][2]++ } |
27 | |
1a3850a5 |
28 | print "1..", @time * 2 + 5, "\n"; |
29 | |
30 | $count = 1; |
31 | for (@time) { |
32 | my($year, $mon, $mday, $hour, $min, $sec) = @$_; |
33 | $year -= 1900; |
34 | $mon --; |
371d6415 |
35 | if ($^O eq 'vos' && $count == 1) { |
36 | print "ok $count -- skipping 1970 test on VOS.\n"; |
1a3850a5 |
37 | } else { |
371d6415 |
38 | my $time = timelocal($sec,$min,$hour,$mday,$mon,$year); |
39 | # print scalar(localtime($time)), "\n"; |
40 | my($s,$m,$h,$D,$M,$Y) = localtime($time); |
41 | |
42 | if ($s == $sec && |
43 | $m == $min && |
44 | $h == $hour && |
45 | $D == $mday && |
46 | $M == $mon && |
47 | $Y == $year |
48 | ) { |
49 | print "ok $count\n"; |
50 | } else { |
51 | print "not ok $count\n"; |
52 | } |
1a3850a5 |
53 | } |
54 | $count++; |
55 | |
56 | # Test gmtime function |
371d6415 |
57 | if ($^O eq 'vos' && $count == 2) { |
58 | print "ok $count -- skipping 1970 test on VOS.\n"; |
1a3850a5 |
59 | } else { |
371d6415 |
60 | $time = timegm($sec,$min,$hour,$mday,$mon,$year); |
61 | ($s,$m,$h,$D,$M,$Y) = gmtime($time); |
62 | |
63 | if ($s == $sec && |
64 | $m == $min && |
65 | $h == $hour && |
66 | $D == $mday && |
67 | $M == $mon && |
68 | $Y == $year |
69 | ) { |
70 | print "ok $count\n"; |
71 | } else { |
72 | print "not ok $count\n"; |
73 | } |
1a3850a5 |
74 | } |
75 | $count++; |
76 | } |
77 | |
371d6415 |
78 | #print "Testing that the differences between a few dates makes sense...\n"; |
1a3850a5 |
79 | |
80 | timelocal(0,0,1,1,0,90) - timelocal(0,0,0,1,0,90) == 3600 |
81 | or print "not "; |
82 | print "ok ", $count++, "\n"; |
83 | |
84 | timelocal(1,2,3,1,0,100) - timelocal(1,2,3,31,11,99) == 24 * 3600 |
85 | or print "not "; |
86 | print "ok ", $count++, "\n"; |
87 | |
371d6415 |
88 | # Diff beween Jan 1, 1980 and Mar 1, 1980 = (31 + 29 = 60 days) |
89 | timegm(0,0,0, 1, 2, 80) - timegm(0,0,0, 1, 0, 80) == 60 * 24 * 3600 |
1a3850a5 |
90 | or print "not "; |
91 | print "ok ", $count++, "\n"; |
92 | |
93 | |
94 | #print "Testing timelocal.pl module too...\n"; |
95 | package test; |
96 | require 'timelocal.pl'; |
371d6415 |
97 | timegm(0,0,0,1,0,80) == main::timegm(0,0,0,1,0,80) or print "not "; |
1a3850a5 |
98 | print "ok ", $main::count++, "\n"; |
99 | |
371d6415 |
100 | timelocal(1,2,3,4,5,88) == main::timelocal(1,2,3,4,5,88) or print "not "; |
1a3850a5 |
101 | print "ok ", $main::count++, "\n"; |