I'm not avoiding answering the question. I thought I DID answer the question. I'll try again... but please remain civil in your reply or I'll probably drop out of this conversation.

Can Date::Manip add a year or only 365 days? I clearly stated that Date::Manip would add a year the same as TimeDate. So yes, Date::Manip can add either a year OR 365 days. The results are identical for Date::Manip and TimeDate except for the case that I cited (i.e. starting on Feb 29 on a leap year) so 2007-11-07 plus one year is 2008-11-07. The two modules differ only in the case of leap year.

Actually, a year of a date is quite well defined. In 2011-11-08, 2011 is the year.

True, but not relevant to the discussion. We're discussing an amount of time. The actual date is irrelevant except for the fact that the date does impacts how we think of the amount of time. That's why this is all so hard... the amount of time is not defined in a mathematical way, it's defined in a human-perspective way which is definitely not simple to enumerate. The example of adding a year is a simple example though. What does it mean to add a year to 2004-02-29. The answer is obviously not to add 365 or 366 days, and the answer is NOT just to modify the year field, because then you'd end up with 2005-02-29 which is not valid, so adding an amount of time is not a simple operation.

It appears that the operation to add a year to a date for DateTime is as follows. Increment the year. If the resulting date is invalid (which only happens in the case of leap years), move forward the number of days you're off by. This is supported by the fact that Jan 31 + 1 month = Mar 3.

The operation used by Date::Manip is different. Increment the year. If the resulting date is invalid, drop back to the last valid date. The advantage is that the month is preserved (you can basically think that I went from the last day in February 2004 to the last day in February 2005). In a similar fashion, Jan 31 plus 1 month is Feb 28 (or 29).

So Date::Manip can add years, months, weeks, hours, minutes, and seconds in a similar (though not identical) fashion as DateTime. Days is the only one where we differ significantly, and I'm working on that now (I'd been intending to add this... and this discussion has pushed this to the forefront). However, here too, the results won't be the same because I'll use a operation (for example, it won't ever return an empty date).

I'll be happy to clarify any points that are not clear.


In reply to Re^9: 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.