Hi,

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;
}


"Dave Rolsky" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Thu, 4 Dec 2003, Anton Berezin wrote:
>
> > - if TZ environment variable is not set, TimeZone tries /etc/localtime,
> >   which is present on FreeBSD.  Unfortunately, on FreeBSD this file is
> >   *NOT* a symlink to a timezone name, but a FreeBSD-specific binary file
> >   (see tzfile(5) for details);
>
> Slaven Rezic submitted a patch a while back that tries to figure out which
> file this is a copy of, specifically for annoying OS's like FreeBSD that
> do this ;)
>
> It's applied in CVS, and wlil be in the next release.
>
> > - even if TZ is set, it is very likely to contain something like "CET",
>
> That's not a time zone.
>
>
> -dave
>
> /*=======================
> House Absolute Consulting
> www.houseabsolute.com
> =======================*/


Reply via email to