| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
|
| 7 |
eval { require Test::MockTime }; |
| 8 |
if ($@) { |
| 9 |
plan skip_all => 'Test::MockTime required for this test'; |
| 10 |
} |
| 11 |
Test::MockTime->import('set_fixed_time', 'restore_time'); |
| 12 |
|
| 13 |
use_ok( 'Time::ParseDate' ); |
| 14 |
|
| 15 |
$ENV{'LANG'} = 'C'; |
| 16 |
$ENV{'TZ'} = 'PST8PDT'; |
| 17 |
|
| 18 |
# Verify that setting $ENV{TZ} actually affects localtime() on this |
| 19 |
# platform. Not all systems honor TZ changes within a running process. |
| 20 |
my @x = localtime(785307957); |
| 21 |
my @y = gmtime(785307957); |
| 22 |
my $hd = $y[2] - $x[2]; |
| 23 |
$hd += 24 if $hd < 0; |
| 24 |
$hd %= 24; |
| 25 |
if ($hd != 8) { |
| 26 |
plan skip_all => "It seems localtime() does not honor \$ENV{TZ} when set in the test script."; |
| 27 |
exit 0; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
# Verify that parsing a date returns the correct epoch regardless of |
| 32 |
# whether the system clock and the parsed date are in different DST states. |
| 33 |
# https://github.com/muir/Time-modules/issues/8 |
| 34 |
|
| 35 |
# Clock in summer, parse a winter date |
| 36 |
set_fixed_time(962409600); # 2000-06-30 PDT |
| 37 |
is(parsedate('1969/12/31 16:00:00', WHOLE => 1), |
| 38 |
0, 'winter date parsed when clock is in summer'); |
| 39 |
restore_time(); |
| 40 |
|
| 41 |
# Clock in winter, parse a summer date |
| 42 |
set_fixed_time(946684800); # 2000-01-01 PST |
| 43 |
is(parsedate('2000/07/04 12:00:00', WHOLE => 1), |
| 44 |
962737200, 'summer date parsed when clock is in winter'); |
| 45 |
restore_time(); |
| 46 |
|
| 47 |
# Clock and parsed date in the same DST state |
| 48 |
set_fixed_time(962409600); # 2000-06-30 PDT |
| 49 |
is(parsedate('2000/07/04 12:00:00', WHOLE => 1), |
| 50 |
962737200, 'summer date parsed when clock is in summer'); |
| 51 |
restore_time(); |
| 52 |
|
| 53 |
set_fixed_time(946684800); # 2000-01-01 PST |
| 54 |
is(parsedate('1969/12/31 16:00:00', WHOLE => 1), |
| 55 |
0, 'winter date parsed when clock is in winter'); |
| 56 |
restore_time(); |
| 57 |
|
| 58 |
done_testing(); |