On Fri, 3 Oct 2003, Eugene van der Pijll wrote:
> Neither DateTime::Format::Excel nor DateTime::Event::Sunrise pass their
> own tests. They were both broken when the subtraction in DateTime
> changed, from returning days and seconds to returning y,m,d, h,m,s.
>
> DT::E::Sunrise uses the subtraction in its function
> days_since_2000_Jan_0(), and DT::F::Excel in format_datetime(). Both
> then call delta_days to see how many days have passed; this is now
> broken.
>
> There should probably an option in DateTime::subtract_datetime() to
> specify which units should be returned. For example:
>
> $dt1->subtract_datetime( $dt2,
> [ 'months', 'days', 'minutes', 'seconds' ] );
>
> would be equivalent to the current behaviour;
>
> $dt1->subtract_datetime( $dt2, [ 'days', 'seconds' ] );
>
> is the old version, that would be used by the two modules I mentioned
> (or:
>
> $dt1->subtract_datetime( $dt2, [ 'days' ] );
>
> as the seconds value is not used;
>
> $dt1->subtract_datetime( $dt2, [ 'seconds' ] );
>
> is equivalent to subtract_datetime_absolute().
>
> Would this be easy to implement?
It's not hard, just a little bit of math. I'm more concerned with the
API. I don't like the one you have up there, but I don't want to just
change the existing syntax either, maybe something like:
$dt1->subtract_datetime( $dt2 ); # current behavior
$dt1->subtract_datetime( datetime => $dt2,
units => [ qw( days minutes nanoseconds ) ] );
-dave
/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/