DateTime-TimeZone-Local-Win32
view release on metacpan or search on metacpan
t/01-local-win32.t view on Meta::CPAN
$tz && DateTime::TimeZone->is_valid_name( $tz->name() ),
"$windows_tz_name - found valid IANA time zone '" .
DateTime::TimeZone::Local::Win32->_FindWindowsTZName() . "' from Windows"
);
}
else {
my $tz_name = DateTime::TimeZone::Local::Win32->_WindowsToIANA( $windows_tz_name );
ok (
defined $tz_name,
"$windows_tz_name - found time zone '" . $windows_tz_name . "' from Hash"
);
}
if ( defined $iana_name ) {
my $desc = "$windows_tz_name was mapped to $iana_name";
if ( $registry_writable && $tz && $minimum_DT_TZ ) {
is( $tz->name(), $iana_name, "$desc (Registry)" );
}
elsif ( $registry_writable && $minimum_DT_TZ ) {
fail("$desc (Registry)");
}
else {
my $tz_name = DateTime::TimeZone::Local::Win32->_WindowsToIANA( $windows_tz_name );
is ( $tz_name, $iana_name, "$desc (Hash)" );
}
}
else {
SKIP: {
unless ( $ENV{'AUTHOR_TESTING'} && $registry_writable ) {
skip (
"$windows_tz_name - Windows offset matches IANA offset (Maintainer only)",
3
);
}
if ( !$tz || !DateTime::TimeZone->is_valid_name( $tz->name() ) ) {
skip (
"Time Zone display for $windows_tz_name not testable",
3
);
}
my $dt = DateTime->now(
time_zone => $tz->name(),
);
# typical times always Winter or Summer time depending on hemisphere if daylight savings in use
# and attempting to avoid Ramadan as Morocco suspends daylight savings during Ramadan
my $feb_dt = DateTime->new(
time_zone => $tz->name(),
year => $dt->year(),
month => 2,
day => 1,
);
my $aug_dt = DateTime->new(
time_zone => $tz->name(),
year => $dt->year(),
month => 8,
day => 1,
);
# Windows time zone offsets are defined in a structure defined here and offsets are in minutes):
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms725481(v=vs.85).aspx
my $windows_tz_info = {};
@{$windows_tz_info}{
'bias',
'standardBias',
'daylightBias',
'standardYear',
'standardMonth',
'standardDayOfWeek',
'standardWeekOfMonth',
'standardHour',
'standardMinute',
'standardSecond',
'standardMilliseconds',
'daylightYear',
'daylightMonth',
'daylightDayOfWeek',
'daylightWeekOfMonth',
'daylightHour',
'daylightMinute',
'daylightSecond',
'daylightMilliseconds'
} = unpack("lllvvvvvvvvvvvvvvvv", $WindowsTZKey->{"${windows_tz_name}/TZI"});
my ($windows_offset, $windows_feb_offset, $windows_aug_offset) =
get_windows_timezone_offsets( $dt, $feb_dt, $aug_dt, $windows_tz_info );
# offsets in DateTime::TimeZone are in seconds
my $dt_offset = $dt->offset();
my $feb_dt_offset = $feb_dt->offset();
my $aug_dt_offset = $aug_dt->offset();
# convert offsets from seconds or minutes before or after UTC to hours
$dt_offset /= SECONDS_PER_HOUR;
$feb_dt_offset /= SECONDS_PER_HOUR;
$aug_dt_offset /= SECONDS_PER_HOUR;
$windows_offset /= MINUTES_PER_HOUR;
$windows_feb_offset /= MINUTES_PER_HOUR;
$windows_aug_offset /= MINUTES_PER_HOUR;
if ( $KnownBad{$windows_tz_name} ) {
TODO: {
local $TODO
= "Microsoft has some out-of-date time zones relative to IANA";
is(
$windows_offset, $dt_offset,
"$windows_tz_name - Windows offset matches IANA offset for current time"
);
is(
$windows_feb_offset, $feb_dt_offset,
"$windows_tz_name - Windows offset matches IANA offset for time set February 1"
);
is(
$windows_aug_offset, $aug_dt_offset,
"$windows_tz_name - Windows offset matches IANA offset for time set August 1"
);
return;
}
( run in 0.857 second using v1.01-cache-2.11-cpan-e1769b4cff6 )