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