On 2010.8.22 3:31 PM, Dave Rolsky wrote:
> On Sun, 22 Aug 2010, Michael G Schwern wrote:
>
>> Or you allow fractional durations. 1 day / 1 hour = 1/24th of a day
>> (not 1
>> hour). Only when it is applied to a fixed datetime does it translate
>> back.
>> Normally something like "2010-02-10 12:00" would become "2010-02-10
>> 13:00"
>> when 1/24th of a day is added. But if the date were DST then it would
>> do...
>> uhh... something I can't quite figure out just now.
>
> What's the point of trying to do this? The result is confusing as hell
> in almost every possible case. What's (1 day / 97) for _any_ date?
14 minutes 50 seconds 43 microseconds
How did I arrive at that?
1) 1 day to a smaller unit which provides a scalar value larger than the
divisor. 24 hours is too small but 1440 minutes is good.
2) 1440 minutes / 97 is 14.84536 minutes
3) .84536 minutes is 50.7216 seconds
4) .7216 seconds is 43 microseconds
Yes, there's the leap second problem of converting from minutes to seconds,
but like I said earlier, its far better to accept that minor ambiguity that we
live with every day then for DateTime to throw up its hands and say it can't
possibly know.
DateTime tries to hold the user to a level of accuracy and precision far
beyond what the real world demands. But no library can control user
requirements. The end result is if the user has to do it the user does it
without the library's help. They'll divide days by 24 and minutes by 60.
They'll do it by hand and they'll screw it up somehow. Better for DateTime to
provide a tested and documented method for doing it the best way possible.
The layer of purity is a Good Thing, but exposing it to the user as the
primary interface is not. Perhaps DateTime::Duration can become
DateTime::Duration::Strict and DateTime::Duration becomes a subclass that's a
bit more realistic about user requirements.
> I'm not sure why the original poster wanted this. The only good use case
> I can think of would be when you have a duration of seconds only and you
> want to divide it, in which case it's not that hard to do something like:
>
> my $new_dur =
> DateTime::Duration->new( seconds => int( $dur->seconds / 25 ) );
I'm moving a bunch of stuff. I have X time to do it in. I need to make Y
trips. How fast will each trip have to be?
--
52. Not allowed to yell "Take that Cobra" at the rifle range.
-- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army
http://skippyslist.com/list/