Commit | Line | Data |
8d063cd8 |
1 | #!./perl |
2 | |
79072805 |
3 | # $RCSfile: time.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:32 $ |
8d063cd8 |
4 | |
26575770 |
5 | if ( $does_gmtime = gmtime(time) ) { |
6 | print "1..7\n" |
7 | } |
8 | else { |
9 | print "1..4\n" |
10 | } |
11 | |
12 | |
13 | my $test = 1; |
14 | sub ok ($$) { |
15 | my($ok, $name) = @_; |
16 | |
17 | # You have to do it this way or VMS will get confused. |
18 | print $ok ? "ok $test - $name\n" : "not ok $test - $name\n"; |
19 | |
20 | printf "# Failed test at line %d\n", (caller)[2] unless $ok; |
21 | |
22 | $test++; |
23 | return $ok; |
24 | } |
25 | |
8d063cd8 |
26 | |
27 | ($beguser,$begsys) = times; |
28 | |
29 | $beg = time; |
30 | |
463ee0b2 |
31 | while (($now = time) == $beg) { sleep 1 } |
8d063cd8 |
32 | |
26575770 |
33 | ok($now > $beg && $now - $beg < 10, 'very basic time test'); |
8d063cd8 |
34 | |
35 | for ($i = 0; $i < 100000; $i++) { |
36 | ($nowuser, $nowsys) = times; |
ab2f3c4a |
37 | $i = 200000 if $nowuser > $beguser && ( $nowsys >= $begsys || |
a0d0e21e |
38 | (!$nowsys && !$begsys)); |
8d063cd8 |
39 | last if time - $beg > 20; |
40 | } |
41 | |
26575770 |
42 | ok($i >= 200000, 'very basic times test'); |
8d063cd8 |
43 | |
44 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($beg); |
45 | ($xsec,$foo) = localtime($now); |
46 | $localyday = $yday; |
47 | |
26575770 |
48 | ok($sec != $xsec && $mday && $year, 'localtime() list context'); |
49 | |
50 | ok(localtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ] |
51 | (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ] |
52 | ([ \d]\d)\ (\d\d):(\d\d):(\d\d)\ (\d{4})$ |
53 | /x, |
54 | 'localtime(), scalar context' |
55 | ); |
8d063cd8 |
56 | |
a0d0e21e |
57 | exit 0 unless $does_gmtime; |
58 | |
8d063cd8 |
59 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($beg); |
60 | ($xsec,$foo) = localtime($now); |
61 | |
26575770 |
62 | ok($sec != $xsec && $mday && $year, 'gmtime() list context'); |
63 | |
64 | my $day_diff = $localyday - $yday; |
65 | ok( grep({ $day_diff == $_ } (0, 1, -1, 364, 365, -364, -365)), |
66 | 'gmtime() and localtime() agree what day of year'); |
8d063cd8 |
67 | |
f5a29b03 |
68 | |
69 | # This could be stricter. |
26575770 |
70 | ok(gmtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ] |
71 | (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ] |
72 | ([ \d]\d)\ (\d\d):(\d\d):(\d\d)\ (\d{4})$ |
73 | /x, |
74 | 'gmtime(), scalar context' |
75 | ); |