Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: DateTime::Duration not adding seconds appropriately

by ww (Archbishop)
on Sep 01, 2013 at 11:57 UTC ( [id://1051784]=note: print w/replies, xml ) Need Help??


in reply to DateTime::Duration not adding seconds appropriately

There's definitely a doc_smell here, but could the part I've emphasized (from perldoc DateTime:Duration) the documentation for this problem?

$dur->in_units( ... )
  Returns the length of the duration in the units (any of those that can
  be passed to "new") given as arguments. All lengths are integral, but
  may be negative. Smaller units are computed from what remains after
  taking away the larger units given, so for example:

    my $dur = DateTime::Duration->new( years => 1, months => 15 );

    $dur->in_units( 'years' );            # 2
    $dur->in_units( 'months' );           # 27
    $dur->in_units( 'years', 'months' );  # (2, 3)
    $dur->in_units( 'weeks', 'days' );    # (0, 0) !

  The last example demonstrates that there will not be any conversion
  between units which don't have a fixed conversion rate. 
The only conversions possible are:

  *       years <=> months

  *       weeks <=> days

  *       hours <=> minutes

  *       seconds <=> nanoseconds

  For the explanation of why this is the case, please see the How DateTime
  Math Works section of the DateTime.pm documentation

My speculation here seems almost non-sensical ... except for the module author's repeated comment, "...if you are trying to generate output suitable for humans, use the "DateTime::Format::Duration" module."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1051784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found