Skip to content
Browse files

Apply patch for ISO parsing from https://rt.cpan.org/Public/Bug/Displ…

  • Loading branch information...
1 parent dc23589 commit 0d54e1126af23f8e61ebd872998c483ba9ed0231 @bacek committed Aug 17, 2012
Showing with 18 additions and 3 deletions.
  1. +3 −3 lib/DateTime/Format/Pg.pm
  2. +15 −0 t/parse_datetime4.t
View
6 lib/DateTime/Format/Pg.pm
@@ -26,7 +26,7 @@ DateTime::Format::Pg - Parse and format PostgreSQL dates and times
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
@@ -209,7 +209,7 @@ my $pg_dateonly_german =
#
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 ],
@@ -225,7 +225,7 @@ my $pg_timeonly =
#
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 ],
};
View
15 t/parse_datetime4.t
@@ -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');
+}

0 comments on commit 0d54e11

Please sign in to comment.
Something went wrong with that request. Please try again.