Subject: | Local TimeZone not detected on Windows 2008 server |
I am using ActiveState Perl version 5.12. Output of perl -v:
---
This is perl 5, version 12, subversion 3 (v5.12.3) built for
MSWin32-x86-multi-thread
(with 9 registered patches, see perl -V for more detail)
Copyright 1987-2010, Larry Wall
Binary build 1204 [294330] provided by ActiveState
http://www.ActiveState.com
Built Feb 9 2011 14:38:22
---
On our Windows 2008 server calling
DateTime::TimeZone->new( name => 'local' )
results in a die "Cannot determine local time zone\n";
The reason is that $win_name in line 205 of
DateTime::TimeZone::Local::Win32.pm contains newlines after the first
null character, resulting in the regulare expression which should clean
up this junk not doing a complete job.
I think changing
$win_name =~ s/\0.*$//
if defined $win_name;
to
$win_name =~ s/\0.*$//s
if defined $win_name;
would do the job.
The actual value, for your reference, of $win_name is
join( '', map { chr } qw( 77 111 117 110 116 97 105 110 32 83 116 97 110
100 97 114 100 32 84 105 109 101 0 10 0 0 0 0 0 0 82 0 0 0 63 32 0 0 63
120 0 0 32 0 0 0 72 0 0 0 64 116 122 114 101 115 46 100 108 108 44 45 49
57 50 0 0 0 0 0 1 0 0 0 63 13 0 0 63 63 63 0 63 13 0 0 1 0 0 0 64 116
122 114 101 115 46 100 108 108 44 45 49 57 49 0 72 0 0 0 0 0 0 0 63 120
0 0 213 63 63 0 0 0 0 0 0 ) );
Maybe it would be a good idea to add this to 19local-win32.t as well,
perhaps as follows:
my $dirty_timezone = join( '', map { chr } qw( 77 111 117 110 116 97 105
110 32 83 116 97 110 100 97 114 100 32 84 105 109 101 0 10 0 0 0 0 0 0
82 0 0 0 63 32 0 0 63 120 0 0 32 0 0 0 72 0 0 0 64 116 122 114 101 115
46 100 108 108 44 45 49 57 50 0 0 0 0 0 1 0 0 0 63 13 0 0 63 63 63 0 63
13 0 0 1 0 0 0 64 116 122 114 101 115 46 100 108 108 44 45 49 57 49 0 72
0 0 0 0 0 0 0 63 120 0 0 213 63 63 0 0 0 0 0 0 ) );
# We test these explicitly because we want to make sure that at
# least a few known names do work, rather than just relying on
# looping through a list.
for my $pair (
[ 'Eastern Standard Time', 'America/New_York' ],
[ 'Dateline Standard Time', '-1200' ],
[ 'Israel Standard Time', 'Asia/Jerusalem' ],
[ $dirty_timezone, 'America/Denver' ]
) {
set_and_test_windows_tz( @{$pair}, $tzi_key );
}