Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^9: Date::Manip and daylight savings

by SBECK (Pilgrim)
on Nov 08, 2011 at 18:44 UTC ( #936850=note: print w/ replies, xml ) Need Help??


in reply to Re^8: Date::Manip and daylight savings
in thread Date::Manip and daylight savings

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.


Comment on Re^9: Date::Manip and daylight savings
Re^10: Date::Manip and daylight savings
by ikegami (Pope) on Nov 08, 2011 at 19:49 UTC

    We're discussing an amount of time.

    I wasn't discussing anything, I was asking a question.

    so 2007-11-07 plus one year is 2008-11-07.

    Thanks. That's 366 days, so DM actually handles years properly.

    I don't have an answer for months, but I'm going to assume they're handle properly (Jan 1st + 1 month = Feb 1st).

    I don't have a crystal clear answer for days, but it sounds like days aren't handled properly — It's possible to add a day without a date change or add a day and have the date change by two days — and it's slated to be fixed.

    It could be interesting to study the differences between DT and DM wrt the corner cases, but it's not what I was asking, and any interest and time I might have had has waned.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://936850]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-12-26 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (164 votes), past polls