Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime-Format-Pg CPAN distribution.

Report information
The Basics
Id: 68473
Status: resolved
Priority: 0/
Queue: DateTime-Format-Pg

People
Owner: Nobody in particular
Requestors: CMCKAY [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Postgresql 'date' types now support the infinity value
As of postgresql 8.4 the infinity value has been changed from just timestamp to be a date as well. This means that for a 'date' type column 'infinity' and '-infinity' are valid values, like for the 'datetime' columns. Currently the formatter thinks it has a badly formatted date when fed 'infinity' into parse_date. I've attached a patch that fixes this and adds tests to support. Let me know if theres anything more that needs to be done to support this. Thanks -Chris
Subject: DateTime-Format-Pg.infinity_dates.patch
diff -ru datetime2/DateTime-Format-Pg-0.16005/lib/DateTime/Format/Pg.pm DateTime-Format-Pg-0.16005//lib/DateTime/Format/Pg.pm --- datetime2/DateTime-Format-Pg-0.16005/lib/DateTime/Format/Pg.pm 2010-06-23 13:14:19.000000000 +1000 +++ DateTime-Format-Pg-0.16005//lib/DateTime/Format/Pg.pm 2011-05-25 17:17:55.543671961 +1000 @@ -373,7 +373,7 @@ parsers => { parse_date => [ $pg_dateonly_iso, $pg_dateonly_sql, - $pg_dateonly_german, ], + $pg_dateonly_german, $pg_infinity ], parse_timetz => [ $pg_timeonly, ], parse_timestamptz => [ $pg_datetime_iso, $pg_datetime_pg_eu, $pg_datetime_pg_us, $pg_datetime_sql, @@ -693,7 +693,9 @@ sub format_date { my ($self,$dt) = @_; - if($dt->year()<=0) { + if($dt->is_infinite) { + return $dt->isa('DateTime::Infinite::Future') ? 'infinity' : '-infinity'; + } elsif($dt->year()<=0) { return sprintf('%04d-%02d-%02d BC', 1-$dt->year(), $dt->month(), diff -ru datetime2/DateTime-Format-Pg-0.16005/t/format_date.t DateTime-Format-Pg-0.16005//t/format_date.t --- datetime2/DateTime-Format-Pg-0.16005/t/format_date.t 2009-07-06 12:41:07.000000000 +1000 +++ DateTime-Format-Pg-0.16005//t/format_date.t 2011-05-25 17:20:26.676421384 +1000 @@ -1,5 +1,5 @@ # $Id: format_date.t 1039 2003-05-30 14:04:49Z cfaerber $ -use Test::More tests => 3; +use Test::More tests => 5; use DateTime 0.10; use DateTime::Format::Pg 0.02; @@ -24,3 +24,13 @@ my $dt = DateTime->new( %{$tests{$result}} ); is( DateTime::Format::Pg->format_date($dt), $result ); } + +is( + DateTime::Format::Pg->format_date(DateTime::Infinite::Future->new), + 'infinity' +); + +is( + DateTime::Format::Pg->format_date(DateTime::Infinite::Past->new), + '-infinity' +); diff -ru datetime2/DateTime-Format-Pg-0.16005/t/parse_infinity.t DateTime-Format-Pg-0.16005//t/parse_infinity.t --- datetime2/DateTime-Format-Pg-0.16005/t/parse_infinity.t 2009-07-06 12:41:07.000000000 +1000 +++ DateTime-Format-Pg-0.16005//t/parse_infinity.t 2011-05-25 17:19:33.484157621 +1000 @@ -1,5 +1,5 @@ # $Id: parse_infinity.t 1061 2006-01-07 00:45:49Z lestrrat $ -use Test::More tests => 4; +use Test::More tests => 6; use DateTime::Format::Pg 0.02; { @@ -8,6 +8,11 @@ } { + my $dt = DateTime::Format::Pg->parse_date('infinity'); + isa_ok($dt, 'DateTime::Infinite::Future'); +} + +{ my $dt = DateTime::Format::Pg->parse_timestamp('infinity'); isa_ok($dt, 'DateTime::Infinite::Future'); } @@ -17,6 +22,11 @@ isa_ok($dt, 'DateTime::Infinite::Past'); } +{ + my $dt = DateTime::Format::Pg->parse_date('-infinity'); + isa_ok($dt, 'DateTime::Infinite::Past'); +} + { my $dt = DateTime::Format::Pg->parse_timestamp('-infinity'); isa_ok($dt, 'DateTime::Infinite::Past');
Thanks, applied and shipped as 0.16006