Changeset 2390

Show
Ignore:
Timestamp:
11/06/07 05:23:56
Author:
miyagawa
Message:

accept patches from swartz and rjbs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Time-Duration-Parse/trunk/Changes

    r1880 r2390  
    11Revision history for Perl extension Time::Duration::Parse 
     2 
     30.03  Mon Nov  5 12:18:15 PST 2007 
     4        - Accept 'hr' for hours (Ricardo SIGNES) 
     5        - Do not require space between digits and units (1hr) (Ricaldo SIGNES) 
     6        - Accept a simple integer as a number of seconds (Jonathan Swartz) 
     7        - Accept negative durations like "-30 minutes" (Jonathan Swartz) 
    28 
    390.02  Tue Jul 18 16:58:53 JST 2006 
  • Time-Duration-Parse/trunk/lib/Time/Duration/Parse.pm

    r1883 r2390  
    22 
    33use strict; 
    4 our $VERSION = '0.02'; 
     4our $VERSION = '0.03'; 
    55 
    66use Carp; 
     
    1010# This map is taken from Cache and Cache::Cache 
    1111# map of expiration formats to their respective time in seconds 
    12 my %Units = ( map(($_,             1), qw(s second seconds sec)), 
    13               map(($_,            60), qw(m minute minutes min)), 
    14               map(($_,         60*60), qw(h hour hours)), 
     12my %Units = ( map(($_,             1), qw(s second seconds sec secs)), 
     13              map(($_,            60), qw(m minute minutes min mins)), 
     14              map(($_,         60*60), qw(h hr hour hours)), 
    1515              map(($_,      60*60*24), qw(d day days)), 
    1616              map(($_,    60*60*24*7), qw(w week weeks)), 
     
    2121    my $timespec = shift; 
    2222 
     23    # Treat plain integer as number of seconds 
     24    if ($timespec =~ /^-?\d+$/) { 
     25        return $timespec; 
     26    } 
     27 
    2328    my $duration = 0; 
    24     while ($timespec =~ s/^\s*(\d+)\s+(\w+)(?:\s*(?:,|and)\s*)*//i) { 
     29    while ($timespec =~ s/^\s*(-?\d+)\s*(\w+)(?:\s*(?:,|and)\s*)*//i) { 
    2530        my($amount, $unit) = ($1, $2); 
    2631        $unit = lc($unit) unless length($unit) == 1; 
  • Time-Duration-Parse/trunk/t/01_parse.t

    r1880 r2390  
    11use strict; 
    2 use Test::More tests => 11
     2use Test::More tests => 17
    33 
    44use Time::Duration::Parse; 
     
    1515} 
    1616 
     17ok_duration '3', 3; 
    1718ok_duration '3 seconds', 3; 
    1819ok_duration '3 Seconds', 3; 
     
    2324ok_duration '1 day', 86400; 
    2425ok_duration '1 day, and 3 seconds', 86403; 
     26ok_duration '-1 seconds', -1; 
     27ok_duration '-6 minutes', -360; 
     28 
     29ok_duration '1 hr', 3600; 
     30ok_duration '3s', 3; 
     31ok_duration '1hr', 3600; 
    2532 
    2633fail_duration '3 sss';