Commit | Line | Data |
---|---|---|
2da668d2 SP |
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 | |
10 | { | |
11 | no warnings 'uninitialized'; | |
12 | $ENV{TZ} = undef; | |
13 | } | |
14 | ||
15 | SKIP: { | |
16 | # It looks like POSIX.xs claims that only VMS and Mac OS traditional | |
17 | # don't have tzset(). A config setting might be helpful. Win32 actually | |
18 | # seems ambiguous | |
19 | skip "No tzset()", 2 | |
20 | if $^O eq "MacOS" || $^O eq "VMS" || $^O eq "cygwin" || | |
34dd738f SP |
21 | $^O eq "MSWin32" || $^O eq "dos" || $^O eq "interix" || |
22 | $^O eq "openbsd"; | |
2da668d2 SP |
23 | tzset(); |
24 | my @tzname = tzname(); | |
25 | like($tzname[0], qr/[GMT|UTC]/i, "tzset() to GMT/UTC"); | |
26 | like($tzname[1], qr/[GMT|UTC]/i, "The whole year?"); | |
27 | } | |
28 | ||
29 | # asctime and ctime...Let's stay below INT_MAX for 32-bits and | |
30 | # positive for some picky systems. | |
31 | ||
32 | is(asctime(localtime(0)), ctime(0), "asctime() and ctime() at zero"); | |
33 | is(asctime(localtime(12345678)), ctime(12345678), "asctime() and ctime() at 12345678"); | |
34 | ||
35 | # Careful! strftime() is locale sensative. Let's take care of that | |
34dd738f SP |
36 | my $orig_loc = setlocale(LC_TIME, "C") || die "Cannot setlocale() to C: $!"; |
37 | if ($^O eq "MSWin32") { | |
38 | is(ctime(0), strftime("%a %b %#d %H:%M:%S %Y\n", localtime(0)), | |
39 | "get ctime() equal to strftime()"); | |
40 | } else { | |
41 | is(ctime(0), strftime("%a %b %e %H:%M:%S %Y\n", localtime(0)), | |
2da668d2 | 42 | "get ctime() equal to strftime()"); |
2da668d2 | 43 | } |
34dd738f | 44 | setlocale(LC_TIME, $orig_loc) || die "Cannot setlocale() back to orig: $!"; |
2da668d2 SP |
45 | |
46 | # Hard to test other than to make sure it returns something numeric and < 0 | |
47 | like(clock(), qr/\d*/, "clock() returns a numeric value"); | |
48 | ok(clock() > 0, "...and its greater than zero"); | |
49 | ||
50 | SKIP: { | |
51 | skip "No difftime()", 1 if $Config{d_difftime} ne 'define'; | |
52 | is(difftime(2, 1), 1, "difftime()"); | |
53 | } | |
54 | ||
55 | SKIP: { | |
56 | skip "No mktime()", 1 if $Config{d_mktime} ne 'define'; | |
57 | my $time = time(); | |
58 | is(mktime(localtime($time)), $time, "mktime()"); | |
59 | } |