1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#!/usr/bin/perl
# Ensure localtime() honors the current time zone
use strict;
use warnings;
use Time::y2038;
use Test::More 'no_plan';
my $Time = time();
SKIP: {
local $ENV{TZ};
# Two time zones, different and likely to exist
my $tz1 = "America/Los_Angeles";
my $tz2 = "America/Chicago";
# If the core localtime doesn't respond to TZ, we don't have to.
skip "localtime does not respect TZ env", 1
unless do {
# check that localtime respects changes to $ENV{TZ}
$ENV{TZ} = $tz1;
my $hour = (CORE::localtime($Time))[2];
$ENV{TZ} = $tz2;
my $hour2 = (CORE::localtime($Time))[2];
$hour != $hour2;
};
# check that localtime respects changes to $ENV{TZ}
$ENV{TZ} = $tz1;
my $hour = (localtime($Time))[2];
$ENV{TZ} = $tz2;
my $hour2 = (localtime($Time))[2];
isnt $hour, $hour2, "localtime() honors TZ";
}
|