Commit | Line | Data |
2da668d2 |
1 | #!perl -w |
2 | |
3 | use strict; |
4 | |
5 | use Config; |
6 | use POSIX; |
dc57de01 |
7 | use Test::More tests => 13; |
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(); |
0bcc7986 |
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; |
0bcc7986 |
27 | like($tzname[1], qr/(GMT|UTC)/i, "The whole year?"); |
6f3614c8 |
28 | } |
2da668d2 |
29 | } |
30 | |
4c34a366 |
31 | if ($^O eq "hpux" && $Config{osvers} >= 11.3) { |
32 | # HP does not support UTC0UTC and/or GMT0GMT, as they state that this is |
33 | # legal syntax but as it has no DST rule, it cannot be used. That is the |
34 | # conclusion of bug |
35 | # QXCR1000896916: Some timezone valuesfailing on 11.31 that work on 11.23 |
7faed49a |
36 | $ENV{TZ} = "UTC"; |
4c34a366 |
37 | } |
38 | |
2da668d2 |
39 | # asctime and ctime...Let's stay below INT_MAX for 32-bits and |
40 | # positive for some picky systems. |
41 | |
42 | is(asctime(localtime(0)), ctime(0), "asctime() and ctime() at zero"); |
43 | is(asctime(localtime(12345678)), ctime(12345678), "asctime() and ctime() at 12345678"); |
44 | |
45 | # Careful! strftime() is locale sensative. Let's take care of that |
34dd738f |
46 | my $orig_loc = setlocale(LC_TIME, "C") || die "Cannot setlocale() to C: $!"; |
018eeb12 |
47 | my $jan_16 = 15 * 86400; |
48 | is(ctime($jan_16), strftime("%a %b %d %H:%M:%S %Y\n", localtime($jan_16)), |
34dd738f |
49 | "get ctime() equal to strftime()"); |
28c3d5f4 |
50 | is(strftime("%Y\x{5e74}%m\x{6708}%d\x{65e5}", gmtime($jan_16)), |
dc57de01 |
51 | "1970\x{5e74}01\x{6708}16\x{65e5}", |
52 | "strftime() can handle unicode chars in the format string"); |
53 | |
54 | my $ss = chr 223; |
55 | unlike($ss, qr/\w/, 'Not internally UTF-8 encoded'); |
56 | is(ord strftime($ss, localtime), 223, 'Format string has correct character'); |
57 | unlike($ss, qr/\w/, 'Still not internally UTF-8 encoded'); |
58 | |
34dd738f |
59 | setlocale(LC_TIME, $orig_loc) || die "Cannot setlocale() back to orig: $!"; |
2da668d2 |
60 | |
439787ad |
61 | # clock() seems to have different definitions of what it does between POSIX |
62 | # and BSD. Cygwin, Win32, and Linux lean the BSD way. So, the tests just |
63 | # check the basics. |
2da668d2 |
64 | like(clock(), qr/\d*/, "clock() returns a numeric value"); |
439787ad |
65 | ok(clock() >= 0, "...and it returns something >= 0"); |
2da668d2 |
66 | |
67 | SKIP: { |
68 | skip "No difftime()", 1 if $Config{d_difftime} ne 'define'; |
69 | is(difftime(2, 1), 1, "difftime()"); |
70 | } |
71 | |
72 | SKIP: { |
73 | skip "No mktime()", 1 if $Config{d_mktime} ne 'define'; |
74 | my $time = time(); |
75 | is(mktime(localtime($time)), $time, "mktime()"); |
76 | } |