Upgrade to Scalar-List-Utils-1.18
[p5sagit/p5-mst-13.2.git] / ext / POSIX / t / time.t
CommitLineData
2da668d2 1#!perl -w
2
3use strict;
4
5use Config;
6use POSIX;
7use Test::More qw(no_plan);
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
14SKIP: {
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");
25 like($tzname[1], qr/[GMT|UTC]/i, "The whole year?");
26}
27
28# asctime and ctime...Let's stay below INT_MAX for 32-bits and
29# positive for some picky systems.
30
31is(asctime(localtime(0)), ctime(0), "asctime() and ctime() at zero");
32is(asctime(localtime(12345678)), ctime(12345678), "asctime() and ctime() at 12345678");
33
34# Careful! strftime() is locale sensative. Let's take care of that
34dd738f 35my $orig_loc = setlocale(LC_TIME, "C") || die "Cannot setlocale() to C: $!";
36if ($^O eq "MSWin32") {
37 is(ctime(0), strftime("%a %b %#d %H:%M:%S %Y\n", localtime(0)),
38 "get ctime() equal to strftime()");
39} else {
40 is(ctime(0), strftime("%a %b %e %H:%M:%S %Y\n", localtime(0)),
2da668d2 41 "get ctime() equal to strftime()");
2da668d2 42}
34dd738f 43setlocale(LC_TIME, $orig_loc) || die "Cannot setlocale() back to orig: $!";
2da668d2 44
45# Hard to test other than to make sure it returns something numeric and < 0
46like(clock(), qr/\d*/, "clock() returns a numeric value");
47ok(clock() > 0, "...and its greater than zero");
48
49SKIP: {
50 skip "No difftime()", 1 if $Config{d_difftime} ne 'define';
51 is(difftime(2, 1), 1, "difftime()");
52}
53
54SKIP: {
55 skip "No mktime()", 1 if $Config{d_mktime} ne 'define';
56 my $time = time();
57 is(mktime(localtime($time)), $time, "mktime()");
58}