Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer nanoseconds #15

Merged
merged 3 commits into from May 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/DateTime/Format/Pg.pm
Expand Up @@ -368,7 +368,7 @@ sub _fix_timezone {
sub _fix_nanosecond {
my %args = @_;
if(defined $args{'parsed'}->{'nanosecond'}) {
$args{'parsed'}->{'nanosecond'} *= 1.0E9;
$args{'parsed'}->{'nanosecond'} = sprintf '%.0f', $args{'parsed'}->{'nanosecond'} * 1.0E9;
} else {
delete $args{'parsed'}->{'nanosecond'}
};
Expand Down
10 changes: 10 additions & 0 deletions t/parse_datetime5.t
@@ -0,0 +1,10 @@
use Test::More tests => 1;
use DateTime::Format::Pg 0.02;

# This test fails when nanosecond is not converted properly to an integer. This
# happens when the fractional part of timestamp is .254182 - got this number by
# experiment.
{
my $dt = DateTime::Format::Pg->parse_datetime('2017-05-02 12:39:10.254182+00');
cmp_ok($dt->nanosecond(), '==', 254182000, 'nanosecond as a number');
}