Commit | Line | Data |
2da668d2 |
1 | #!perl -w |
2 | |
3 | use strict; |
4 | |
5 | use Config; |
6 | use POSIX; |
439787ad |
7 | use Test::More tests => 9; |
2da668d2 |
8 | |
31b629d6 |
9 | # go to UTC to avoid DST issues around the world when testing. SUS3 says that |
10 | # null should get you UTC, but some environments want the explicit names. |
11 | # Those with a working tzset() should be able to use the TZ below. |
12 | $ENV{TZ} = "UTC0UTC"; |
2da668d2 |
13 | |
14 | SKIP: { |
15 | # It looks like POSIX.xs claims that only VMS and Mac OS traditional |
31b629d6 |
16 | # don't have tzset(). Win32 works to call the function, but it doesn't |
17 | # actually do anything. Cygwin works in some places, but not others. The |
18 | # other Win32's below are guesses. |
2da668d2 |
19 | skip "No tzset()", 2 |
31b629d6 |
20 | if $^O eq "MacOS" || $^O eq "VMS" || $^O eq "cygwin" || $^O eq "djgpp" || |
21 | $^O eq "MSWin32" || $^O eq "dos" || $^O eq "interix"; |
2da668d2 |
22 | tzset(); |
23 | my @tzname = tzname(); |
24 | like($tzname[0], qr/[GMT|UTC]/i, "tzset() to GMT/UTC"); |
6f3614c8 |
25 | SKIP: { |
26 | skip "Mac OS X/Darwin doesn't handle this", 1 if $^O =~ /darwin/i; |
27 | like($tzname[1], qr/[GMT|UTC]/i, "The whole year?"); |
28 | } |
2da668d2 |
29 | } |
30 | |
31 | # asctime and ctime...Let's stay below INT_MAX for 32-bits and |
32 | # positive for some picky systems. |
33 | |
34 | is(asctime(localtime(0)), ctime(0), "asctime() and ctime() at zero"); |
35 | is(asctime(localtime(12345678)), ctime(12345678), "asctime() and ctime() at 12345678"); |
36 | |
37 | # Careful! strftime() is locale sensative. Let's take care of that |
34dd738f |
38 | my $orig_loc = setlocale(LC_TIME, "C") || die "Cannot setlocale() to C: $!"; |
39 | if ($^O eq "MSWin32") { |
0be3c6f7 |
40 | is(ctime(0), strftime("%a %b %d %H:%M:%S %Y\n", localtime(0)), |
34dd738f |
41 | "get ctime() equal to strftime()"); |
42 | } else { |
43 | is(ctime(0), strftime("%a %b %e %H:%M:%S %Y\n", localtime(0)), |
2da668d2 |
44 | "get ctime() equal to strftime()"); |
2da668d2 |
45 | } |
34dd738f |
46 | setlocale(LC_TIME, $orig_loc) || die "Cannot setlocale() back to orig: $!"; |
2da668d2 |
47 | |
439787ad |
48 | # clock() seems to have different definitions of what it does between POSIX |
49 | # and BSD. Cygwin, Win32, and Linux lean the BSD way. So, the tests just |
50 | # check the basics. |
2da668d2 |
51 | like(clock(), qr/\d*/, "clock() returns a numeric value"); |
439787ad |
52 | ok(clock() >= 0, "...and it returns something >= 0"); |
2da668d2 |
53 | |
54 | SKIP: { |
55 | skip "No difftime()", 1 if $Config{d_difftime} ne 'define'; |
56 | is(difftime(2, 1), 1, "difftime()"); |
57 | } |
58 | |
59 | SKIP: { |
60 | skip "No mktime()", 1 if $Config{d_mktime} ne 'define'; |
61 | my $time = time(); |
62 | is(mktime(localtime($time)), $time, "mktime()"); |
63 | } |