Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: trs [...] bestpractical.com
Cc:
AdminCc:

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



Subject: Roundtripping with Time::Duration's concise
Date: Thu, 03 Jan 2008 23:17:34 -0500
To: bug-Time-Duration-Parse [...] rt.cpan.org
From: Thomas Sibley <trs [...] bestpractical.com>
Hi, Time::Duration::Parse doesn't recognize "3d2h" but does recognize "3d 2h". Time::Duration's concise function outputs the former, and it'd be great if your module could parse that so it can round trip nicely as well. I've attached a patch (with tests!) that fixes this. Cheers, Tom
diff -ru Time-Duration-Parse-0.03-orig/lib/Time/Duration/Parse.pm Time-Duration-Parse-0.03/lib/Time/Duration/Parse.pm --- Time-Duration-Parse-0.03-orig/lib/Time/Duration/Parse.pm 2007-11-05 15:25:09.000000000 -0500 +++ Time-Duration-Parse-0.03/lib/Time/Duration/Parse.pm 2008-01-03 21:18:56.000000000 -0500 @@ -26,7 +26,7 @@ } my $duration = 0; - while ($timespec =~ s/^\s*(-?\d+)\s*(\w+)(?:\s*(?:,|and)\s*)*//i) { + while ($timespec =~ s/^\s*(-?\d+)\s*([a-zA-Z]+)(?:\s*(?:,|and)\s*)*//i) { my($amount, $unit) = ($1, $2); $unit = lc($unit) unless length($unit) == 1; diff -ru Time-Duration-Parse-0.03-orig/t/02_roundtrip.t Time-Duration-Parse-0.03/t/02_roundtrip.t --- Time-Duration-Parse-0.03-orig/t/02_roundtrip.t 2006-07-17 14:02:07.000000000 -0400 +++ Time-Duration-Parse-0.03/t/02_roundtrip.t 2008-01-03 21:15:09.000000000 -0500 @@ -7,7 +7,7 @@ plan skip_all => 'Time::Duration is required'; } -plan tests => 1000; +plan tests => 2000; my @tests = map int rand(100_000), 1..1000; @@ -16,4 +16,8 @@ is parse_duration($spec), $test, "$spec - $test"; } +for my $test (@tests) { + my $spec = Time::Duration::concise(Time::Duration::duration_exact($test)); + is parse_duration($spec), $test, "$spec - $test"; +}
Subject: Re: [rt.cpan.org #32078] Roundtripping with Time::Duration's concise
Date: Fri, 4 Jan 2008 17:13:40 -0800
To: bug-Time-Duration-Parse [...] rt.cpan.org
From: "Tatsuhiko Miyagawa" <miyagawa [...] gmail.com>
Applied and shipped as 0.04. Thanks! -- Tatsuhiko Miyagawa