Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime CPAN distribution.

Report information
The Basics
Id: 66744
Status: resolved
Priority: 0/
Queue: DateTime

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

Bug Information
Severity: Normal
Broken in: 0.66
Fixed in: 0.70



Subject: DateTime->strftime(%2N) Truncates not Rounds
I would think that we should be able to round trip 2 decimal places but this does not round trip because strftime truncates and does not round. Example that fails. $ perl -MDateTime -e 'print DateTime->from_epoch (epoch=>"1297777805.12")->strftime(q{%FT%T.%2N}), "\n";' 2011-02-15T13:50:05.11 What I expect 2011-02-15T13:50:05.12 The value is actually stored as 2011-02-15T13:50:05.119999885 which is correct to 6 places. (I still would expect 9 places) I suggest changing _format_nanosecs so that we round not trunc. -return substr( $ret, 0, $precision ); +return roundit($ret, $precision); #wrapper around Math::Round::nearest or something like it.
Subject: Re: [rt.cpan.org #66744] DateTime->strftime(%2N) Truncates not Rounds
Date: Fri, 1 Apr 2011 21:49:16 +0200
To: bug-DateTime [...] rt.cpan.org
From: "Flavio S. Glock" <fglock [...] gmail.com>
How about using string operations in from_epoch() to extract the nanoseconds: $ perl -e ' my $e = "1297777805.12"; my ($int,$frac)=split(/\./,$e); $frac=0+substr($frac."000000000",0,9); print "$frac\n"; ' 120000000 $ perl -e ' my $e = "1297777805.00012"; my ($int,$frac)=split(/\./,$e); $frac=0+substr($frac."000000000",0,9); print "$frac\n"; ' 120000 2011/3/21 Michael R. Davis via RT <bug-DateTime@rt.cpan.org>: Show quoted text
> Sun Mar 20 20:33:42 2011: Request 66744 was acted upon. > Transaction: Ticket created by MRDVT >       Queue: DateTime >     Subject: DateTime->strftime(%2N) Truncates not Rounds >   Broken in: 0.66 >    Severity: Normal >       Owner: Nobody >  Requestors: MRDVT@cpan.org >      Status: new >  Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=66744 > > > > I would think that we should be able to round trip 2 decimal places but > this does not round trip because strftime truncates and does not round. > > Example that fails. > > $ perl -MDateTime -e 'print DateTime->from_epoch > (epoch=>"1297777805.12")->strftime(q{%FT%T.%2N}), "\n";' > 2011-02-15T13:50:05.11 > > What I expect > > 2011-02-15T13:50:05.12 > > The value is actually stored as > > 2011-02-15T13:50:05.119999885 > > which is correct to 6 places. (I still would expect 9 places) > > I suggest changing _format_nanosecs so that we round not trunc. > > -return substr( $ret, 0, $precision ); > +return roundit($ret, $precision); #wrapper around Math::Round::nearest > or something like it. > >