On Fri, 11 Oct 2003, Rick Measham wrote:

> > But some people have indicated that they'd like something a little
> > more flexible.  Eugene van der Pijll suggested something like this:
> >
> >  my $dur = $dt1->difference( datetime => $dt2,
> >                              units    => [ 'months', 'days' ] );
> >
> > This would return a duration which only included month and day values,
> > without minutes, seconds, or nanoseconds.
>
> $dt1 = 2003-05-15 19:23:33;
> $dt2 = 2003-04-01 00:00:00;
> my $dur = $dt1->difference( datetime => $dt2,
>                             units    => [ 'months', 'days' ] );
>
> So do we now have:
> 1 month, 15 days
> or:
> 1 month, 15 days, 19 hours, 23 minutes, 33 seconds
> or:
> 1 month, 15 days, 68400 seconds

 1 month, 15 days

> > It seems to me that these 3 cover all the important possibilities, and
> > they have a nice simple API.
>
> Looks good to me ... however for _standard_ subtraction I'd like it
> stored the way I think about it:
>
> 2004-04-11 - 2003-04-20 = 1 year, -9 days.
>
> I know this breaks some of the internal logic so far as 'if one element
> is negative, it's a negative duration', but I still think of the
> difference in terms of the individual units.

Hmm, that just seems a little too confusing.  It's a lot easier to explain
that the difference will always be all negative or positive, and I think
it makes it easier to work with.

> Also, I said this a while back so skip it if you're bored:
>
> I'd like a 'normalise' (*normalize = \&normalise) function so that:
>
> (1 year, -9 days)->normalise(2004-04-11) = (1 year, 11 months, 22 days)
>
> and:
> (45 days)->normalise(2004-04-11) = (1 month, 15 days);
> (45 days)->normalise(2004-05-11) = (1 month, 14 days);
>
> (45 days)->normalise(2003-02-01) = (1 month, 17 days);
> (45 days)->normalise(2004-02-01) = (1 month, 16 days);

This is certainly doable.  Instead of converting the duration I'd probably
want to return a new one.


-dave

/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/

Reply via email to