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

People
Owner: CFAERBER [...] cpan.org
Requestors: MARKSTOS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.05
Fixed in: 0.060



Subject: format_datetime silently truncates sub-second digits
Hello, format_datetime() is silently truncating times to seconds, although the timestamp field in Postgres supports greater precision from this. There should at least be a warning that some data-loss is occuring, although ideally this can be fixed to preserve the precision as much as possible.
Subject: [PATCH] format_datetime silently truncates sub-second digits
From: markstos [...] cpan.org
Well, that was a lot easier to patch than I thought it might be. The below patch works for me. I tested it with and without dates that include nanosecond values. Below the patch I've included a simple script to illustrate it working. ################# --- /usr/local/lib/perl5/site_perl/5.8.0/DateTime/Format/Pg.pm Wed Jul 16 08:46:20 2003 +++ DateTime/Format/Pg.pm Tue Jun 8 15:12:43 2004 @@ -801,10 +801,12 @@ $dt->day()). ' '. $dt->hms(':'). + '.'.$dt->nanosecond. ($self->_format_time_zone($dt)). ' BC'; } else { return $dt->ymd('-').' '.$dt->hms(':'). + '.'.$dt->nanosecond. ($self->_format_time_zone($dt)); } } ####################### require DateTime::HiRes; my $dt = DateTime::HiRes->now(); require DateTime::Format::Pg; print "ns: ", $dt->nanosecond,"\n"; print DateTime::Format::Pg->format_datetime($dt);
From: Claus Färber
[guest - Tue Jun 8 16:17:24 2004]: Show quoted text
> + '.'.$dt->nanosecond. > ($self->_format_time_zone($dt)). > ' BC'; > } else { > return $dt->ymd('-').' '.$dt->hms(':'). > + '.'.$dt->nanosecond. > ($self->_format_time_zone($dt)); > } > }
What if $dt->nanosecond is "123" (or another value representing a fractional second between 0.000000000 and 0.099999999)? No, it has to be done differently.
[mark@summersault.com - Mon Jun 21 09:10:09 2004]: Show quoted text
> Should really be paddd with zeros, like: > 0000000123
Well, "123 nanoseconds" is "0.000000123 seconds", not "0.123" seconds. The bug is fixed in version 0.060.