This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
There *is* a month called October.
[perl5.git] / t / op / time.t
CommitLineData
8d063cd8
LW
1#!./perl
2
79072805 3# $RCSfile: time.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:32 $
8d063cd8 4
f5a29b03 5if ($does_gmtime = gmtime(time)) { print "1..6\n" }
a0d0e21e 6else { print "1..3\n" }
8d063cd8
LW
7
8($beguser,$begsys) = times;
9
10$beg = time;
11
463ee0b2 12while (($now = time) == $beg) { sleep 1 }
8d063cd8
LW
13
14if ($now > $beg && $now - $beg < 10){print "ok 1\n";} else {print "not ok 1\n";}
15
16for ($i = 0; $i < 100000; $i++) {
17 ($nowuser, $nowsys) = times;
a0d0e21e
LW
18 $i = 200000 if $nowuser > $beguser && ( $nowsys > $begsys ||
19 (!$nowsys && !$begsys));
8d063cd8
LW
20 last if time - $beg > 20;
21}
22
23if ($i >= 200000) {print "ok 2\n";} else {print "not ok 2\n";}
24
25($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($beg);
26($xsec,$foo) = localtime($now);
27$localyday = $yday;
28
135863df 29if ($sec != $xsec && $mday && $year)
8d063cd8
LW
30 {print "ok 3\n";}
31else
32 {print "not ok 3\n";}
33
a0d0e21e
LW
34exit 0 unless $does_gmtime;
35
8d063cd8
LW
36($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($beg);
37($xsec,$foo) = localtime($now);
38
135863df 39if ($sec != $xsec && $mday && $year)
8d063cd8
LW
40 {print "ok 4\n";}
41else
42 {print "not ok 4\n";}
43
c07a80fd 44if (index(" :0:1:-1:364:365:-364:-365:",':' . ($localyday - $yday) . ':') > 0)
8d063cd8
LW
45 {print "ok 5\n";}
46else
47 {print "not ok 5\n";}
f5a29b03
RB
48
49# This could be stricter.
b3656ec3 50if (gmtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([ \d]\d) (\d\d):(\d\d):(\d\d) (\d\d\d\d)$/)
f5a29b03
RB
51 {print "ok 6\n";}
52else
53 {print "not ok 6\n";}