Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > TimeZone calculation on Windows Vista with DateTime::TimeZone

Reply
Thread Tools

TimeZone calculation on Windows Vista with DateTime::TimeZone

 
 
Ami
Guest
Posts: n/a
 
      09-20-2007
Hi All,
I am using Windows Vista with ActivePerl 5.8.8.822. I have
downloaded the latest DateTime::TimeZone package from CPAN (DateTime-
TimeZone-0.67). When I write a small script to work with it, I always
get error stating that "Cannot determine local time zone.". After
debugging, I came to know that DateTime package of Perl reads the
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contr ol
\TimeZoneInformation\StandardName" to access this information which is
supposed to contain a Windows name for the time zone (e.g.) but in
Windows Vista, it contains some dll entry point information
(@tzres.dll,-492).

The code snippet with which I am trying to work is as follows:

use DateTime::TimeZone;
my $tz = DateTime::TimeZone->new( name => 'local' );
$tz = DateTime::TimeZone::Local->TimeZone();

Can any one help me to make it working on Windows Vista?

Thanks in advance for your help and time.
Regards

 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      09-20-2007

Quoth Ami <(E-Mail Removed)>:
> Hi All,
> I am using Windows Vista with ActivePerl 5.8.8.822. I have
> downloaded the latest DateTime::TimeZone package from CPAN (DateTime-
> TimeZone-0.67). When I write a small script to work with it, I always
> get error stating that "Cannot determine local time zone.". After
> debugging, I came to know that DateTime package of Perl reads the
> "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contr ol
> \TimeZoneInformation\StandardName" to access this information which is
> supposed to contain a Windows name for the time zone (e.g.) but in
> Windows Vista, it contains some dll entry point information
> (@tzres.dll,-492).
>
> The code snippet with which I am trying to work is as follows:
>
> use DateTime::TimeZone;
> my $tz = DateTime::TimeZone->new( name => 'local' );
> $tz = DateTime::TimeZone::Local->TimeZone();
>
> Can any one help me to make it working on Windows Vista?


This is clearly a bug in DateTime::TimeZone, or rather an
incompatibility with Vista. It's probably worth filing a bug report on
rt.cpan.org.

About the only workaround is to pick the appropriate timezone from the
list returned by DateTime::TimeZone->all_names and set %TZ% in the
environment to that value.

Ben

 
Reply With Quote
 
 
 
 
Ami
Guest
Posts: n/a
 
      09-21-2007
On Sep 21, 3:36 am, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth Ami <(E-Mail Removed)>:
>
>
>
> > Hi All,
> > I am using Windows Vista with ActivePerl 5.8.8.822. I have
> > downloaded the latest DateTime::TimeZone package from CPAN (DateTime-
> > TimeZone-0.67). When I write a small script to work with it, I always
> > get error stating that "Cannot determine local time zone.". After
> > debugging, I came to know that DateTime package of Perl reads the
> > "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contr ol
> > \TimeZoneInformation\StandardName" to access this information which is
> > supposed to contain a Windows name for the time zone (e.g.) but in
> > Windows Vista, it contains some dll entry point information
> > (@tzres.dll,-492).

>
> > The code snippet with which I am trying to work is as follows:

>
> > use DateTime::TimeZone;
> > my $tz = DateTime::TimeZone->new( name => 'local' );
> > $tz = DateTime::TimeZone::Local->TimeZone();

>
> > Can any one help me to make it working on Windows Vista?

>
> This is clearly a bug in DateTime::TimeZone, or rather an
> incompatibility with Vista. It's probably worth filing a bug report on
> rt.cpan.org.
>
> About the only workaround is to pick the appropriate timezone from the
> list returned by DateTime::TimeZone->all_names and set %TZ% in the
> environment to that value.
>
> Ben


Hi Ben,
Many thanks for your reply but being a new comer to Perl, I am not
sure how can I choose the appropriate timezone from array returned
from all_names function. This array consists of list of all time
zones. How can I determine which time zone my machine is using and set
the %TZ% in environment variable. To try it with hardcode, i used
following code in below given code:

use Time::Local;
my @dayofweek = (qw(Sunday Monday Tuesday Wednesday Thursday Friday
Saturday));
my @monthnames = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov
Dec));
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday);
$ENV{TZ}='Asia/Calcutta';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =
localtime($TimeInSeconds);
$year += 1900;
print "This date is $dayofweek[$wday], $monthnames[$mon] $mday, $year
\n";
print "This time is $hour:$min:$sec\n";

and same code with
$ENV{'TZ'}='+530';

but it gives me following date/time:
This date is Thursday, Jan 1, 1970
This time is 5:30:0

Please could you give me some code example to make it working?
Thanks for your help.
Regards,

 
Reply With Quote
 
Ami
Guest
Posts: n/a
 
      09-21-2007
On Sep 21, 3:36 am, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth Ami <(E-Mail Removed)>:
>
>
>
> > Hi All,
> > I am using Windows Vista with ActivePerl 5.8.8.822. I have
> > downloaded the latest DateTime::TimeZone package from CPAN (DateTime-
> > TimeZone-0.67). When I write a small script to work with it, I always
> > get error stating that "Cannot determine local time zone.". After
> > debugging, I came to know that DateTime package of Perl reads the
> > "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contr ol
> > \TimeZoneInformation\StandardName" to access this information which is
> > supposed to contain a Windows name for the time zone (e.g.) but in
> > Windows Vista, it contains some dll entry point information
> > (@tzres.dll,-492).

>
> > The code snippet with which I am trying to work is as follows:

>
> > use DateTime::TimeZone;
> > my $tz = DateTime::TimeZone->new( name => 'local' );
> > $tz = DateTime::TimeZone::Local->TimeZone();

>
> > Can any one help me to make it working on Windows Vista?

>
> This is clearly a bug in DateTime::TimeZone, or rather an
> incompatibility with Vista. It's probably worth filing a bug report on
> rt.cpan.org.
>
> About the only workaround is to pick the appropriate timezone from the
> list returned by DateTime::TimeZone->all_names and set %TZ% in the
> environment to that value.
>
> Ben


Hi Ben,
Many Thanks for your reply.But being a new bee to perl, I am not
sure how can retrieve the current time zone from the list returned by
all_names() function. What should be the condition to match the
current time zone from list?
How can I set the TZ in ENV variable. I tried with
$ENV{'TZ'}='Asia/Calcutta';
and
$ENV{TZ}='America/Chicago';
All time I get same date/time;

The script used is as follows:
use Time::Local;
my @dayofweek = (qw(Sunday Monday Tuesday Wednesday Thursday Friday
Saturday));
my @monthnames = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov
Dec));
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday);
$ENV{TZ}='America/Chicago';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime();
$year += 1900;
print "This date is $dayofweek[$wday], $monthnames[$mon] $mday, $year
\n";
print "This time is $hour:$min:$sec\n";

It would be great help, if i can get some code snippet to set the TZ
correctly to get correct time according to zones.
Thanks

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      09-21-2007

Quoth Ami <(E-Mail Removed)>:
> On Sep 21, 3:36 am, Ben Morrow <(E-Mail Removed)> wrote:
> > Quoth Ami <(E-Mail Removed)>:
> > >
> > > Hi All,
> > > I am using Windows Vista with ActivePerl 5.8.8.822. I have
> > > downloaded the latest DateTime::TimeZone package from CPAN (DateTime-
> > > TimeZone-0.67). When I write a small script to work with it, I always
> > > get error stating that "Cannot determine local time zone.". After
> > > debugging, I came to know that DateTime package of Perl reads the
> > > "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contr ol
> > > \TimeZoneInformation\StandardName" to access this information which is
> > > supposed to contain a Windows name for the time zone (e.g.) but in
> > > Windows Vista, it contains some dll entry point information
> > > (@tzres.dll,-492).

> >
> > > The code snippet with which I am trying to work is as follows:

> >
> > > use DateTime::TimeZone;
> > > my $tz = DateTime::TimeZone->new( name => 'local' );
> > > $tz = DateTime::TimeZone::Local->TimeZone();

> >
> > > Can any one help me to make it working on Windows Vista?

> >
> > This is clearly a bug in DateTime::TimeZone, or rather an
> > incompatibility with Vista. It's probably worth filing a bug report on
> > rt.cpan.org.
> >
> > About the only workaround is to pick the appropriate timezone from the
> > list returned by DateTime::TimeZone->all_names and set %TZ% in the
> > environment to that value.

>
> Many Thanks for your reply.But being a new bee to perl, I am not
> sure how can retrieve the current time zone from the list returned by
> all_names() function. What should be the condition to match the
> current time zone from list?


I'm afraid I don't know. The correct answer is to call the Win32 API
function GetTimeZoneInformation or GetDynamicTimeZoneInformation, but
while it would be possible to do this using Win32::API it's not
something I can construct an example of off the top of my head. I think
for now you're just going to have to set it manually.

> How can I set the TZ in ENV variable. I tried with
> $ENV{'TZ'}='Asia/Calcutta';
> and
> $ENV{TZ}='America/Chicago';
> All time I get same date/time;


You probably need to set $ENV{TZ} in a BEGIN block before you load
DateTime::TimeZone, something like

BEGIN { $ENV{TZ} = 'Asia/Calcutta' }

use DateTime::TimeZone; # or Time::Local, or whatever

You could also set the variable in the 'real' environment, so it's
always present.

Ben

 
Reply With Quote
 
Ami
Guest
Posts: n/a
 
      09-24-2007
On Sep 21, 9:35 pm, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth Ami <(E-Mail Removed)>:
>
>
>
> > On Sep 21, 3:36 am, Ben Morrow <(E-Mail Removed)> wrote:
> > > Quoth Ami <(E-Mail Removed)>:

>
> > > > Hi All,
> > > > I am using Windows Vista with ActivePerl 5.8.8.822. I have
> > > > downloaded the latest DateTime::TimeZone package from CPAN (DateTime-
> > > > TimeZone-0.67). When I write a small script to work with it, I always
> > > > get error stating that "Cannot determine local time zone.". After
> > > > debugging, I came to know that DateTime package of Perl reads the
> > > > "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contr ol
> > > > \TimeZoneInformation\StandardName" to access this information which is
> > > > supposed to contain a Windows name for the time zone (e.g.) but in
> > > > Windows Vista, it contains some dll entry point information
> > > > (@tzres.dll,-492).

>
> > > > The code snippet with which I am trying to work is as follows:

>
> > > > use DateTime::TimeZone;
> > > > my $tz = DateTime::TimeZone->new( name => 'local' );
> > > > $tz = DateTime::TimeZone::Local->TimeZone();

>
> > > > Can any one help me to make it working on Windows Vista?

>
> > > This is clearly a bug in DateTime::TimeZone, or rather an
> > > incompatibility with Vista. It's probably worth filing a bug report on
> > > rt.cpan.org.

>
> > > About the only workaround is to pick the appropriate timezone from the
> > > list returned by DateTime::TimeZone->all_names and set %TZ% in the
> > > environment to that value.

>
> > Many Thanks for your reply.But being a new bee to perl, I am not
> > sure how can retrieve the current time zone from the list returned by
> > all_names() function. What should be the condition to match the
> > current time zone from list?

>
> I'm afraid I don't know. The correct answer is to call the Win32 API
> function GetTimeZoneInformation or GetDynamicTimeZoneInformation, but
> while it would be possible to do this using Win32::API it's not
> something I can construct an example of off the top of my head. I think
> for now you're just going to have to set it manually.
>
> > How can I set the TZ in ENV variable. I tried with
> > $ENV{'TZ'}='Asia/Calcutta';
> > and
> > $ENV{TZ}='America/Chicago';
> > All time I get same date/time;

>
> You probably need to set $ENV{TZ} in a BEGIN block before you load
> DateTime::TimeZone, something like
>
> BEGIN { $ENV{TZ} = 'Asia/Calcutta' }
>
> use DateTime::TimeZone; # or Time::Local, or whatever
>
> You could also set the variable in the 'real' environment, so it's
> always present.
>
> Ben


Hi Ben,
Thanks for your reply. I have tried using
BEGIN { $ENV{TZ} = 'Asia/Calcutta' }
and than
BEGIN { $ENV{TZ} = 'America/Chicago' }
before loading DateTime::TimeZone but i find no impact. It shows
current PC time on using localtime() function. Setting the environmnet
variable TZ to different values also returns same value.
Any other idea, what i might be doing wrong?
Regards

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TimeZone change - how to use TimeZone class axrock Java 8 03-25-2009 11:54 PM
Windows Vista Free! I Need to share my results I found Windows Vista for Free! I love Google Digital Photography 7 05-06-2007 02:37 PM
Vista codec packages for Vista 32 & vista 64 Kue2 Windows 64bit 0 03-05-2007 05:48 PM
Windows Vista 64 or Windows Vista 32 for AMD 64 FX-57 =?Utf-8?B?YWRub24=?= Windows 64bit 4 02-07-2007 12:52 AM
Convert windows TimeZone to Java TimeZone asaf Java 3 09-11-2006 05:40 PM



Advertisments