On Thu, 4 Dec 2003, Thomas Bergmann wrote:

> I had the some problem "Cannot determine local time zone" on W2K.
>
> i dont like to set an additional enviroment variable TZ to find the right
> TimeZone on the server, because
> perl knows the timezone. gmtime and localtime work fine. So i wrote a
> "small" function to get the local timezone.
> is there any comparable at CPAN modules?
>
> # $timezone = local_time_zone() # in format: <sign>\d{2}:\d{2}
> sub local_time_zone {
>     my $timer = time;
>     my ($sec,$min,$hour,$mday,$mon,$year) = localtime($timer);
>     my $loc_time = sprintf("%4d-%02d-%02d %02d:%02d:%02d",$year + 1900,$mon
> + 1,$mday,$hour,$min,$sec);
>
>     ($sec,$min,$hour,$mday,$mon,$year) = gmtime($timer);
>     my $gmt_time = sprintf("%4d-%02d-%02d %02d:%02d:%02d",$year + 1900,$mon
> + 1,$mday,$hour,$min,$sec);
>
>     my $Strp = new DateTime::Format::Strptime(
>         pattern     => '%F %T',
>         locale      => 'en_AU',
>         time_zone   => '+0000',
>     );
>     my $d = $Strp->parse_datetime($loc_time) -
> $Strp->parse_datetime($gmt_time);
>     my $time_zone = sprintf("%s%02d:%02d",$d->is_negative ? '-' : '+' ,
> $d->hours,$d->minutes);
>     return $time_zone;
> }

Unfortunately, this isn't a time zone either.  Rather, it's an offset from
UTC that's valid at a specific moment in time.

Time zones are made up of multiple observances representing the historical
changes in that particular zone.  Each observance consists of:

- A base offset from UTC

- A set of 0+ rules defining DST changes during that observance

All the time zones have at least two observances, and a lot of them have
more.

Simply knowing the current UTC offset does not tell you if DST is in
effect, and more importantly, it doesn't tell you when that offset will
change because of a rule-specified DST change.

I'd love to get some code in there that works on Win32, but it needs to
get an actual time zone, not just an offset.


-dave

/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/

Reply via email to