11 ($beguser,$begsys) = times;
15 while (($now = time) == $beg) { sleep 1 }
17 ok($now > $beg && $now - $beg < 10, 'very basic time test');
19 for ($i = 0; $i < 1_000_000; $i++) {
20 for my $j (1..100) {}; # burn some user cycles
21 ($nowuser, $nowsys) = times;
22 $i = 2_000_000 if $nowuser > $beguser && ( $nowsys >= $begsys ||
23 (!$nowsys && !$begsys));
24 last if time - $beg > 20;
27 ok($i >= 2_000_000, 'very basic times test');
29 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($beg);
30 ($xsec,$foo) = localtime($now);
33 isnt($sec, $xsec), 'localtime() list context';
34 ok $mday, ' month day';
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})$
41 'localtime(), scalar context'
45 # This conditional of "No tzset()" is stolen from ext/POSIX/t/time.t
47 if $^O eq "VMS" || $^O eq "cygwin" ||
48 $^O eq "djgpp" || $^O eq "MSWin32" || $^O eq "dos" ||
51 # check that localtime respects changes to $ENV{TZ}
53 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($beg);
55 ($sec,$min,$hour2,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($beg);
56 ok($hour != $hour2, 'changes to $ENV{TZ} respected');
60 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($beg);
61 ($xsec,$foo) = localtime($now);
63 isnt($sec, $xsec), 'gmtime() list conext';
64 ok $mday, ' month day';
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');
72 # This could be stricter.
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})$
77 'gmtime(), scalar context'
82 # Test gmtime over a range of times.
84 # The range should be limited only by the 53-bit mantissa of an IEEE double (or
85 # whatever kind of double you've got). Here we just prove that we're comfortably
86 # beyond the range possible with 32-bit time_t.
88 # time_t gmtime list scalar
89 -2**35 => [52, 13, 20, 7, 2, -1019, 5, 65, 0, "Fri Mar 7 20:13:52 881"],
90 -2**32 => [44, 31, 17, 24, 10, -67, 0, 327, 0, "Sun Nov 24 17:31:44 1833"],
91 -2**31 => [52, 45, 20, 13, 11, 1, 5, 346, 0, "Fri Dec 13 20:45:52 1901"],
92 -1 => [59, 59, 23, 31, 11, 69, 3, 364, 0, "Wed Dec 31 23:59:59 1969"],
93 0 => [0, 0, 0, 1, 0, 70, 4, 0, 0, "Thu Jan 1 00:00:00 1970"],
94 1 => [1, 0, 0, 1, 0, 70, 4, 0, 0, "Thu Jan 1 00:00:01 1970"],
95 2**30 => [4, 37, 13, 10, 0, 104, 6, 9, 0, "Sat Jan 10 13:37:04 2004"],
96 2**31 => [8, 14, 3, 19, 0, 138, 2, 18, 0, "Tue Jan 19 03:14:08 2038"],
97 2**32 => [16, 28, 6, 7, 1, 206, 0, 37, 0, "Sun Feb 7 06:28:16 2106"],
98 2**39 => [8, 18, 12, 25, 0, 17491, 2, 24, 0, "Tue Jan 25 12:18:08 19391"],
101 for my $time (keys %tests) {
102 my @expected = @{$tests{$time}};
103 my $scalar = pop @expected;
105 ok eq_array([gmtime($time)], \@expected), "gmtime($time) list context";
106 is scalar gmtime($time), $scalar, " scalar";
113 # We pick times which fall in the middle of a month, so the month and year should be
114 # the same regardless of the time zone.
116 # time_t month, year, scalar
117 -8589934592 => [9, -203, qr/Oct \d+ .* 1697$/],
118 -1296000 => [11, 69, qr/Dec \d+ .* 1969$/],
119 1296000 => [0, 70, qr/Jan \d+ .* 1970$/],
120 5000000000 => [5, 228, qr/Jun \d+ .* 2128$/],
121 1163500000 => [10, 106, qr/Nov \d+ .* 2006$/],
124 for my $time (keys %tests) {
125 my @expected = @{$tests{$time}};
126 my $scalar = pop @expected;
128 my @time = (localtime($time))[4,5];
129 ok( eq_array(\@time, \@expected), "localtime($time) list context" )
131 like scalar localtime($time), $scalar, " scalar";
135 # Test floating point args
138 $SIG{__WARN__} = sub { die @_; };
141 is($@, '', 'Ignore fractional time');
143 $SIG{__WARN__} = sub { die @_; };
146 is($@, '', 'Ignore fractional time');