Subject: | is there a bug in _normalize_nanoseconds_? |
I probably are not using it correctly.. but if I do:
my $a = DateTime->new(
year => 2007,
month => 3,
day => 15,
hour => 9,
minute => 30,
second => 0,
nanosecond => 880 * 1000);
my $b = DateTime->new(
year => 2007,
month => 3,
day => 15,
hour => 9,
minute => 30,
second => 1,
nanosecond => 0);
my $d = $b - $a;
$d->in_units('nanoseconds');
in debugger: x $d
0 DateTime::Duration=HASH(0x8981c04)
'days' => 0
'end_of_month' => 'wrap'
'minutes' => 0
'months' => 0
'nanoseconds' => 999120000
'seconds' => 0
I was expecting 120000 nanoseconds.. in _normalize_nanoseconds, we
start off with:
$seconds = 1;
$nanoseconds = -880000;
my $seconds = $self->{seconds} + $self->{nanoseconds} /
MAX_NANOSECONDS; -> gives 0.99988
$self->{seconds} = int( $seconds ); -> gives 0
$self->{nanoseconds} = $self->{nanoseconds} % MAX_NANOSECONDS; ->
gives 999120000
$self->{nanoseconds} -= MAX_NANOSECONDS if $seconds < 0; -> this guy
will never get run...
Am I missing something?
Thanks!
- Mag