Subject: | Comparison of two DT objects with nanoseconds sometimes fails |
Hi,
for quite a while I have been observing some weird behavior in the
DateTime::Format::CLDR test suite which most likely originates from
DateTime.
I have written a test case
(http://cpansearch.perl.org/src/MAROS/DateTime-Format-CLDR-1.10/t/011_nanosecond.t
and
http://cpansearch.perl.org/src/MAROS/DateTime-Format-CLDR-1.10/t/lib/testlib.pm)
which generates a DateTime object with nanoseconds, prints it out,
parses the output, returns a new DateTime object and then finally
compares the two objects (via DateTime->compare_ignore_floating).
However this test *sometimes* fails (according to cpan testers - however
I have never experienced such a test failure myself). The stringified DT
objects look exactly the same, but nonetheless compare_ignore_floating
returns false.
Here are some reported test failures:
http://www.cpantesters.org/cpan/report/6711070
http://www.cpantesters.org/cpan/report/5583764
http://www.cpantesters.org/cpan/report/5373996
http://www.cpantesters.org/cpan/report/5374015
So far I was not able to narrow the problem down to a certain OS/Perl
version/32-64bit/DateTime version/DT::Format::CLDR version ...
For now I'd suggest adding the following test to DateTime' 07compare test:
# sub-second equals
{
my $date1 = DateTime->new( year => 2000, month => 10, day => 24,
hour => 12, minute => 0, second => 0,
nanosecond => 10000,
);
my $date2 = DateTime->new( year => 2000, month => 10, day => 24,
hour => 12, minute => 0, second => 0,
nanosecond => 10000,
);
is( DateTime->compare( $date1, $date2 ), 0, 'Comparison with
floating time (cmp)' );
is( ($date1 <=> $date2), 0, 'Comparison with floating time (<=>)' );
is( ($date1 cmp $date2), 0, 'Comparison with floating time (cmp)' );
is( DateTime->compare_ignore_floating($date1, $date2), 0,
'Comparison with compare_ignore_floating (cmp)' );
}
Cheers
Maros