Hello Monks after a wee while. Well, I have a weird situation with DateTime::Duration when I am adding values of the format [hh:mm::ss] together. The normalization of the seconds into minutes after 59 seems to be not doing what should exactly be done when the total of the seconds is over 59. In my case seconds just get added up well beyond this rather than be converted to minutes. However, minutes seamlessly get converted into hours with no glitches. I tried a few tricks in the documentation of DateTime::Duration regarding the addition of [hh:mm::ss] values but all producing the same result.

Is this a behavior to expect with this module ? or it got to do with the way I wrote my program. And since it is one of the very robust modules out there I still saw that many other similar modules offering date and time calculation don't weigh in such straightforward additions and subtraction of values

Here's a functioning code that reproduces the case I am describing. After adding up all the hh:mm::ss values I get this output Total Time: 11:57:300

use strict; use warnings; use DateTime::Duration; my $duration = DateTime::Duration->new(); while(<DATA>){ chomp; my ($hour, $minute, $second); my @time = split(':',$_); if(scalar @time == 3){ ($hour, $minute, $second) = @time; $duration->add(hours=>$hour, minutes=>$minute, seconds=>$secon +d); }elsif(scalar @time == 2){ $hour =0; ($minute, $second) = @time; $duration->add(hours=>$hour, minutes=>$minute, seconds=>$s +econd); } } print "Total Time: ", join(':',$duration->in_units('hours', 'minutes', +'seconds')),$/; __DATA__ 5:43:05 01:18 11:25 36:31 17:14 20:14 07:55 06:50 00:40 23:33 1:18:02 2:55:13

David R. Gergen said "We know that second terms have historically been marred by hubris and by scandal." and I am a two y.o. monk today :D, June,12th, 2011...

In reply to DateTime::Duration not adding seconds appropriately by biohisham

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.