[Omaha.pm] Date::Calc

Miller, Scott L (Omaha Networks) scott.l.miller at hp.com
Mon Aug 2 10:08:15 CDT 2004


Yes, it's behaving correctly because 6/31, since there are only 30 days in June, becomes 7/1.  So, yes you want the truncated version.  

BTW, I'm glad you're using Date::Calc, I looked at Date::Manip, which I think you wrote about a couple weeks ago.  Although I'm impressed with the scope of Date::Manip, I particularly found the following lines from the documentation to be quite effective in making me look at other packages available:

   SHOULD I USE DATE::MANIP

   If you look in CPAN, you'll find that there are a number of Date and Time packages. Is Date::Manip the one you should be using? In my opinion, the answer is no most of the time. This sounds odd coming from the author of the software, but read on.


I needed to be able to find the 2nd Wednesday of each month, Date::Calc was the package I settled on.

-Scott

-----Original Message-----
From: omaha-pm-bounces at pm.org [mailto:omaha-pm-bounces at pm.org]On Behalf
Of Jay Hannah
Sent: Saturday, July 31, 2004 9:55 AM
To: omaha-pm at pm.org
Subject: [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



_______________________________________________
Omaha-pm mailing list
Omaha-pm at pm.org
http://www.pm.org/mailman/listinfo/omaha-pm




More information about the Omaha-pm mailing list