Starky has asked for the wisdom of the Perl Monks concerning the following question:
I have searched the CPAN, but to no avail. And using localtime has provided me with nothing but frustration, since (so far as I can tell) the only way to determine whether it is daylight savings time in a particular time zone is:
The reason for dealing with the offset is that localtime() likes to adjust the return value according to the offset between the machine's time zone and that given by $ENV{TZ}:
yields#!/usr/bin/perl use strict; my $time = time(); print "Localtime is [".localtime($time)."[ when \$ENV{TZ} is [$ENV{TZ} +] based on time [$time]\n"; $ENV{TZ} = 'GMT'; print "Localtime is now [".localtime($time)."] when \$ENV{TZ} is [$ENV +{TZ}[ based on time [$time]\n";
Even Date::Manip likes to implicitly convert epoch seconds. For example,Localtime is [Wed May 29 14:42:15 2002] when $ENV{TZ} is [] based on t +ime [1022704935] Localtime is now [Wed May 29 20:42:15 2002] when $ENV{TZ} is [GMT] bas +ed on time [1022704935]
gives#!/usr/bin/perl use strict; use Date::Manip; print &UnixDate(&ParseDate("epoch ".time()),"%Y-%m-%d %H:%M:%S")."\n";
[starky@freak bin]$ unset TZ [starky@freak bin]$ ./dm-test.pl 2002-05-29 15:11:01 [starky@freak bin]$ export TZ=GMT [starky@freak bin]$ ./dm-test.pl 2002-05-29 21:11:15
It just seems to be an overly convoluted process. I'm convinced there's an easier way but cannot seem to find it. I feel like I'm just being daft here or there's something about time zones I'm simply not clued in to ...
Edit by tye to change PRE tags to CODE tags
|
|---|