I'm afraid I have to disagree here. I fail to see why 'switch to DateTime' is the correct answer.

The fact of the matter is that 1 hour before 1:00 AM on a certain date was also 1:00 AM. Date::Manip is doing it right. The reason that the information doesn't look right is that the date is only partially being printed out (i.e. no timezone information).

You could always print out the dates as timestamps (seconds since the epoch) or you could print the date in UTC time (which doesn't use daylight saving time), or there are alternate answers depending on what you're really trying to do.

As for the second question (i.e. subtract one day), the answer is a bit trickier. The problem really is 'what do you mean by 1 day ago'. If you say 'the same time the day before', that's ambiguous twice a year. When you move the clock back (as we just did), the time 1:00 AM to 2:00 AM happens twice, so if you start at 1:30 AM the day after and move back 1 day, do you mean 1:30 AM in standard time or saving time? Worse, when you move the clock forward, you bypass 1:00 AM to 2:00 AM, so if you start at 1:30 AM the following day and move back 1 day, if you specify 1:30 AM, you have an invalid date.

Date::Manip defines a day as 24 hours which DOES lead to unexpected results... but it DOES lead to unambiguous and correct results.

It would be possible to come up with another definition for '1 day'... and I'm definitely considering it (just as soon as I have a definition which is meaningful and useful)..

So, again, I'm sorry. The correct answer is NOT to switch to DateTime. The correct answer is to figure out what you really want, and then do it. I assure you that both Date::Manip and DateTime are flexible enough to do what you want.


In reply to Re^3: Date::Manip and daylight savings by SBECK
in thread Date::Manip and daylight savings by ChrisDennis

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.