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

Of course, if you do write your own code you will be spending time to re-implement something that someone has already written. If the overhead of calling a "slow" module like Date::Manip is too much for you, then Perl is probably too slow and inefficient for you; you should use a compiled language like C. Also Date::Manip (and all other perl modules) has been used by thousands of perl programmers, so the code is well tested and proven to be reliable, stable and relatively bug-free.

Replies are listed 'Best First'.
RE: RE: RE: RE: Timezones in Perl
by Shendal (Hermit) on Jun 23, 2000 at 00:00 UTC
    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.
      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";