4 unshift @INC, "../../t";
5 require 'loc_tools.pl';
12 use Test::More tests => 19;
14 # go to UTC to avoid DST issues around the world when testing. SUS3 says that
15 # null should get you UTC, but some environments want the explicit names.
16 # Those with a working tzset() should be able to use the TZ below.
20 # It looks like POSIX.xs claims that only VMS and Mac OS traditional
21 # don't have tzset(). Win32 works to call the function, but it doesn't
22 # actually do anything. Cygwin works in some places, but not others. The
23 # other Win32's below are guesses.
25 if $^O eq "VMS" || $^O eq "cygwin" || $^O eq "djgpp" ||
26 $^O eq "MSWin32" || $^O eq "dos" || $^O eq "interix";
28 my @tzname = tzname();
29 like($tzname[0], qr/(GMT|UTC)/i, "tzset() to GMT/UTC");
31 skip "Mac OS X/Darwin doesn't handle this", 1 if $^O =~ /darwin/i;
32 like($tzname[1], qr/(GMT|UTC)/i, "The whole year?");
36 if ($^O eq "hpux" && $Config{osvers} >= 11.3) {
37 # HP does not support UTC0UTC and/or GMT0GMT, as they state that this is
38 # legal syntax but as it has no DST rule, it cannot be used. That is the
40 # QXCR1000896916: Some timezone valuesfailing on 11.31 that work on 11.23
44 # asctime and ctime...Let's stay below INT_MAX for 32-bits and
45 # positive for some picky systems.
47 is(asctime(CORE::localtime(0)), ctime(0), "asctime() and ctime() at zero");
48 is(asctime(POSIX::localtime(0)), ctime(0), "asctime() and ctime() at zero");
49 is(asctime(CORE::localtime(12345678)), ctime(12345678),
50 "asctime() and ctime() at 12345678");
51 is(asctime(POSIX::localtime(12345678)), ctime(12345678),
52 "asctime() and ctime() at 12345678");
54 # Careful! strftime() is locale sensitive. Let's take care of that
55 my $orig_time_loc = 'C';
56 my $orig_ctype_loc = 'C';
57 if (locales_enabled('LC_TIME')) {
58 $orig_time_loc = setlocale(LC_TIME) || die "Cannot get time locale information: $!";
59 setlocale(LC_TIME, "C") || die "Cannot setlocale() to C: $!";
61 if (locales_enabled('LC_CTYPE')) {
62 $orig_ctype_loc = setlocale(LC_CTYPE) || die "Cannot get ctype locale information: $!";
63 setlocale(LC_CTYPE, "C") || die "Cannot setlocale() to C: $!";
65 my $jan_16 = 15 * 86400;
66 is(ctime($jan_16), strftime("%a %b %d %H:%M:%S %Y\n", CORE::localtime($jan_16)),
67 "get ctime() equal to strftime()");
68 is(ctime($jan_16), strftime("%a %b %d %H:%M:%S %Y\n", POSIX::localtime($jan_16)),
69 "get ctime() equal to strftime()");
70 is(strftime("%Y\x{5e74}%m\x{6708}%d\x{65e5}", CORE::gmtime($jan_16)),
71 "1970\x{5e74}01\x{6708}16\x{65e5}",
72 "strftime() can handle unicode chars in the format string");
73 is(strftime("%Y\x{5e74}%m\x{6708}%d\x{65e5}", POSIX::gmtime($jan_16)),
74 "1970\x{5e74}01\x{6708}16\x{65e5}",
75 "strftime() can handle unicode chars in the format string");
78 unlike($ss, qr/\w/, 'Not internally UTF-8 encoded');
79 is(ord strftime($ss, CORE::localtime), 223,
80 'Format string has correct character');
81 is(ord strftime($ss, POSIX::localtime(time)),
82 223, 'Format string has correct character');
83 unlike($ss, qr/\w/, 'Still not internally UTF-8 encoded');
85 if (locales_enabled('LC_TIME')) {
86 setlocale(LC_TIME, $orig_time_loc) || die "Cannot setlocale(LC_TIME) back to orig: $!";
88 if (locales_enabled('LC_CTYPE')) {
89 setlocale(LC_TIME, $orig_ctype_loc) || die "Cannot setlocale(LC_CTYPE) back to orig: $!";
92 # clock() seems to have different definitions of what it does between POSIX
93 # and BSD. Cygwin, Win32, and Linux lean the BSD way. So, the tests just
95 like(clock(), qr/\d*/, "clock() returns a numeric value");
96 cmp_ok(clock(), '>=', 0, "...and it returns something >= 0");
99 skip "No difftime()", 1 if $Config{d_difftime} ne 'define';
100 is(difftime(2, 1), 1, "difftime()");
104 skip "No mktime()", 2 if $Config{d_mktime} ne 'define';
106 is(mktime(CORE::localtime($time)), $time, "mktime()");
107 is(mktime(POSIX::localtime($time)), $time, "mktime()");