It seems consistent and logical to normalize nanoseconds when
multiplying durations. There is also a comment about normalization that
seems both redundant and misleading (since comparison doesn't depend on
nanoseconds being normalized; I assume comparison used to be done
without a reference time).
Although, looking at _normalize_nanoseconds and the tests for it, I
don't understand the sense of "normalizing" to (-1, 1) at all.
Andrew
--- lib/DateTime/Duration.pm.orig 2003-11-14 22:13:52.000000000 -0500
+++ lib/DateTime/Duration.pm 2004-02-09 21:56:16.000000000 -0500
@@ -162,7 +162,6 @@
$self->{$_} += $dur->{$_};
}
- # we might have to normalize_nanoseconds before comparing durations
$self->_normalize_nanoseconds if $self->{nanoseconds};
return $self;
@@ -194,6 +193,8 @@
$self->{$_} *= $multiplier;
}
+ $self->_normalize_nanoseconds if $self->{nanoseconds};
+
return $self;
}
--- t/11duration.t.orig 2004-02-09 22:00:36.000000000 -0500
+++ t/11duration.t 2004-02-09 22:02:08.000000000 -0500
@@ -2,7 +2,7 @@
use strict;
-use Test::More tests => 86;
+use Test::More tests => 88;
use DateTime;
use DateTime::Duration;
@@ -163,6 +163,12 @@
$new2->subtract( nanoseconds => 100000000 );
is( $new2->delta_nanoseconds, 100300400, 'sub nanoseconds works' );
+
+ my $new3 = $dur2 * 3;
+
+ is( $new3->delta_seconds, 4, 'seconds normalized after multiplication');
+ is( $new3->delta_nanoseconds, 500000000,
+ 'nanoseconds normalized after multiplication' );
}
{