10 # Set up time values to test
13 #year,mon,day,hour,min,sec
14 [1970, 1, 2, 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 [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
28 # use vmsish 'time' makes for oddness around the Unix epoch
29 if ($^O eq 'VMS') { $time[0][2]++ }
31 print "1..", @time * 2 + 6, "\n";
35 my($year, $mon, $mday, $hour, $min, $sec) = @$_;
38 if ($^O eq 'vos' && $count == 1) {
39 print "ok $count -- skipping 1970 test on VOS.\n";
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);
54 print "not ok $count\n";
59 # Test gmtime function
60 if ($^O eq 'vos' && $count == 2) {
61 print "ok $count -- skipping 1970 test on VOS.\n";
63 $time = timegm($sec,$min,$hour,$mday,$mon,$year);
64 ($s,$m,$h,$D,$M,$Y) = gmtime($time);
75 print "not ok $count\n";
81 #print "Testing that the differences between a few dates makes sense...\n";
83 timelocal(0,0,1,1,0,90) - timelocal(0,0,0,1,0,90) == 3600
85 print "ok ", $count++, "\n";
87 timelocal(1,2,3,1,0,100) - timelocal(1,2,3,31,11,99) == 24 * 3600
89 print "ok ", $count++, "\n";
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
94 print "ok ", $count++, "\n";
97 # At a DST transition, the clock skips forward, eg from 01:59:59 to
98 # 03:00:00. In this case, 02:00:00 is an invalid time, and should be
99 # treated like 03:00:00 rather than 01:00:00 - negative zone offsets used
103 my $hour = (localtime(timelocal(0, 0, 2, 7, 3, 102)))[2];
104 # testers in US/Pacific should get 3,
105 # other testers should get 2
106 print "not " unless $hour == 2 || $hour == 3;
107 print "ok ", $main::count++, "\n";
111 #print "Testing timelocal.pl module too...\n";
113 require 'timelocal.pl';
114 timegm(0,0,0,1,0,80) == main::timegm(0,0,0,1,0,80) or print "not ";
115 print "ok ", $main::count++, "\n";
117 timelocal(1,2,3,4,5,88) == main::timelocal(1,2,3,4,5,88) or print "not ";
118 print "ok ", $main::count++, "\n";