As you have discovered, there are various problems with Time Zones and Date::Manip. If I were you, I'd take a look at the DateTime project. Using DateTime means you can get rid of that clutter of date modules that was previously needed to work with dates in Perl. The DateTime modules know all about Time Zones, including when local governing bodies changed their moves in and out of daylight savings. DateTime also knows about leap seconds and so carries accuracy over long periods very well.

There are a library of DateTime modules now available that can help you with anything related to dates and times, including working with httpd logs, with databases and even with using your own date formats. DateTime offers both strftime and strptime, so you're never limited by existing format modules.

DateTime also does a good job of durations and never assumes there's 24 * 60 * 60 seconds in a day. A fault of most (if not all) previously existing date and time modules.

However, like Date::Manip, DateTime needs to find your local time zone from somewhere if you want to talk about 'local' dates and times. But if your machine doesn't already have the information DateTime needs, there's no need to worry. If you know where you are (and most of us do!) you should be setting it anyways.

If timezones don't matter, then there's always the 'floating' timezone. This zone just 'floats' your datetime until you allocate a time zone to it. Huh? Well, if you make a datetime for 5pm on Sept 9, 2003 but don't specify a timezone then it's 'floating'. One you $dt->set_timezone('SomeZone') then it becomes 5pm on Sept 9, 2003 in SomeZone. It doesn't change the time, just the zone its in. Now if you were to change from SomeZone to UTC (similar to GMT), it becomes some other time, depending on the offset of SomeZone to UTC.

All in all, the DateTime modules solve pretty much any problem to do with dates and times in perl. If you have a problem that it doesn't solve then you're in luck: the development group is very active and will listen to anything you need.

At this point I should point out that I am one of the lowly developers in the project, so I have a certain bias. Despite this, and thinking as objectivly as I can, I still think DateTime is the best solution for most date and time problems in perl.

You can contact the mailing list at datetime@perl.org, and can download the modules from CPAN.


In reply to Re: setting TZ causes Date::Manip to report incorrect time by BigLug
in thread setting TZ causes Date::Manip to report incorrect time by meonkeys

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.