Skip Menu |

This queue is for tickets about the Time-Duration-Parse CPAN distribution.

Report information
The Basics
Id: 32159
Status: resolved
Priority: 0/
Queue: Time-Duration-Parse

People
Owner: NEILB [...] cpan.org
Requestors: trs [...] bestpractical.com
Cc:
AdminCc:

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



Subject: hh:mm:ss patch
Date: Tue, 08 Jan 2008 12:21:10 -0500
To: bug-Time-Duration-Parse [...] rt.cpan.org
From: Thomas Sibley <trs [...] bestpractical.com>
Hi again, Here's a patch (with tests) that lets Time::Duration::Parse understand hh:mm and hh:mm:ss durations. It also fixes an issue where if $timespec contained trailing spaces after parsing, the function would croak. Cheers, Tom
diff -ru Time-Duration-Parse-0.04-orig/lib/Time/Duration/Parse.pm Time-Duration-Parse-0.04/lib/Time/Duration/Parse.pm --- Time-Duration-Parse-0.04-orig/lib/Time/Duration/Parse.pm 2008-01-04 20:13:25.000000000 -0500 +++ Time-Duration-Parse-0.04/lib/Time/Duration/Parse.pm 2008-01-08 12:16:20.000000000 -0500 @@ -25,6 +25,10 @@ return $timespec; } + # Convert hh:mm(:ss)? to something we understand + $timespec =~ s/\b(\d+):(\d\d):(\d\d)\b/$1h $2m $3s/g; + $timespec =~ s/\b(\d+):(\d\d)\b/$1h $2m/g; + my $duration = 0; while ($timespec =~ s/^\s*(-?\d+)\s*([a-zA-Z]+)(?:\s*(?:,|and)\s*)*//i) { my($amount, $unit) = ($1, $2); @@ -37,7 +41,7 @@ } } - if ($timespec) { + if ($timespec =~ /\S/) { Carp::croak "Unknown timespec: $timespec"; } diff -ru Time-Duration-Parse-0.04-orig/t/01_parse.t Time-Duration-Parse-0.04/t/01_parse.t --- Time-Duration-Parse-0.04-orig/t/01_parse.t 2007-11-05 15:22:10.000000000 -0500 +++ Time-Duration-Parse-0.04/t/01_parse.t 2008-01-08 12:15:41.000000000 -0500 @@ -1,5 +1,5 @@ use strict; -use Test::More tests => 17; +use Test::More tests => 22; use Time::Duration::Parse; @@ -30,6 +30,13 @@ ok_duration '3s', 3; ok_duration '1hr', 3600; +ok_duration '1d 2:03', 93780; +ok_duration '1d 2:03:01', 93781; +ok_duration '1d -24:00', 0; +ok_duration '2:03', 7380; + +ok_duration ' 1s ', 1; + fail_duration '3 sss'; fail_duration '6 minutes and 3 sss'; fail_duration '6 minutes, and 3 seconds a';
Subject: Re: [rt.cpan.org #32159] hh:mm:ss patch
Date: Wed, 9 Jan 2008 14:40:18 -0800
To: bug-Time-Duration-Parse [...] rt.cpan.org
From: "Tatsuhiko Miyagawa" <miyagawa [...] gmail.com>
Hi, This patch doesn't apply very well. Please create a patch against http://svn.bulknews.net/repos/public/Time-Duration-Parse/trunk/ and make it an attachment, not inline so MUA doesn't make it messy. Thanks! On 1/8/08, trs@bestpractical.com via RT <bug-Time-Duration-Parse@rt.cpan.org> wrote: Show quoted text
> > Tue Jan 08 12:21:58 2008: Request 32159 was acted upon. > Transaction: Ticket created by trs@bestpractical.com > Queue: Time-Duration-Parse > Subject: hh:mm:ss patch > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: trs@bestpractical.com > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=32159 > > > > Hi again, > > Here's a patch (with tests) that lets Time::Duration::Parse understand > hh:mm and hh:mm:ss durations. > > It also fixes an issue where if $timespec contained trailing spaces > after parsing, the function would croak. > > Cheers, > Tom > > > diff -ru Time-Duration-Parse-0.04-orig/lib/Time/Duration/Parse.pm Time-Duration-Parse-0.04/lib/Time/Duration/Parse.pm > --- Time-Duration-Parse-0.04-orig/lib/Time/Duration/Parse.pm 2008-01-04 20:13:25.000000000 -0500 > +++ Time-Duration-Parse-0.04/lib/Time/Duration/Parse.pm 2008-01-08 12:16:20.000000000 -0500 > @@ -25,6 +25,10 @@ > return $timespec; > } > > + # Convert hh:mm(:ss)? to something we understand > + $timespec =~ s/\b(\d+):(\d\d):(\d\d)\b/$1h $2m $3s/g; > + $timespec =~ s/\b(\d+):(\d\d)\b/$1h $2m/g; > + > my $duration = 0; > while ($timespec =~ s/^\s*(-?\d+)\s*([a-zA-Z]+)(?:\s*(?:,|and)\s*)*//i) { > my($amount, $unit) = ($1, $2); > @@ -37,7 +41,7 @@ > } > } > > - if ($timespec) { > + if ($timespec =~ /\S/) { > Carp::croak "Unknown timespec: $timespec"; > } > > diff -ru Time-Duration-Parse-0.04-orig/t/01_parse.t Time-Duration-Parse-0.04/t/01_parse.t > --- Time-Duration-Parse-0.04-orig/t/01_parse.t 2007-11-05 15:22:10.000000000 -0500 > +++ Time-Duration-Parse-0.04/t/01_parse.t 2008-01-08 12:15:41.000000000 -0500 > @@ -1,5 +1,5 @@ > use strict; > -use Test::More tests => 17; > +use Test::More tests => 22; > > use Time::Duration::Parse; > > @@ -30,6 +30,13 @@ > ok_duration '3s', 3; > ok_duration '1hr', 3600; > > +ok_duration '1d 2:03', 93780; > +ok_duration '1d 2:03:01', 93781; > +ok_duration '1d -24:00', 0; > +ok_duration '2:03', 7380; > + > +ok_duration ' 1s ', 1; > + > fail_duration '3 sss'; > fail_duration '6 minutes and 3 sss'; > fail_duration '6 minutes, and 3 seconds a'; > >
-- Tatsuhiko Miyagawa
Subject: Re: [rt.cpan.org #32159] hh:mm:ss patch
Date: Thu, 10 Jan 2008 08:47:30 -0500
To: bug-Time-Duration-Parse [...] rt.cpan.org
From: Thomas Sibley <trs [...] bestpractical.com>
It was an attachment (it even is on the ticket page), but when RT sent you a copy it made it inline (and so it got changed). Weird. It applied just fine to trunk, but here's the output of svn diff against patched trunk. miyagawa@gmail.com via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=32159 > > > Hi, > > This patch doesn't apply very well. Please create a patch against > http://svn.bulknews.net/repos/public/Time-Duration-Parse/trunk/ > and make it an attachment, not inline so MUA doesn't make it messy. > > Thanks! > > On 1/8/08, trs@bestpractical.com via RT > <bug-Time-Duration-Parse@rt.cpan.org> wrote:
>> Tue Jan 08 12:21:58 2008: Request 32159 was acted upon. >> Transaction: Ticket created by trs@bestpractical.com >> Queue: Time-Duration-Parse >> Subject: hh:mm:ss patch >> Broken in: (no value) >> Severity: (no value) >> Owner: Nobody >> Requestors: trs@bestpractical.com >> Status: new >> Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=32159 > >> >> >> Hi again, >> >> Here's a patch (with tests) that lets Time::Duration::Parse understand >> hh:mm and hh:mm:ss durations. >> >> It also fixes an issue where if $timespec contained trailing spaces >> after parsing, the function would croak. >> >> Cheers, >> Tom >> >> >> diff -ru Time-Duration-Parse-0.04-orig/lib/Time/Duration/Parse.pm Time-Duration-Parse-0.04/lib/Time/Duration/Parse.pm >> --- Time-Duration-Parse-0.04-orig/lib/Time/Duration/Parse.pm 2008-01-04 20:13:25.000000000 -0500 >> +++ Time-Duration-Parse-0.04/lib/Time/Duration/Parse.pm 2008-01-08 12:16:20.000000000 -0500 >> @@ -25,6 +25,10 @@ >> return $timespec; >> } >> >> + # Convert hh:mm(:ss)? to something we understand >> + $timespec =~ s/\b(\d+):(\d\d):(\d\d)\b/$1h $2m $3s/g; >> + $timespec =~ s/\b(\d+):(\d\d)\b/$1h $2m/g; >> + >> my $duration = 0; >> while ($timespec =~ s/^\s*(-?\d+)\s*([a-zA-Z]+)(?:\s*(?:,|and)\s*)*//i) { >> my($amount, $unit) = ($1, $2); >> @@ -37,7 +41,7 @@ >> } >> } >> >> - if ($timespec) { >> + if ($timespec =~ /\S/) { >> Carp::croak "Unknown timespec: $timespec"; >> } >> >> diff -ru Time-Duration-Parse-0.04-orig/t/01_parse.t Time-Duration-Parse-0.04/t/01_parse.t >> --- Time-Duration-Parse-0.04-orig/t/01_parse.t 2007-11-05 15:22:10.000000000 -0500 >> +++ Time-Duration-Parse-0.04/t/01_parse.t 2008-01-08 12:15:41.000000000 -0500 >> @@ -1,5 +1,5 @@ >> use strict; >> -use Test::More tests => 17; >> +use Test::More tests => 22; >> >> use Time::Duration::Parse; >> >> @@ -30,6 +30,13 @@ >> ok_duration '3s', 3; >> ok_duration '1hr', 3600; >> >> +ok_duration '1d 2:03', 93780; >> +ok_duration '1d 2:03:01', 93781; >> +ok_duration '1d -24:00', 0; >> +ok_duration '2:03', 7380; >> + >> +ok_duration ' 1s ', 1; >> + >> fail_duration '3 sss'; >> fail_duration '6 minutes and 3 sss'; >> fail_duration '6 minutes, and 3 seconds a'; >> >>
> >
Download hhmmss.patch.gz
application/x-gzip 571b

Message body not shown because it is not plain text.