I think I've uncoveded a bug in Date::Calc, but before I submit a bug report, I'd like some feedback.

Using the sample script below, I recieve the following output:

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

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

Notice how Delta_DHMS calculates each value, while Delta_YMDHMS shows offset from the years of difference. I can't tell if this is by design or not according to the module docs. The nearest thing I can find to an explination is this passage:

This function is based on the function "Delta_YMD()" above but additionally calculates the time difference. When a carry over from the time difference occurs, the value of "$D_d" is adjusted accordingly, thus giving the correct total date/time difference.

The Date::Calc Readme doesn't make any mention of changes regarding this function, so I don't think it's something that's been changed recently.

I guess the bottom line is, I'm not confident enough in my debugging skills to know if I've discovered a bug, am misreading the documentation, or if something is goofy on the system I'm working with. Any feedback would be greatly appreciated.

#!/usr/bin/perl use warnings; use strict; use Date::Calc qw/Time_to_Date Delta_YMDHMS Delta_DHMS Today_and_Now/; my ( $year, $month, $day, $hour, $min, $sec ) = Today_and_Now(); my ( $end_year, $end_month, $end_day, $end_hour, $end_min, $end_sec ) = ( 2004, 4, 1, 0, 0, 0 ); my @cached_today_and_now = Today_and_Now; print "Today_and_Now value: ", join('-', @cached_today_and_now), "\n"; print "End time value: 2004-4-1-0-0-0\n\n"; print 'Function |', join ( '|', map { sprintf( "%-5s", $_ ) } qw/Yrs Mons Hrs Days Mins Secs/ ), "\n"; print "-" x 49, "\n"; # The two N/As are added in to pad the results of Delta_DHMS, as it # returns two fewer values and I wanted the table to line up neatly print 'Delta_DHMS |', join ('|', (' N/A', ' N/A', map { sprintf( "%5d", $_ ) } Delta_DHMS( @cached_today_and_now, 2004, 4, 1, 0, 0, 0 ))), "\n"; print 'Delta_YMDHMS |', join ( '|', map { sprintf( "%5d", $_ ) } Delta_YMDHMS( @cached_today_and_now, 2004, 4, 1, 0, 0, 0 ) ), "\n";

In reply to 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.