Just be explicit about $TZ.
[p5sagit/p5-mst-13.2.git] / ext / POSIX / t / time.t
1 #!perl -w
2
3 use strict;
4
5 use Config;
6 use POSIX;
7 use Test::More qw(no_plan);
8
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";
13
14 SKIP: {
15     # It looks like POSIX.xs claims that only VMS and Mac OS traditional
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.
19     skip "No tzset()", 2
20        if $^O eq "MacOS" || $^O eq "VMS" || $^O eq "cygwin" || $^O eq "djgpp" ||
21           $^O eq "MSWin32" || $^O eq "dos" || $^O eq "interix";
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
31 is(asctime(localtime(0)), ctime(0), "asctime() and ctime() at zero");
32 is(asctime(localtime(12345678)), ctime(12345678), "asctime() and ctime() at 12345678");
33
34 # Careful!  strftime() is locale sensative.  Let's take care of that
35 my $orig_loc = setlocale(LC_TIME, "C") || die "Cannot setlocale() to C:  $!";
36 if ($^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)),
41         "get ctime() equal to strftime()");
42 }
43 setlocale(LC_TIME, $orig_loc) || die "Cannot setlocale() back to orig: $!";
44
45 # Hard to test other than to make sure it returns something numeric and < 0
46 like(clock(), qr/\d*/, "clock() returns a numeric value");
47 ok(clock() > 0, "...and its greater than zero");
48
49 SKIP: {
50     skip "No difftime()", 1 if $Config{d_difftime} ne 'define';
51     is(difftime(2, 1), 1, "difftime()");
52 }
53
54 SKIP: {
55     skip "No mktime()", 1 if $Config{d_mktime} ne 'define';
56     my $time = time();
57     is(mktime(localtime($time)), $time, "mktime()");
58 }