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

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

Bug Information
Severity: (no value)
Broken in:
  • 0.67
  • 0.68
Fixed in: 0.70



Subject: Zero values in %N strftime patterns are truncated
The output of the %N strftime pattern isn't the correct length when the value is 0. Here's a failing test: my $d = DateTime->new(year => 2011, second => 0); is($d->strftime('.%5N'), '.00000', 'strftime %5N'); Instead of ".00000", the string ".0" is returned.
Subject: [PATCH] [rt.cpan.org #67928] Fix strftime %N truncating leading zeros
Date: Thu, 5 May 2011 17:39:37 +0100
To: bug-DateTime [...] rt.cpan.org
From: Dagfinn Ilmari Mannsåker <ilmari [...] ilmari.org>
--- lib/DateTime.pm | 2 +- t/13strftime.t | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/DateTime.pm b/lib/DateTime.pm index 8e717e5..f309ffc 100644 --- a/lib/DateTime.pm +++ b/lib/DateTime.pm @@ -1304,7 +1304,7 @@ sub _format_nanosecs { if ( $self->{rd_nanosecs} ) { my $divide_by = 10**( 9 - $precision ); - return round( $self->{rd_nanosecs} / $divide_by ); + return sprintf("%0${precision}u", round( $self->{rd_nanosecs} / $divide_by )); } else { return '0' x $precision; diff --git a/t/13strftime.t b/t/13strftime.t index 41ac1e9..0b7e5bc 100644 --- a/t/13strftime.t +++ b/t/13strftime.t @@ -187,7 +187,7 @@ done_testing(); # %Oy XCIX __DATA__ -year => 1999, month => 9, day => 7, hour => 13, minute => 2, second => 42, nanosecond => 123456789 +year => 1999, month => 9, day => 7, hour => 13, minute => 2, second => 42, nanosecond => 012345678 %y => '99' %Y => '1999' %% => '%' @@ -207,10 +207,10 @@ year => 1999, month => 9, day => 7, hour => 13, minute => 2, second => 42, nanos %l => ' 1' %m => '09' %M => '02' -%N => '123456789' -%3N => '123' -%6N => '123457' -%10N => '1234567890' +%N => '012345678' +%3N => '012' +%6N => '012346' +%10N => '0123456780' %p => 'PM' %r => '01:02:42 PM' %R => '13:02' -- 1.7.1