Skip Menu |

This queue is for tickets about the DateManip CPAN distribution.

Report information
The Basics
Id: 6678
Status: resolved
Priority: 0/
Queue: DateManip

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 5.42a
Fixed in: (no value)



Subject: timezone not detected on windows
You should use POSIX to determine timezone perl -MPOSIX -le"print for POSIX::tzname()"
From: shane.mcwhorter [...] userinterfacehelp.com
Suggest adding ability, after standard routines fail, to set timezone from the timezone offset, ala (localtime)[2] - (gmtime)[2] (with minutes as well as is needed for NST, IT, etc.). This appears to work with Perl on Win32 without hard coding TZ in script as suggested by the docs or invoking POSIX. Example returns -5 on win32 is EST5EDT: #!perl my $lh = (localtime)[2]; my $gh = (gmtime)[2]; print $lh - $gh, "\n"; Background: Date:Manip looks for: $Date::Manip::TZ (set with Date_Init or in Manip.pm) $ENV{TZ} the unix `date` command (if available) $main::TZ /etc/TIMEZONE /etc/timezone and TZ is not set on Windows in the above. Documentation suggests: Date::Manip tries hard to determine the local timezone, but on some machines, it cannot do this (especially non-unix systems). To fix this, just set the TZ variable, either at the top of the Manip.pm file,, in the DateManip.cnf file, or in a call to Date_Init. I suggest using the form ``EST5EDT'' so you don't have to change it every 6 months when going to or from daylight savings time.
From: shane.mcwhorter [...] userinterfacehelp.com
See attached for example code.
#!perl -w # TZ calculation can be used by Date::Manip # if not found on win32 # shane.mcwhorter#userinterfacehelp.com print getTZ(), "\n"; sub getTZ { my ($lm, $lh, $ldst) = (localtime)[1,2,8]; my ($gm, $gh) = (gmtime)[1,2]; my $h = $lh - $gh; my $m = $lm - $gm; if ($m < 0) { $m += 60; $h -= 1; } $h -= 1 if ($ldst); $h += 24 if ($h < -12); return (sprintf "%+03d%02d", $h, $m); }
On Wed Jan 05 17:15:16 2005, guest wrote: Show quoted text
> See attached for example code.
Sorry, but I don't think that's correct at all. I realize this thread is old, but I ran into this page while looking for a similar method. You can't just subtract the "gm hour" from the "local hour" and reliably get the timezone offset. That doesn't take into account the case where "gm hour" and "local hour" are actually hours of different days. In my case I need the timezone on windows in order to produce an rfc822 date string (ala unix' "date -R"), and so far the easiest way I've come up with to get the timezone offset is below. The idea is to feed the output of both localtime and gmtime back into timelocal to get an epoch time for each of them as though they were different times in the same timezone, then compute the offset as a function of the difference in epoch seconds. #!/usr/bin/perl use Time::Local; my $local=scalar localtime; my $gm=scalar gmtime; my @locals=(localtime)[0,1,2,3,4,5]; my @gms=(gmtime)[0,1,2,3,4,5]; my $localepochtime=timelocal(@locals); my $gmepochtime=timelocal(@gms); my $seconds_apart=$localepochtime-$gmepochtime; # Admittedly the rounding isn't exactly correct according to # the conventions of science. if ($seconds_apart<0) { print "Offset=", int( ($seconds_apart/60/60) - .5), "\n"; } else { print "Offset=", int( ($seconds_apart/60/60) + .5), "\n"; }
6.xx has much better support for windows timezones.