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