in reply to RE: RE: RE: Timezones in Perl
in thread Timezones in Perl

Good points. I would still encourage writing your own routine, if all you need is different timezones -- it would be trivial. I know that I have to work on many varying machines all over, and the more modules I have to worry about installing the more of a headache it becomes (especially when you're talking about hundreds of NT clients).

FWIW, I haven't noticed this package being "slow"... I'm merely pointing out that the author seems to think so.

Replies are listed 'Best First'.
RE: RE: RE: RE: RE: Timezones in Perl
by lhoward (Vicar) on Jun 23, 2000 at 00:47 UTC
    Time-zone conversion is not a trivial problem. If the from/to timezones are constant and you don't have any foolishness like "daylight savings time" to consider you could theoretically do a conversion by adding or subtracting n hours. However, what if that rolls over a day boundary? What about month boundaries? You have to consider years too. You also need to keep track of leap-years to be accurate. By the time you're done you've impelmented a good portion of a full calendar system just to do a timezone conversion. IMHO, much better to use a module.
      Correct me if I'm wrong, but localtime does all that conversion/daylight savings/boundary work for you. Wouldn't this work?
      use strict; use warnings; sub myGetTime { my($timezone) = shift; $timezone = 0 unless $timezone; # convert to seconds $timezone = $timezone * 3600 if ($timezone); my($time) = time + $timezone; return (gmtime($time)); } print "Local : " . localtime(time) . "\n"; print "London : " . &myGetTime . "\n"; print "Houston: " . &myGetTime(-5) . "\n";
        Your example works fine if you want to add or subtract hours from the current local time. However, the date the original question is not accessible from the time call. It must be parsed, converted to an apropriate timestamp value and de-timezoned before you can start using localtime or gmtime to manipulate it. And what if the output format the person wants isn't what gmtime or localtime produces? It must then be manipulated again into the proper format. All these functions are provided for you by the Date and Time modules.