Subject: | [Patch] Documentation bug, plus parsing strict ISO8601 timestamps |
Date: | Tue, 03 Nov 2009 14:54:47 +0100 |
To: | bug-DateTime-Format-Pg [...] rt.cpan.org |
From: | Knut Arne Bjørndal <knut.arne.bjorndal [...] easyconnect.no> |
Message body not shown because it is not plain text.
The synopsis erroneously indicate the output format of format_datetime
will be 2003-01-16T23:12:01+0200 when it will in fact output 2003-01-16
23:12:01
The attached patch fixes this bug, and also adds support for parsing
timestamps including the T.
Also includes a unit test.
--
Knut Arne Bjørndal, Tekniker Easy Connect AS - http://1890.no
E-post: knut.arne.bjorndal@easyconnect.no Tlf: 53 20 53 25
diff -urN DateTime-Format-Pg-0.16004.orig/lib/DateTime/Format/Pg.pm DateTime-Format-Pg-0.16004/lib/DateTime/Format/Pg.pm
--- DateTime-Format-Pg-0.16004.orig/lib/DateTime/Format/Pg.pm 2009-07-06 04:43:39.000000000 +0200
+++ DateTime-Format-Pg-0.16004/lib/DateTime/Format/Pg.pm 2009-11-03 14:32:19.000000000 +0100
@@ -27,7 +27,7 @@
my $dt = DateTime::Format::Pg->parse_datetime( '2003-01-16 23:12:01' );
- # 2003-01-16T23:12:01+0200
+ # 2003-01-16 23:12:01
DateTime::Format::Pg->format_datetime($dt);
=head1 DESCRIPTION
@@ -210,7 +210,7 @@
#
my $pg_timeonly =
{
- regex => qr/^(\d{2,}):(\d{2,}):(\d{2,})(\.\d+)? *([-\+][\d:]+)?$/,
+ regex => qr/^T?(\d{2,}):(\d{2,}):(\d{2,})(\.\d+)? *([-\+][\d:]+)?$/,
params => [ qw( hour minute second nanosecond time_zone) ],
extra => { year => '1970' },
postprocess => [ \&_fix_timezone, \&_fix_nanosecond ],
@@ -226,7 +226,7 @@
#
my $pg_datetime_iso =
{
- regex => qr/^(\d{4,})-(\d{2,})-(\d{2,}) (\d{2,}):(\d{2,}):(\d{2,})(\.\d+)? *([-\+][\d:]+)?( BC)?$/,
+ regex => qr/^(\d{4,})-(\d{2,})-(\d{2,})[ T](\d{2,}):(\d{2,}):(\d{2,})(\.\d+)? *([-\+][\d:]+)?( BC)?$/,
params => [ qw( year month day hour minute second nanosecond time_zone era) ],
postprocess => [ \&_fix_era, \&_fix_timezone, \&_fix_nanosecond ],
};
diff -urN DateTime-Format-Pg-0.16004.orig/t/parse_datetime4.t DateTime-Format-Pg-0.16004/t/parse_datetime4.t
--- DateTime-Format-Pg-0.16004.orig/t/parse_datetime4.t 1970-01-01 01:00:00.000000000 +0100
+++ DateTime-Format-Pg-0.16004/t/parse_datetime4.t 2009-11-03 14:44:02.000000000 +0100
@@ -0,0 +1,15 @@
+# $Id$
+use Test::More tests => 8;
+use DateTime::Format::Pg 0.02;
+
+{
+ my $dt = DateTime::Format::Pg->parse_datetime('2003-01-02T19:18:17.123+09:30');
+ is($dt->year(), 2003, 'year');
+ is($dt->month(), 01, 'month');
+ is($dt->day(), 02, 'day');
+ is($dt->hour(), 19, 'hour');
+ is($dt->minute(), 18, 'minute');
+ is($dt->second(), 17, 'second');
+ is($dt->nanosecond(), 123000000, 'nanosecond');
+ is($dt->offset(), (9*60+30)*60, 'tz offset');
+}