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