Commit | Line | Data |
1a3850a5 |
1 | #!./perl |
2 | |
3 | BEGIN { |
1c41b6a4 |
4 | if ($ENV{PERL_CORE}){ |
5 | chdir('t') if -d 't'; |
6 | @INC = ('.', '../lib'); |
7 | } |
1a3850a5 |
8 | } |
9 | |
10 | use Time::Local; |
11 | |
12 | # Set up time values to test |
13 | @time = |
14 | ( |
15 | #year,mon,day,hour,min,sec |
9b599b2a |
16 | [1970, 1, 2, 00, 00, 00], |
1a3850a5 |
17 | [1980, 2, 28, 12, 00, 00], |
18 | [1980, 2, 29, 12, 00, 00], |
19 | [1999, 12, 31, 23, 59, 59], |
20 | [2000, 1, 1, 00, 00, 00], |
21 | [2010, 10, 12, 14, 13, 12], |
78063c05 |
22 | [2020, 2, 29, 12, 59, 59], |
23 | [2030, 7, 4, 17, 07, 06], |
24 | # The following test fails on a surprising number of systems |
25 | # so it is commented out. The end of the Epoch for a 32-bit signed |
26 | # implementation of time_t should be Jan 19, 2038 03:14:07 UTC. |
27 | # [2038, 1, 17, 23, 59, 59], # last full day in any tz |
1a3850a5 |
28 | ); |
29 | |
61bb5906 |
30 | # use vmsish 'time' makes for oddness around the Unix epoch |
31 | if ($^O eq 'VMS') { $time[0][2]++ } |
32 | |
1c41b6a4 |
33 | my $tests = @time * 2 + 4; |
34 | $tests += 2 if $ENV{PERL_CORE}; |
35 | |
36 | print "1..$tests\n"; |
1a3850a5 |
37 | |
38 | $count = 1; |
39 | for (@time) { |
40 | my($year, $mon, $mday, $hour, $min, $sec) = @$_; |
41 | $year -= 1900; |
42 | $mon --; |
78063c05 |
43 | if ($^O eq 'vos' && $count == 1) { |
44 | print "ok $count -- skipping 1970 test on VOS.\n"; |
1a3850a5 |
45 | } else { |
78063c05 |
46 | my $time = timelocal($sec,$min,$hour,$mday,$mon,$year); |
47 | # print scalar(localtime($time)), "\n"; |
48 | my($s,$m,$h,$D,$M,$Y) = localtime($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 | } |
1a3850a5 |
61 | } |
62 | $count++; |
63 | |
64 | # Test gmtime function |
78063c05 |
65 | if ($^O eq 'vos' && $count == 2) { |
66 | print "ok $count -- skipping 1970 test on VOS.\n"; |
1a3850a5 |
67 | } else { |
78063c05 |
68 | $time = timegm($sec,$min,$hour,$mday,$mon,$year); |
69 | ($s,$m,$h,$D,$M,$Y) = gmtime($time); |
70 | |
71 | if ($s == $sec && |
72 | $m == $min && |
73 | $h == $hour && |
74 | $D == $mday && |
75 | $M == $mon && |
76 | $Y == $year |
77 | ) { |
78 | print "ok $count\n"; |
79 | } else { |
80 | print "not ok $count\n"; |
81 | } |
1a3850a5 |
82 | } |
83 | $count++; |
84 | } |
85 | |
78063c05 |
86 | #print "Testing that the differences between a few dates makes sense...\n"; |
1a3850a5 |
87 | |
88 | timelocal(0,0,1,1,0,90) - timelocal(0,0,0,1,0,90) == 3600 |
89 | or print "not "; |
90 | print "ok ", $count++, "\n"; |
91 | |
92 | timelocal(1,2,3,1,0,100) - timelocal(1,2,3,31,11,99) == 24 * 3600 |
93 | or print "not "; |
94 | print "ok ", $count++, "\n"; |
95 | |
78063c05 |
96 | # Diff beween Jan 1, 1980 and Mar 1, 1980 = (31 + 29 = 60 days) |
97 | timegm(0,0,0, 1, 2, 80) - timegm(0,0,0, 1, 0, 80) == 60 * 24 * 3600 |
1a3850a5 |
98 | or print "not "; |
99 | print "ok ", $count++, "\n"; |
100 | |
13ef5feb |
101 | # bugid #19393 |
102 | # At a DST transition, the clock skips forward, eg from 01:59:59 to |
103 | # 03:00:00. In this case, 02:00:00 is an invalid time, and should be |
104 | # treated like 03:00:00 rather than 01:00:00 - negative zone offsets used |
105 | # to do the latter |
13ef5feb |
106 | { |
107 | my $hour = (localtime(timelocal(0, 0, 2, 7, 3, 102)))[2]; |
108 | # testers in US/Pacific should get 3, |
109 | # other testers should get 2 |
110 | print "not " unless $hour == 2 || $hour == 3; |
111 | print "ok ", $main::count++, "\n"; |
112 | } |
113 | |
1c41b6a4 |
114 | if ($ENV{PERL_CORE}) { |
115 | #print "Testing timelocal.pl module too...\n"; |
116 | package test; |
117 | require 'timelocal.pl'; |
118 | timegm(0,0,0,1,0,80) == main::timegm(0,0,0,1,0,80) or print "not "; |
119 | print "ok ", $main::count++, "\n"; |
1a3850a5 |
120 | |
1c41b6a4 |
121 | timelocal(1,2,3,4,5,88) == main::timelocal(1,2,3,4,5,88) or print "not "; |
122 | print "ok ", $main::count++, "\n"; |
123 | } |