[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Date::Calc



In the debugger after

use Date::Calc qw( Today Add_Delta_YMD );

-----------
  DB<3> x Today
0  2004
1  7
2  31
  DB<4> x Add_Delta_YMD(Today, 0, -1, 0)
0  2004
1  7
2  1
-----------

That was not what I was expecting. I guess I was expecting 2004 6 30?

j

from perldoc Date::Calc

---------------------------
       o "($year,$month,$day) = Add_Delta_YMD($year,$month,$day,
         $Dy,$Dm,$Dd);"

         This function serves to add a years, months and days
         offset to a given date.

         (In order to add a weeks offset, simply multiply the
         weeks offset with ""7"" and add this number to your days
         offset.)

         Note that the three offsets for years, months and days
         are applied independently from each other. This also
         allows them to have different signs.

         The years and months offsets are applied first, and the
         days offset is applied last.

         If the resulting date happens to fall on a day after the
         end of the resulting month, like the 32nd of April or
         the 30th of February, then the date is simply counted
         forward into the next month (possibly also into the next
         year) by the number of excessive days (e.g., the 32nd of
         April will become the 2nd of May).

         BEWARE that this behaviour differs from that of previous
         versions of this module! In previous versions, the day
         was simply truncated to the maximum number of days in
         the resulting month.

         If you want the previous behaviour, use the new function
         ""Add_Delta_YM()"" (described immediately above) plus
         the function ""Add_Delta_Days()"" instead.

         BEWARE also that because a year and a month offset is
         not equivalent to a fixed number of days, the transfor-
         mation performed by this function is NOT ALWAYS
         REVERSIBLE!

         This is in contrast to the functions
         ""Add_Delta_Days()"" and ""Add_Delta_DHMS()"", which are
         fully and truly reversible (with the help of the func-
         tions ""Delta_Days()"" and ""Delta_DHMS()"", for
         instance).

         Note that for this same reason,

           @date = Add_Delta_YMD(
                   Add_Delta_YMD(@date, $Dy,$Dm,$Dd), -$Dy,-$Dm,-$Dd);

         will in general NOT return the initial date ""@date"".

         Note that this is NOT a program bug but NECESSARILY so
         because of the variable lengths of years and months!
------------------

I guess I want Delta_YM instead?

It's hard to report bugs when authors keep accurately documenting
behaviors. -grin-

j