Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime-Format-Strptime CPAN distribution.

Report information
The Basics
Id: 58459
Status: resolved
Priority: 0/
Queue: DateTime-Format-Strptime

People
Owner: Nobody in particular
Requestors: alex [...] chmrr.net
Cc:
AdminCc:

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



Subject: [PATCH] '%e' and friends can include a leading space, which DateTime objects to
Date: Wed, 16 Jun 2010 13:27:21 -0400
To: bug-datetime-format-strptime [...] rt.cpan.org
From: Alex Vandiver <alex [...] chmrr.net>
Download (untitled) / with headers
text/plain 2.4k
When parsing, '%e' accepts a leading space; however, when ' 3' is passed as an argument to DateTime->new, it fails. Resolve this by forcing the arguemnts to DateTime->new to be purely numeric, by adding 0. --- lib/DateTime/Format/Strptime.pm | 18 +++++++++--------- t/002_dates.t | 6 +++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/DateTime/Format/Strptime.pm b/lib/DateTime/Format/Strptime.pm index fcf1700..1e4a2fc 100644 --- a/lib/DateTime/Format/Strptime.pm +++ b/lib/DateTime/Format/Strptime.pm @@ -542,7 +542,7 @@ iso_week_year_100 = $iso_week_year_100 and return undef unless $Year and $Month; my $dt = eval { - DateTime->new( year => $Year, month => $Month, day => $Day, + DateTime->new( year => $Year+0, month => $Month+0, day => $Day+0, hour => 12, time_zone => $use_timezone ); }; $self->local_croak("Datetime $Year-$Month-$Day is not a valid date") @@ -646,14 +646,14 @@ iso_week_year_100 = $iso_week_year_100 my $potential_return = eval { DateTime->new( - year => ( $Year || 1 ), - month => ( $Month || 1 ), - day => ( $Day || 1 ), - - hour => ( $Hour || 0 ), - minute => ( $Minute || 0 ), - second => ( $Second || 0 ), - nanosecond => ( $Nanosecond || 0 ), + year => ( $Year || 1 )+0, + month => ( $Month || 1 )+0, + day => ( $Day || 1 )+0, + + hour => ( $Hour || 0 )+0, + minute => ( $Minute || 0 )+0, + second => ( $Second || 0 )+0, + nanosecond => ( $Nanosecond || 0 )+0, locale => $self->{_locale}, time_zone => $use_timezone, diff --git a/t/002_dates.t b/t/002_dates.t index e15fda3..f1c1e03 100644 --- a/t/002_dates.t +++ b/t/002_dates.t @@ -2,7 +2,7 @@ # t/002_basic.t - check module dates in various formats -use Test::More tests => 17; +use Test::More tests => 19; use DateTime::Format::Strptime; use DateTime; use DateTime::TimeZone; @@ -36,6 +36,10 @@ my @tests = ( # Complex dates [ '%Y;%j = %Y-%m-%d', '2003;56 = 2003-02-25' ], [ q|%d %b '%y = %Y-%m-%d|, q|25 Feb '03 = 2003-02-25| ], + + # Leading spaces + [ '%e-%b-%Y %T %z', '13-Jun-2010 09:20:47 -0400' ], + [ '%e-%b-%Y %T %z', ' 3-Jun-2010 09:20:47 -0400' ], ); foreach (@tests) { -- 1.7.0.4
Download (untitled) / with headers
text/plain 267b
It seems the author doesn't check RT... I cross-posted this. http://code.google.com/p/datetime-format-strptime/issues/detail?id=27 -- If riding in an airplane is flying, then riding in a boat is swimming. 116 jumps, 48.6 minutes of freefall, 92.9 freefall miles.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.