Both Delta_DHMS() and Delta_YMDHMS() correspond to their companion functions Add_Delta_DHMS() and Add_Delta_YDHMS(). In both cases, the results from Delta_* can be passed to the Add_Delta_* function, along with the first date, in order to get the second date. Accordingly, the complimentary operation is supported if you reverse the sign of each value of the delta and pass to Add_Delta_* along with the second date.

From the POD:

In any case, adding the result of this function to the first date/time + value ($year1,$month1,$day1, $hour1,$min1,$sec1) always gives the se +cond date/time value ($year2,$month2,$day2, $hour2,$min2,$sec2) again +, and adding the negative result (all elements of the result vector n +egated) to the second date/time value gives the first date/time value +.

As you can see, the specification for what Delta_YMDHMS() and Delta_DHMS() return is defined in terms of complimentary operations, not any particular representation of values. So in your example (hr/day labels fixed):

Today_and_Now value: 2003-12-1-14-52-15
     End time value: 2004-4-1-0-0-0

Function     |Yrs  |Mons |Days |Hrs  |Mins |Secs
-------------------------------------------------
Delta_DHMS   |  N/A|  N/A|  121|    9|    7|   45
Delta_YMDHMS |    1|   -8|    0|  -14|  -52|  -15

Add_Delta_YMDHMS() (no modulo, no carry):

  original: 2003 |  12 |   1 |  14 |  52 |  15
+    delta:    1 |  -8 |   0 | -14 | -52 | -15
-------------------------------------------------
       end: 2004 |   4 |   1 |   0 |   0 |   0
-    delta:    1 |  -8 |   0 | -14 | -52 | -15
-------------------------------------------------
  original: 2003 |  12 |   1 |  14 |  52 |  15

Add_Delta_DHMS() (modulo, columnar carry, calendrical):

      math:|   calendrical   |mod24|mod60|mod60
-------------------------------------------------
  original:       2003-12-01 |  14 |  52 |  15
+    delta:              121 |   9 |   7 |  45
-------------------------------------------------
       end:       2004-04-01 |   0 |   0 |   0
-    delta:              121 |   9 |   7 |  45
-------------------------------------------------
  original:       2003-12-01 |  14 |  52 |  15

As you can see, there's no actual calendrical or modulo/carrying calculations going on with Delta_YMDHMS(). Delta_DHMS(), on the other hand, does do it that way.

Nowhere in the documentation does it state that the Delta_* functions perform their arithmetic in the same fashion, or represent their results the same way. They are merely guaranteed to provide symmetry for the Add_Delta_* functions.

Matt


In reply to Re^3: Unexplained Behavior in Date::Calc by mojotoad
in thread Unexplained Behavior in Date::Calc by jpfarmer

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.