Subject: | Default stringification of DateTime::Infinite types does not format correctly (root cause of install failures) |
Using DateTime v0.2901 in Perl v5.8.6 under Genoo Linux 2.6.14.
Stringinfying a DateTime::Infinity::Future results in '-0001--01--01T-01:-01:-01' and a DateTime::Infinity::Past results in '-2147483648--2147483648--2147483648T-2147483648:-2147483648:-2147483648'. This also causes the installation to fail since the is() used by tests 17 and 18 in 20infinite.t uses eq to compare the values (did that change between Test::More 0.46 and now?). The install failure may be a separate issue since that section of the tests appears to be intended to do numeric tests.
Code to reproduce:
use DateTime;
my $pos = DateTime::Infinite::Future->new;
my $neg = DateTime::Infinite::Past->new;
print "$pos\t$neg\n";
This outputs the values I mentioned above.
Proposed solution:
Add a formatter for the Infinite types which explicitly formats the stringification. This should correct all platforms treatment of inf -
package DateTime::Infinte;
sub format_datetime {
my $self = shift;
return $self->{utc_rd_days};
}
And include it in the constructors:
<snip>
tz => DateTime::TimeZone->new( name => 'floating' ),
formatter => 'DateTime::Infinite', #add this
}, __PACKAGE__;
<snip>
Also, add tests to handle the numeric verification:
ok($pos == $posinf, "infinity (datetime) == infinity (number)");
ok($neg == $neginf, "neg infinity (datetime) == neg infinity (number)");
and change the descriptions on the current tests to indicate they are work on the stringified values.