Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime CPAN distribution.

Report information
The Basics
Id: 59331
Status: resolved
Priority: 0/
Queue: DateTime

People
Owner: Nobody in particular
Requestors: jettero [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



I could be reading the documentation wrong for ->seconds (aka in_units('seconds'); but it seems to me it should be returning the number of seconds in the duration... it doesn't. Not even close. It seems there are some missing computations in the in_units method: use strict; use warnings; use Test::More; use DateTime; { my $date1 = DateTime->new( year => 2001, month => 5, day => 10, hour => 4, minute => 3, second => 2, nanosecond => 12, time_zone => 'UTC' ); my $date2 = DateTime->new( year => 2001, month => 6, day => 12, hour => 5, minute => 7, second => 23, nanosecond => 7, time_zone => 'UTC' ); is( ($date2 - $date1)->seconds, 2855061, "roughly 285ksec"); } done_testing(); If riding in an airplane is flying, then riding in a boat is swimming. 115 jumps, 47.9 minutes of freefall, 91.6 freefall miles.
Subject: DateTime::Duration->seconds (fail)
Didn't mean to click send yet. Not even sure how that happened. Failed to set subject (trying to fix). On Tue Jul 13 18:40:22 2010, JETTERO wrote: Show quoted text
> I could be reading the documentation wrong for ->seconds (aka
Show quoted text
> is( ($date2 - $date1)->seconds, 2855061, "roughly 285ksec");
Should be 2.85 msec too. Not sure it matters in any way though. -- If riding in an airplane is flying, then riding in a boat is swimming. 115 jumps, 47.9 minutes of freefall, 91.6 freefall miles.
Subject: in_units() doesn't do what I expect.
Actually, none of these seem even remotely correct. Either in_units() doesn't do what I expect (give the duration in units specified); or it doesn't do it correctly. is( $dur->seconds, 2855061, "roughly 2.85Msec"); is( $dur->minutes, 47584, "47kmin"); is( $dur->hours, 793, "793 hours"); is( $dur->days, 33, "33 hours"); is( $dur->weeks, 4, "4 weeks"); is( $dur->months, 1, "1 moonth"); -- If riding in an airplane is flying, then riding in a boat is swimming. 115 jumps, 47.9 minutes of freefall, 91.6 freefall miles.
Subject: Re: [rt.cpan.org #59331]
Date: Thu, 15 Jul 2010 11:05:32 -0500 (CDT)
To: Paul Miller via RT <bug-DateTime [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Tue, 13 Jul 2010, Paul Miller via RT wrote: Show quoted text
> I could be reading the documentation wrong for ->seconds (aka > in_units('seconds'); but it seems to me it should be returning the
I think you are reading it wrong. The ->seconds method and ->in_units metohds are two different things. If you want to know the difference between two dates _in seconds only_, you need to use the DateTime.pm method subtract_datetime_absolute. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
I'm marking this ticket as resolved. Please don't reply or it will be re-opened. If you have further questions about DateTime, please email datetime@perl.org. Thanks, -dave
On Thu Jul 15 12:05:46 2010, autarch@urth.org wrote: Show quoted text
> I think you are reading it wrong. The ->seconds method and > ->in_units metohds are two different things.
I may be reading it wrong, but they are not different things: sub seconds { abs( $_[0]->in_units('seconds') ) } On Thu, Jul 15, 2010 at 12:06 PM, Dave Rolsky Show quoted text
> I'm marking this ticket as resolved. Please don't reply or > it will be re-opened.
Sorry for re-opening it, but if the Duration object has no ability to report the length of the duration in seconds (or whatever units you chose); I'm afraid I literally don't understand what the object is for. It seems to work in comparisons? If this isn't an actual in_units() bug, then I think it may be a pod-bug instead. While the docs do say, "One cannot in general convert between seconds, minutes, days, and months, so this class will never do so;" they also say, "Returns the length of the duration in the units [...] given as arguments." If in_units() doesn't return the length of the duration in the units given, then what is it for? -Paul -- If riding in an airplane is flying, then riding in a boat is swimming. 116 jumps, 48.6 minutes of freefall, 92.9 freefall miles.
Subject: Re: [rt.cpan.org #59331]
Date: Thu, 15 Jul 2010 12:50:05 -0500 (CDT)
To: Paul Miller via RT <bug-DateTime [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Thu, 15 Jul 2010, Paul Miller via RT wrote: Show quoted text
> On Thu Jul 15 12:05:46 2010, autarch@urth.org wrote:
>> I think you are reading it wrong. The ->seconds method and >> ->in_units metohds are two different things.
> > I may be reading it wrong, but they are not different > things: > > sub seconds { abs( $_[0]->in_units('seconds') ) }
Well, that looks different to me but ... Show quoted text
> Sorry for re-opening it, but if the Duration object has no > ability to report the length of the duration in seconds (or > whatever units you chose); I'm afraid I literally don't > understand what the object is for.
Have you read the DateTime.pm docs in detail? It explains some of this. The simplified version is that given a duration of "4 months, 1 day, 2 hours", there is no way to know how many seconds that represents. If you want the difference in seconds, you can use the method I suggested. Or you can just argue with me if that's more fun for you, but I may stop participating in the argument ;) Show quoted text
> If in_units() doesn't return the length of the duration in > the units given, then what is it for?
It returns the duration in X units. So a duration could be 2 months, 3 days, 4 hours, and 5 seconds. There's no way to determine a length in seconds from that. Please stop re-opening this ticket. If you want to discuss it further, email datetime@perl.org. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/