Commit | Line | Data |
8d063cd8 |
1 | #!./perl |
2 | |
a8c5b3cc |
3 | $does_gmtime = gmtime(time); |
26575770 |
4 | |
a8c5b3cc |
5 | BEGIN { |
6 | chdir 't' if -d 't'; |
7 | @INC = '../lib'; |
8 | require './test.pl'; |
26575770 |
9 | } |
10 | |
a8c5b3cc |
11 | plan tests => 8; |
8d063cd8 |
12 | |
13 | ($beguser,$begsys) = times; |
14 | |
15 | $beg = time; |
16 | |
463ee0b2 |
17 | while (($now = time) == $beg) { sleep 1 } |
8d063cd8 |
18 | |
26575770 |
19 | ok($now > $beg && $now - $beg < 10, 'very basic time test'); |
8d063cd8 |
20 | |
5f80d426 |
21 | for ($i = 0; $i < 1_000_000; $i++) { |
584ba4d5 |
22 | for my $j (1..100) {}; # burn some user cycles |
8d063cd8 |
23 | ($nowuser, $nowsys) = times; |
5f80d426 |
24 | $i = 2_000_000 if $nowuser > $beguser && ( $nowsys >= $begsys || |
a0d0e21e |
25 | (!$nowsys && !$begsys)); |
8d063cd8 |
26 | last if time - $beg > 20; |
27 | } |
28 | |
5f80d426 |
29 | ok($i >= 2_000_000, 'very basic times test'); |
8d063cd8 |
30 | |
31 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($beg); |
32 | ($xsec,$foo) = localtime($now); |
33 | $localyday = $yday; |
34 | |
26575770 |
35 | ok($sec != $xsec && $mday && $year, 'localtime() list context'); |
36 | |
37 | ok(localtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ] |
38 | (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ] |
39 | ([ \d]\d)\ (\d\d):(\d\d):(\d\d)\ (\d{4})$ |
40 | /x, |
41 | 'localtime(), scalar context' |
42 | ); |
8d063cd8 |
43 | |
a8c5b3cc |
44 | SKIP: { |
45 | # This conditional of "No tzset()" is stolen from ext/POSIX/t/time.t |
46 | skip "No tzset()", 1 |
47 | if $^O eq "MacOS" || $^O eq "VMS" || $^O eq "cygwin" || |
48 | $^O eq "djgpp" || $^O eq "MSWin32" || $^O eq "dos" || |
49 | $^O eq "interix"; |
50 | |
8572b25d |
51 | # check that localtime respects changes to $ENV{TZ} |
52 | $ENV{TZ} = "GMT-5"; |
53 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($beg); |
54 | $ENV{TZ} = "GMT+5"; |
55 | ($sec,$min,$hour2,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($beg); |
56 | ok($hour != $hour2, 'changes to $ENV{TZ} respected'); |
a8c5b3cc |
57 | } |
8572b25d |
58 | |
a8c5b3cc |
59 | SKIP: { |
60 | skip "No gmtime()", 3 unless $does_gmtime; |
a0d0e21e |
61 | |
8d063cd8 |
62 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($beg); |
63 | ($xsec,$foo) = localtime($now); |
64 | |
26575770 |
65 | ok($sec != $xsec && $mday && $year, 'gmtime() list context'); |
66 | |
67 | my $day_diff = $localyday - $yday; |
68 | ok( grep({ $day_diff == $_ } (0, 1, -1, 364, 365, -364, -365)), |
69 | 'gmtime() and localtime() agree what day of year'); |
8d063cd8 |
70 | |
f5a29b03 |
71 | |
72 | # This could be stricter. |
26575770 |
73 | ok(gmtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ] |
74 | (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ] |
75 | ([ \d]\d)\ (\d\d):(\d\d):(\d\d)\ (\d{4})$ |
76 | /x, |
77 | 'gmtime(), scalar context' |
78 | ); |
a8c5b3cc |
79 | } |