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: 58612
Status: open
Priority: 0/
Queue: DateTime-Format-Pg

People
Owner: Nobody in particular
Requestors: whatson [...] gmail.com
Cc:
AdminCc:

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



Subject: off-by-one error in _format_fractional
Hi, The date included in the test below triggers an interesting edge case in _format_fractional. When formatted initially, the correct string is built. When this string is parsed and formatted again, there is one nanosecond difference between the dates. I believe this is due to some oddity with integer maths, though it is difficult to pin down. Testing in the debugger, the issue was resolved by changing: sprintf(".%09d", $ns) to: sprintf(".%09d", "$ns") I have attached a patch for DateTime::Format::Pg 0.16004 which makes this one-line change, and also adds a test that demonstrates the issue. Regards, Andrew Whatson
Subject: datetime_format_pg_format_fractional.diff
=== modified file 'lib/DateTime/Format/Pg.pm' --- lib/DateTime/Format/Pg.pm 2010-06-23 01:08:36 +0000 +++ lib/DateTime/Format/Pg.pm 2010-06-23 01:09:10 +0000 @@ -640,7 +640,7 @@ sub _format_fractional { my $ns = shift->nanosecond; - return $ns ? sprintf(".%09d", $ns) : '' + return $ns ? sprintf(".%09d", "$ns") : '' } sub format_time === added file 't/format_fractional.t' --- t/format_fractional.t 1970-01-01 00:00:00 +0000 +++ t/format_fractional.t 2010-06-23 01:22:26 +0000 @@ -0,0 +1,26 @@ +use strict; +use warnings; + +use Test::More tests => 1; + +use DateTime; +use DateTime::Format::Pg; + +my $dt1 = DateTime->new( + year => 2010, + month => 6, + day => 21, + hour => 10, + minute => 11, + second => 9, + nanosecond => 66727999, + time_zone => 'Australia/Brisbane', + +); + +my $ts1 = DateTime::Format::Pg->format_datetime($dt1); + +my $dt2 = DateTime::Format::Pg->parse_datetime($ts1); +my $ts2 = DateTime::Format::Pg->format_datetime($dt2); + +is($ts1, $ts2, 'fractional timestamptz was parsed/formatted correctly');
Hmm, applied your patch, and I get this error: t/format_fractional.t .. 1/1 # Failed test 'fractional timestamptz was parsed/formatted correctly' # at t/format_fractional.t line 26. # got: '2010-06-21 10:11:09.066727999+1000' # expected: '2010-06-21 10:11:09.066727998+1000' # Looks like you failed 1 test of 1. Just to be sure, what version of Perl and DateTime, DateTime::TimeZone, DateTime::Locale are you using? --d On 2010-6月-22 火 21:45:35, whatson@gmail.com wrote: Show quoted text
> Hi, > > The date included in the test below triggers an interesting edge case in > _format_fractional. When formatted initially, the correct string is > built. When this string is parsed and formatted again, there is one > nanosecond difference between the dates. > > I believe this is due to some oddity with integer maths, though it is > difficult to pin down. Testing in the debugger, the issue was resolved > by changing: > > sprintf(".%09d", $ns) > > to: > > sprintf(".%09d", "$ns") > > I have attached a patch for DateTime::Format::Pg 0.16004 which makes > this one-line change, and also adds a test that demonstrates the issue. > > Regards, > Andrew Whatson
From: whatson [...] gmail.com
You might need to run with -Ilib if you haven't installed the patched module. [andreww@kamaitachi DateTime-Format-Pg-0.16004]$ patch -p0 -i ../datetime_format_pg_format_fractional.diff patching file lib/DateTime/Format/Pg.pm patching file t/format_fractional.t [andreww@kamaitachi DateTime-Format-Pg-0.16004]$ perl t/format_fractional.t 1..1 not ok 1 - fractional timestamptz was parsed/formatted correctly # Failed test 'fractional timestamptz was parsed/formatted correctly' # at t/format_fractional.t line 26. # got: '2010-06-21 10:11:09.066727999+1000' # expected: '2010-06-21 10:11:09.066727998+1000' # Looks like you failed 1 test of 1. [andreww@kamaitachi DateTime-Format-Pg-0.16004]$ perl -Ilib t/format_fractional.t 1..1 ok 1 - fractional timestamptz was parsed/formatted correctly I'm running the following versions: perl v5.10.1 DateTime 0.55 DateTime::TimeZone 1.19 DateTime::Locale 0.45 On Tue Jun 22 22:24:59 2010, DMAKI wrote: Show quoted text
> Hmm, applied your patch, and I get this error: > > t/format_fractional.t .. 1/1 > # Failed test 'fractional timestamptz was parsed/formatted > correctly' > # at t/format_fractional.t line 26. > # got: '2010-06-21 10:11:09.066727999+1000' > # expected: '2010-06-21 10:11:09.066727998+1000' > # Looks like you failed 1 test of 1. > > Just to be sure, what version of Perl and DateTime, > DateTime::TimeZone, DateTime::Locale are > you using? > > --d > > On 2010-6月-22 火 21:45:35, whatson@gmail.com wrote:
> > Hi, > > > > The date included in the test below triggers an interesting edge
> case in
> > _format_fractional. When formatted initially, the correct string is > > built. When this string is parsed and formatted again, there is one > > nanosecond difference between the dates. > > > > I believe this is due to some oddity with integer maths, though it
> is
> > difficult to pin down. Testing in the debugger, the issue was
> resolved
> > by changing: > > > > sprintf(".%09d", $ns) > > > > to: > > > > sprintf(".%09d", "$ns") > > > > I have attached a patch for DateTime::Format::Pg 0.16004 which makes > > this one-line change, and also adds a test that demonstrates the
> issue.
> > > > Regards, > > Andrew Whatson
>
ah, oops. I'll spare you the details, but essentially my test was looking at a subdirectory, even after make clean. cool, your patch looks fine. I'll upload a new release. --d On 2010-6月-22 火 22:40:22, whatson@gmail.com wrote: Show quoted text
> You might need to run with -Ilib if you haven't installed the patched > module. > > [andreww@kamaitachi DateTime-Format-Pg-0.16004]$ patch -p0 -i > ../datetime_format_pg_format_fractional.diff > patching file lib/DateTime/Format/Pg.pm > patching file t/format_fractional.t > [andreww@kamaitachi DateTime-Format-Pg-0.16004]$ perl t/format_fractional.t > 1..1 > not ok 1 - fractional timestamptz was parsed/formatted correctly > # Failed test 'fractional timestamptz was parsed/formatted correctly' > # at t/format_fractional.t line 26. > # got: '2010-06-21 10:11:09.066727999+1000' > # expected: '2010-06-21 10:11:09.066727998+1000' > # Looks like you failed 1 test of 1. > [andreww@kamaitachi DateTime-Format-Pg-0.16004]$ perl -Ilib > t/format_fractional.t > 1..1 > ok 1 - fractional timestamptz was parsed/formatted correctly > > I'm running the following versions: > > perl v5.10.1 > DateTime 0.55 > DateTime::TimeZone 1.19 > DateTime::Locale 0.45 > > On Tue Jun 22 22:24:59 2010, DMAKI wrote:
> > Hmm, applied your patch, and I get this error: > > > > t/format_fractional.t .. 1/1 > > # Failed test 'fractional timestamptz was parsed/formatted > > correctly' > > # at t/format_fractional.t line 26. > > # got: '2010-06-21 10:11:09.066727999+1000' > > # expected: '2010-06-21 10:11:09.066727998+1000' > > # Looks like you failed 1 test of 1. > > > > Just to be sure, what version of Perl and DateTime, > > DateTime::TimeZone, DateTime::Locale are > > you using? > > > > --d > > > > On 2010-6月-22 火 21:45:35, whatson@gmail.com wrote:
> > > Hi, > > > > > > The date included in the test below triggers an interesting edge
> > case in
> > > _format_fractional. When formatted initially, the correct string is > > > built. When this string is parsed and formatted again, there is one > > > nanosecond difference between the dates. > > > > > > I believe this is due to some oddity with integer maths, though it
> > is
> > > difficult to pin down. Testing in the debugger, the issue was
> > resolved
> > > by changing: > > > > > > sprintf(".%09d", $ns) > > > > > > to: > > > > > > sprintf(".%09d", "$ns") > > > > > > I have attached a patch for DateTime::Format::Pg 0.16004 which makes > > > this one-line change, and also adds a test that demonstrates the
> > issue.
> > > > > > Regards, > > > Andrew Whatson
> >
> >