r28443 - in /trunk/libdatetime-format-natural-perl: Changes META.yml README debian/changelog lib/DateTime/Format/Natural.pm lib/DateTime/Format/Natural/Base.pm lib/DateTime/Format/Natural/Lang/EN.pm t/01-parse.t

gregoa at users.alioth.debian.org gregoa at users.alioth.debian.org
Sun Dec 21 21:36:53 UTC 2008


Author: gregoa
Date: Sun Dec 21 21:36:50 2008
New Revision: 28443

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=28443
Log:
New upstream release.

Modified:
    trunk/libdatetime-format-natural-perl/Changes
    trunk/libdatetime-format-natural-perl/META.yml
    trunk/libdatetime-format-natural-perl/README
    trunk/libdatetime-format-natural-perl/debian/changelog
    trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural.pm
    trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural/Base.pm
    trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural/Lang/EN.pm
    trunk/libdatetime-format-natural-perl/t/01-parse.t

Modified: trunk/libdatetime-format-natural-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdatetime-format-natural-perl/Changes?rev=28443&op=diff
==============================================================================
--- trunk/libdatetime-format-natural-perl/Changes (original)
+++ trunk/libdatetime-format-natural-perl/Changes Sun Dec 21 21:36:50 2008
@@ -1,4 +1,40 @@
 Revision history for Perl extension DateTime::Format::Natural.
+
+0.74 Sat Dec 20 15:06:50 CET 2008
+
+ - Merged development version to stable.
+
+0.73_04 Sun Nov 30 12:27:26 CET 2008
+
+ - Be more exact with english time matching regular expressions,
+   which fixes [rt #41266 - Alex Bowley] partly.
+
+ - The date and time validation methods do now honor all their
+   arguments; this reduces the amount of false errors.
+
+ - Wrap the code calling Nth_Weekday_of_Month_Year() in eval
+   blocks to catch errors and add some code to act upon the results.
+
+ - Do not call the setter method multiple times if the values can
+   be set at once.
+
+0.73_03 Thu Nov 13 21:20:53 CET 2008
+
+ - Move some duplicated logic to helper methods.
+
+ - Do not save intermediate data when generating the trace output.
+
+ - Use the proper data structure name in parse_datetime_duration().
+
+0.73_02 Sun Nov  2 21:40:31 CET 2008
+
+ - The grammar parser now, for each run, only iterates through
+   entries with an according count of fields.
+
+0.73_01 Sat Oct 18 22:21:56 CEST 2008
+
+ - Corrected a few typos in the main documentation and also 
+   reworded some bits.
 
 0.73 Thu Sep  4 19:53:44 CEST 2008
 

Modified: trunk/libdatetime-format-natural-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdatetime-format-natural-perl/META.yml?rev=28443&op=diff
==============================================================================
--- trunk/libdatetime-format-natural-perl/META.yml (original)
+++ trunk/libdatetime-format-natural-perl/META.yml Sun Dec 21 21:36:50 2008
@@ -1,6 +1,6 @@
 ---
 name: DateTime-Format-Natural
-version: 0.73
+version: 0.74
 author:
   - 'Steven Schubiger <schubiger at cpan.org>'
 abstract: Create machine readable date/time with natural parsing logic
@@ -23,16 +23,16 @@
 provides:
   DateTime::Format::Natural:
     file: lib/DateTime/Format/Natural.pm
-    version: 0.73
+    version: 0.74
   DateTime::Format::Natural::Base:
     file: lib/DateTime/Format/Natural/Base.pm
-    version: 1.15
+    version: 1.17
   DateTime::Format::Natural::Lang::Base:
     file: lib/DateTime/Format/Natural/Lang/Base.pm
     version: 0.9
   DateTime::Format::Natural::Lang::EN:
     file: lib/DateTime/Format/Natural/Lang/EN.pm
-    version: 1.12
+    version: 1.14
 generated_by: Module::Build version 0.2808
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.2.html

Modified: trunk/libdatetime-format-natural-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdatetime-format-natural-perl/README?rev=28443&op=diff
==============================================================================
--- trunk/libdatetime-format-natural-perl/README (original)
+++ trunk/libdatetime-format-natural-perl/README Sun Dec 21 21:36:50 2008
@@ -51,7 +51,7 @@
         Specifies the format of numeric dates, defaults to '"d/m/y"'.
 
     * "prefer_future"
-        Turns ambigious weekdays/months to their futuristic relatives.
+        Turns ambiguous weekdays/months to their futuristic relatives.
         Accepts a boolean, defaults to false.
 
     * "time_zone"
@@ -59,8 +59,8 @@
         zone recognized by DateTime. Defaults to 'floating'.
 
     * "daytime"
-        A hash consisting of specific hours given for peculiar daytimes.
-        Daytimes may be selectively changed.
+        A hash reference consisting of customized daytime hours, which may
+        be selectively changed.
 
 METHODS
   parse_datetime
@@ -87,11 +87,11 @@
     date/time string given.
 
   error
-    Returns the error message if the parsing didn't succeed.
+    Returns the error message if the parsing did not succeed.
 
   trace
-    Returns a trace of methods which we're called within the Base class and
-    a summary how often certain units were modified.
+    Returns a trace of methods which were called within the Base class and a
+    summary how often certain units have been modified.
 
 GRAMMAR
     The grammar handling has been rewritten to be easily extendable and
@@ -129,6 +129,7 @@
      Jason May
      Pat Kale
      Ankur Gupta
+     Alex Bowley
 
 SEE ALSO
     DateTime, Date::Calc, <http://datetime.perl.org>

Modified: trunk/libdatetime-format-natural-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdatetime-format-natural-perl/debian/changelog?rev=28443&op=diff
==============================================================================
--- trunk/libdatetime-format-natural-perl/debian/changelog (original)
+++ trunk/libdatetime-format-natural-perl/debian/changelog Sun Dec 21 21:36:50 2008
@@ -1,7 +1,8 @@
-libdatetime-format-natural-perl (0.73-2) UNRELEASED; urgency=low
+libdatetime-format-natural-perl (0.74-1) UNRELEASED; urgency=low
 
   * debian/control: Changed: Switched Vcs-Browser field to ViewSVN
     (source stanza).
+  * New upstream release.
 
  -- gregor herrmann <gregoa at debian.org>  Sun, 16 Nov 2008 20:41:32 +0100
 

Modified: trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural.pm?rev=28443&op=diff
==============================================================================
--- trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural.pm (original)
+++ trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural.pm Sun Dec 21 21:36:50 2008
@@ -11,7 +11,7 @@
 use List::MoreUtils qw(all any);
 use Params::Validate ':all';
 
-our $VERSION = '0.73';
+our $VERSION = '0.74';
 
 validation_options(
     on_fail => sub
@@ -113,7 +113,7 @@
     if (scalar keys %count == 1 && $count{(keys %count)[0]} == 2) {
         if ($date_string =~ /^\S+\b\s+\b\S+/) {
             ($date_string, @{$self->{tokens}}) = split /\s+/, $date_string;
-            $self->{count}{tokens} = 1 + @{$self->{tokens}};
+            $self->{count}{tokens} = 1 + scalar @{$self->{tokens}};
         }
         else {
             $self->{count}{tokens} = 1;
@@ -175,6 +175,7 @@
         $self->_set_modified(1);
 
         if (@{$self->{tokens} || []}) {
+            $self->{count}{tokens}--;
             $self->_unset_valid_exp;
             $self->_unset_modified;
             $self->_process;
@@ -231,12 +232,12 @@
       ? split /\s+ $timespan_sep \s+/ix, $self->{Date_string}
       : ($self->{Date_string});
 
-    my @stack;
+    my @queue;
     foreach my $date_string (@date_strings) {
-        push @stack, $self->parse_datetime($date_string);
-    }
-
-    return @stack;
+        push @queue, $self->parse_datetime($date_string);
+    }
+
+    return @queue;
 }
 
 sub success
@@ -262,24 +263,26 @@
 {
     my $self = shift;
 
-    my @modified;
-    foreach my $unit (grep { $_ ne 'total' } keys %{$self->{modified}}) {
-        push @modified, "$unit: $self->{modified}{$unit}";
-    }
-
-    return join "\n", @{$self->{trace}}, @modified;
+    return join "\n", @{$self->{trace}},
+      map  { my $unit = $_; "$unit: $self->{modified}{$unit}" }
+      grep { $_ ne 'total' } keys %{$self->{modified}};
 }
 
 sub _process
 {
     my $self = shift;
 
-    PARSE: foreach my $keyword (keys %{$self->{data}->__grammar('')}) {
+    if (!exists $self->{lookup}) {
+        foreach my $keyword (keys %{$self->{data}->__grammar('')}) {
+            push @{$self->{lookup}{scalar @{$self->{data}->__grammar($keyword)->[0]}}}, $keyword;
+        }
+    }
+
+    PARSE: foreach my $keyword (@{$self->{lookup}{$self->{count}{tokens}} || []}) {
+        last if $self->_get_modified >= $self->{count}{tokens};
+
         my @grammar = @{$self->{data}->__grammar($keyword)};
         my $types = shift @grammar;
-
-        next if @{$self->{tokens}} > @$types;
-        last if $self->_get_modified >= @{$self->{tokens}};
 
         foreach my $expression (@grammar) {
             my $valid_expression = true;
@@ -294,6 +297,7 @@
                         }
                         else {
                             $valid_expression = false;
+                            last;
                         }
                     }
                 }
@@ -305,6 +309,7 @@
                     }
                     else {
                         $valid_expression = false;
+                        last;
                     }
                 }
                 else {
@@ -507,7 +512,7 @@
 
 =item * C<prefer_future>
 
-Turns ambigious weekdays/months to their futuristic relatives. Accepts a boolean,
+Turns ambiguous weekdays/months to their futuristic relatives. Accepts a boolean,
 defaults to false.
 
 =item * C<time_zone>
@@ -517,7 +522,7 @@
 
 =item * C<daytime>
 
-A hash consisting of specific hours given for peculiar daytimes. Daytimes may be
+A hash reference consisting of customized daytime hours, which may be
 selectively changed.
 
 =back
@@ -557,16 +562,16 @@
 
 =head2 error
 
-Returns the error message if the parsing didn't succeed.
+Returns the error message if the parsing did not succeed.
 
 =head2 trace
 
-Returns a trace of methods which we're called within the Base class and
-a summary how often certain units were modified.
+Returns a trace of methods which were called within the Base class and
+a summary how often certain units have been modified.
 
 =head1 GRAMMAR
 
-The grammar handling has been rewritten to be easily extendable and hence 
+The grammar handling has been rewritten to be easily extendable and hence
 everybody is encouraged to propose sensible new additions and/or changes.
 
 See the classes C<DateTime::Format::Natural::Lang::[language_code]> if
@@ -574,7 +579,7 @@
 
 =head1 EXAMPLES
 
-See the classes C<DateTime::Format::Natural::Lang::[language_code]> for a 
+See the classes C<DateTime::Format::Natural::Lang::[language_code]> for a
 overview of current valid input.
 
 =head1 CREDITS
@@ -601,6 +606,7 @@
  Jason May
  Pat Kale
  Ankur Gupta
+ Alex Bowley
 
 =head1 SEE ALSO
 

Modified: trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural/Base.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural/Base.pm?rev=28443&op=diff
==============================================================================
--- trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural/Base.pm (original)
+++ trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural/Base.pm Sun Dec 21 21:36:50 2008
@@ -9,7 +9,7 @@
                   Nth_Weekday_of_Month_Year
                   check_date check_time);
 
-our $VERSION = '1.15';
+our $VERSION = '1.17';
 
 use constant MORNING   => '08';
 use constant AFTERNOON => '14';
@@ -173,9 +173,11 @@
     $self->_add_trace;
     my ($hour) = @_;
     if ($self->_valid_time(hour => $hour)) {
-        $self->_set(hour => $hour);
-        $self->_set(minute => 0);
-        $self->_set(second => 0);
+        $self->_set(
+            hour   => $hour,
+            minute => 0,
+            second => 0,
+        );
     }
     $self->_set_modified(4);
 }
@@ -186,9 +188,11 @@
     $self->_add_trace;
     my ($hour) = @_;
     if ($self->_valid_time(hour => 12 + $hour)) {
-        $self->_set(hour => 12 + $hour);
-        $self->_set(minute => 0);
-        $self->_set(second => 0);
+        $self->_set(
+            hour   => 12 + $hour,
+            minute => 0,
+            second => 0,
+        );
     }
     $self->_set_modified(4);
 }
@@ -199,9 +203,11 @@
     $self->_add_trace;
     my ($hour) = @_;
     if ($self->_valid_time(hour => 12 + $hour)) {
-        $self->_set(hour => 12 + $hour);
-        $self->_set(minute => 0);
-        $self->_set(second => 0);
+        $self->_set(
+            hour   => 12 + $hour,
+            minute => 0,
+            second => 0,
+        );
     }
     $self->_set_modified(4);
 }
@@ -214,9 +220,11 @@
       ? $self->{Opts}{daytime}{morning}
       : MORNING;
     if ($self->_valid_time(hour => $hour)) {
-        $self->_set(hour => $hour);
-        $self->_set(minute => 0);
-        $self->_set(second => 0);
+        $self->_set(
+            hour   => $hour,
+            minute => 0,
+            second => 0,
+        );
     }
     $self->_set_modified(1);
 }
@@ -225,9 +233,11 @@
 {
     my $self = shift;
     $self->_add_trace;
-    $self->_set(hour => 12);
-    $self->_set(minute => 0);
-    $self->_set(second => 0);
+    $self->_set(
+        hour   => 12,
+        minute => 0,
+        second => 0,
+    );
     $self->_set_modified(1);
 }
 
@@ -239,9 +249,11 @@
       ? $self->{Opts}{daytime}{afternoon}
       : AFTERNOON;
     if ($self->_valid_time(hour => $hour)) {
-        $self->_set(hour => $hour);
-        $self->_set(minute => 0);
-        $self->_set(second => 0);
+        $self->_set(
+            hour   => $hour,
+            minute => 0,
+            second => 0,
+        );
     }
     $self->_set_modified(1);
 }
@@ -254,9 +266,11 @@
       ? $self->{Opts}{daytime}{evening}
       : EVENING;
     if ($self->_valid_time(hour => $hour)) {
-        $self->_set(hour => $hour);
-        $self->_set(minute => 0);
-        $self->_set(second => 0);
+        $self->_set(
+            hour   => $hour,
+            minute => 0,
+            second => 0,
+        );
     }
     $self->_set_modified(1);
 }
@@ -265,9 +279,11 @@
 {
     my $self = shift;
     $self->_add_trace;
-    $self->_set(hour => 0);
-    $self->_set(minute => 0);
-    $self->_set(second => 0);
+    $self->_set(
+        hour   => 0,
+        minute => 0,
+        second => 0,
+    );
     $self->_set_modified(2);
 }
 
@@ -275,8 +291,10 @@
 {
     my $self = shift;
     $self->_add_trace;
-    $self->_set(hour => 12);
-    $self->_set(minute => 0);
+    $self->_set(
+        hour   => 12,
+        minute => 0,
+    );
     $self->_subtract(hour => shift);
     $self->_set_modified(4);
 }
@@ -285,8 +303,10 @@
 {
     my $self = shift;
     $self->_add_trace;
-    $self->_set(hour => 12);
-    $self->_set(minute => 0);
+    $self->_set(
+        hour   => 12,
+        minute => 0,
+    );
     $self->_add(hour => shift);
     $self->_set_modified(4);
 }
@@ -295,8 +315,10 @@
 {
     my $self = shift;
     $self->_add_trace;
-    $self->_set(hour => 0);
-    $self->_set(minute => 0);
+    $self->_set(
+        hour   => 0,
+        minute => 0,
+    );
     $self->_subtract(hour => shift);
     $self->_set_modified(4);
 }
@@ -305,8 +327,10 @@
 {
     my $self = shift;
     $self->_add_trace;
-    $self->_set(hour => 0);
-    $self->_set(minute => 0);
+    $self->_set(
+        hour   => 0,
+        minute => 0,
+    );
     $self->_add(hour => shift);
     $self->_set_modified(4);
 }
@@ -415,7 +439,7 @@
     $self->_add_trace;
     my ($day) = @_;
     $self->_day_name(\$day);
-    my $days_diff = $self->{datetime}->wday + (7 - $self->{data}->{weekdays}->{$day});
+    my $days_diff = $self->_last_wday_diff($day);
     $self->_subtract(day => $days_diff);
     $self->_set_modified(2);
 }
@@ -425,7 +449,7 @@
     my $self = shift;
     $self->_add_trace;
     my $day = ucfirst lc(shift);
-    my $days_diff = $self->{datetime}->wday + (7 - $self->{data}->{weekdays}->{$day});
+    my $days_diff = $self->_last_wday_diff($day);
     $self->_subtract(day => $days_diff);
     $self->_set_modified(3);
 }
@@ -435,7 +459,7 @@
     my $self = shift;
     $self->_add_trace;
     my $day = ucfirst lc(shift);
-    my $days_diff = $self->{datetime}->wday + (7 - $self->{data}->{weekdays}->{$day});
+    my $days_diff = $self->_last_wday_diff($day);
     $self->_subtract(day => $days_diff);
     $self->_set_modified(3);
 }
@@ -501,7 +525,7 @@
     $self->_add_trace;
     my ($day) = @_;
     $self->_day_name(\$day);
-    my $days_diff = (7 - $self->{datetime}->wday + Decode_Day_of_Week($day));
+    my $days_diff = $self->_next_wday_diff($day);
     $self->_add(day => $days_diff);
     $self->_set_modified(2);
 }
@@ -512,7 +536,7 @@
     $self->_add_trace;
     my ($day) = @_;
     $self->_day_name(\$day);
-    my $days_diff = (7 - $self->{datetime}->wday + Decode_Day_of_Week($day));
+    my $days_diff = $self->_next_wday_diff($day);
     $self->_add(day => $days_diff);
     $self->_set_modified(3);
 }
@@ -634,14 +658,26 @@
     $self->_day_name(\$day);
     $self->_month_name(\$month);
     my $year;
-    ($year, $month, $day) =
-      Nth_Weekday_of_Month_Year($self->{datetime}->year,
-                                $self->{data}->{months}->{$month},
-                                $self->{data}->{weekdays}->{$day},
-                                $count);
-    $self->_set(year => $year);
-    $self->_set(month => $month);
-    $self->_set(day => $day);
+    eval {
+        ($year, $month, $day) =
+          Nth_Weekday_of_Month_Year($self->{datetime}->year,
+                                    $self->{data}->{months}->{$month},
+                                    $self->{data}->{weekdays}->{$day},
+                                    $count);
+    };
+    if (!$@ and defined $year && defined $month && defined $day
+        and $self->_valid_date(year => $year, month => $month, day => $day))
+    {
+        $self->_set(
+            year  => $year,
+            month => $month,
+            day   => $day,
+        );
+    }
+    else {
+        $self->_set_failure;
+        $self->_set_error("(date is not valid)");
+    }
     $self->_set_modified(4);
 }
 
@@ -688,14 +724,18 @@
     if ($time =~ /:/) {
         my ($hour, $minute) = split /:/, $time;
         if ($self->_valid_time(hour => $hour, minute => $minute)) {
-            $self->_set(hour => $hour);
-            $self->_set(minute => $minute);
+            $self->_set(
+                hour   => $hour,
+                minute => $minute,
+            );
         }
     }
     else {
         if ($self->_valid_time(hour => $time)) {
-            $self->_set(hour => $time);
-            $self->_set(minute => 0);
+            $self->_set(
+                hour   => $time,
+                minute => 0,
+            );
         }
     }
     $self->_set_modified(2);
@@ -709,14 +749,18 @@
     if ($time =~ /:/) {
         my ($hour, $minute) = split /:/, $time;
         if ($self->_valid_time(hour => 12 + $hour, minute => $minute)) {
-            $self->_set(hour => 12 + $hour);
-            $self->_set(minute => $minute);
+            $self->_set(
+                hour   => 12 + $hour,
+                minute => $minute,
+            );
         }
     }
     else {
         if ($self->_valid_time(hour => 12 + $time)) {
-            $self->_set(hour => 12 + $time);
-            $self->_set(minute => 0);
+            $self->_set(
+                hour   => 12 + $time,
+                minute => 0,
+            );
         }
     }
     $self->_set_modified(2);
@@ -730,14 +774,18 @@
     if ($time =~ /:/) {
         my ($hour, $minute) = split /:/, $time;
         if ($self->_valid_time(hour => $hour, minute => $minute)) {
-            $self->_set(hour => $hour);
-            $self->_set(minute => $minute);
+            $self->_set(
+                hour   => $hour,
+                minute => $minute,
+            );
         }
     }
     else {
         if ($self->_valid_time(hour => $time)) {
-            $self->_set(hour => $time);
-            $self->_set(minute => 0);
+            $self->_set(
+                hour   => $time,
+                minute => 0,
+            );
         }
     }
     $self->_set_modified(1);
@@ -750,9 +798,11 @@
     my ($time) = @_;
     my ($hour, $minute, $second) = split /:/, $time;
     if ($self->_valid_time(hour => $hour, minute => $minute, second => $second)) {
-        $self->_set(hour => $hour);
-        $self->_set(minute => $minute);
-        $self->_set(second => $second);
+        $self->_set(
+            hour   => $hour,
+            minute => $minute,
+            second => $second,
+        );
     }
     $self->_set_modified(1);
 }
@@ -771,9 +821,11 @@
     my ($day) = @_;
     my ($year, $month);
     ($year, $month, $day) = Add_Delta_Days($self->{datetime}->year, 1, 1, $day - 1);
-    $self->_set(day => $day);
-    $self->{datetime}->set_month($month);
-    $self->{datetime}->set_year($year);
+    $self->_set(
+        year  => $year,
+        month => $month,
+        day   => $day,
+    );
     $self->_set_modified(2);
 }
 
@@ -783,15 +835,26 @@
     $self->_add_trace;
     my ($count, $weekday) = @_;
     $weekday = ucfirst lc $weekday;
-    my ($year, $month, $day) =
-      Nth_Weekday_of_Month_Year($self->{datetime}->year,
-                                $self->{datetime}->month,
-                                $self->{data}->{weekdays}->{$weekday},
-                                $count);
-    if ($self->_valid_date(day => $day, month => $month, year => $year)) {
-        $self->_set(day => $day);
-        $self->_set(month => $month);
-        $self->{datetime}->set_year($year);
+    my ($year, $month, $day);
+    eval {
+        ($year, $month, $day) =
+          Nth_Weekday_of_Month_Year($self->{datetime}->year,
+                                    $self->{datetime}->month,
+                                    $self->{data}->{weekdays}->{$weekday},
+                                    $count);
+    };
+    if (!$@ and defined $year && defined $month && defined $day
+        and $self->_valid_date(year => $year, month => $month, day => $day))
+    {
+        $self->_set(
+            year  => $year,
+            month => $month,
+            day   => $day,
+        );
+    }
+    else {
+        $self->_set_failure;
+        $self->_set_error("(date is not valid)");
     }
     $self->_set_modified(2);
 }
@@ -802,10 +865,10 @@
     $self->_add_trace;
     my ($day, $month, $year) = @_;
     $self->_month_name(\$month);
-    $self->{datetime}->set(
-        year => $year,
+    $self->_set(
+        year  => $year,
         month => $self->_month_num($month),
-        day => $day,
+        day   => $day,
     );
     $self->_set_modified(3);
 }
@@ -841,66 +904,105 @@
     return $self->{data}->{months}->{$month};
 }
 
+sub _last_wday_diff
+{
+    my $self = shift;
+    my ($day) = @_;
+    return $self->{datetime}->wday + (7 - $self->{data}->{weekdays}->{$day});
+}
+
+sub _next_wday_diff
+{
+    my $self = shift;
+    my ($day) = @_;
+    return (7 - $self->{datetime}->wday + Decode_Day_of_Week($day));
+}
+
 sub _add
 {
     my ($self, $unit, $value) = @_;
-
-    $self->{modified}{$unit}++;
 
     $unit .= 's' unless $unit =~ /s$/;
     $self->{datetime}->add($unit => $value);
+
+    chop $unit;
+    $self->{modified}{$unit}++;
 }
 
 sub _subtract
 {
     my ($self, $unit, $value) = @_;
-
-    $self->{modified}{$unit}++;
 
     $unit .= 's' unless $unit =~ /s$/;
     $self->{datetime}->subtract($unit => $value);
+
+    chop $unit;
+    $self->{modified}{$unit}++;
 }
 
 sub _set
 {
-    my ($self, $unit, $value) = @_;
-
-    $self->{modified}{$unit}++;
-
-    my $setter = 'set_' . $unit;
-    $self->{datetime}->$setter($value);
+    my ($self, %values) = @_;
+
+    my @units = qw(
+        year
+        month
+        day
+        hour
+        minute
+        second
+    );
+
+    foreach my $unit (@units) {
+        if (exists $values{$unit}) {
+            my $setter = 'set_' . $unit;
+            $self->{datetime}->$setter($values{$unit});
+            $self->{modified}{$unit}++;
+        }
+    }
 }
 
 sub _valid_date
 {
-    my ($self, $type, $value) = @_;
+    my ($self, %values) = @_;
 
     my %set = map { $_ => $self->{datetime}->$_ } qw(year month day);
-    $set{$type} = $value;
+
+    while (my ($unit, $value) = each %values) {
+        $set{$unit} = $value;
+    }
 
     if (check_date($set{year}, $set{month}, $set{day})) {
         return true;
     }
     else {
         $self->_set_failure;
-        $self->_set_error("('$value' is not a valid $type)");
+        $self->_set_error("(date is not valid)");
         return false;
     }
 }
 
 sub _valid_time
 {
-    my ($self, $type, $value) = @_;
-
-    my %set = map { $_ => $self->{datetime}->$_ } qw(hour min sec);
-    $set{$type} = $value;
+    my ($self, %values) = @_;
+
+    my %abbrev = (
+        second => 'sec',
+        minute => 'min',
+        hour   => 'hour',
+    );
+    my %set = map { $_ => $self->{datetime}->$_ } values %abbrev;
+
+    while (my ($unit, $value) = each %values) {
+        $set{$abbrev{$unit}} = $value;
+    }
 
     if (check_time($set{hour}, $set{min}, $set{sec})) {
         return true;
     }
     else {
         $self->_set_failure;
-        $self->_set_error("('$value' is not a valid $type)");
+        $self->_set_error("(time is not valid)");
         return false;
     }
 }

Modified: trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural/Lang/EN.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural/Lang/EN.pm?rev=28443&op=diff
==============================================================================
--- trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural/Lang/EN.pm (original)
+++ trunk/libdatetime-format-natural-perl/lib/DateTime/Format/Natural/Lang/EN.pm Sun Dec 21 21:36:50 2008
@@ -4,7 +4,7 @@
 use warnings;
 use base qw(DateTime::Format::Natural::Lang::Base);
 
-our $VERSION = '1.12';
+our $VERSION = '1.14';
 
 our (%init,
      %timespan,
@@ -22,10 +22,10 @@
 
 %RE = ('number'    => qr/^(\d+)$/,
        'year'      => qr/^(\d{4})$/,
-       'time'      => qr/^((?:\d{1,2})(?:\:\d{1,2})?)$/,
-       'time_am'   => qr/^((?:\d+)(?:\:\d+)?)(?:am)?$/,
-       'time_pm'   => qr/^((?:\d+)(?:\:\d+)?)pm$/,
-       'time_full' => qr/^(\d{2}\:\d{2}:\d{2})$/,
+       'time'      => qr/^((?:\d{1,2})(?:\:\d{2})?)$/,
+       'time_am'   => qr/^((?:\d{1,2})(?:\:\d{2})?)(?:am)?$/,
+       'time_pm'   => qr/^((?:\d{1,2})(?:\:\d{2})?)pm$/,
+       'time_full' => qr/^(\d{1,2}\:\d{2}\:\d{2})$/,
        'day_enum'  => qr/^(\d+)(?:st|nd|rd|th)?$/,
        'monthday'  => qr/^(\d{1,2})$/);
 {
@@ -383,19 +383,19 @@
        ],
        [
          { 0 => $RE{time}, 1 => 'pm' },
-         [ [ 0 ] ], 
+         [ [ 0 ] ],
          [ '_at_pm' ],
        ],
     ],
     at_combined => [
        [ 'REGEXP' ],
        [
-         { 0 => qr/^(\d+)(?:am)$/i }, 
+         { 0 => $RE{time_am} },
          [ [ 0 ] ],
          [ '_at_am' ],
        ],
        [
-         { 0 => qr/^(\d+)(?:pm)$/i },
+         { 0 => $RE{time_pm} },
          [ [ 0 ] ],
          [ '_at_pm' ],
        ],
@@ -925,7 +925,7 @@
 =head1 EXAMPLES
 
 Below are some examples of human readable date/time input in english (be aware
-that the parser doesn't differentiate between lower/upper case):
+that the parser does not distinguish between lower/upper case):
 
 =head2 Simple
 
@@ -952,7 +952,7 @@
  tomorrow evening
  march
  4th february
- november 3rd 
+ november 3rd
  saturday
  last wednesday
  last june
@@ -966,11 +966,13 @@
  this month
  6 am
  5am
+ 5:30am
  5am yesterday
  5am today
  5am tomorrow
  8 pm
  4pm
+ 4:20pm
  4pm yesterday
  4pm today
  4pm tomorrow
@@ -1088,6 +1090,7 @@
  27/5/1979
  4:00
  17:00
+ 3:20:00
 
 =head1 SEE ALSO
 

Modified: trunk/libdatetime-format-natural-perl/t/01-parse.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdatetime-format-natural-perl/t/01-parse.t?rev=28443&op=diff
==============================================================================
--- trunk/libdatetime-format-natural-perl/t/01-parse.t (original)
+++ trunk/libdatetime-format-natural-perl/t/01-parse.t Sun Dec 21 21:36:50 2008
@@ -4,7 +4,7 @@
 use warnings;
 
 use DateTime::Format::Natural;
-use Test::More tests => 149;
+use Test::More tests => 152;
 
 my ($sec, $min, $hour, $day, $month, $year) = (00, 13, 01, 24, 11, 2006);
 
@@ -51,11 +51,13 @@
               'this month'            => '24.11.2006 01:13:00',
               '6 am'                  => '24.11.2006 06:00:00',
               '5am'                   => '24.11.2006 05:00:00',
+              '5:30am'                => '24.11.2006 05:30:00',
               '5am yesterday'         => '23.11.2006 05:00:00',
               '5am today'             => '24.11.2006 05:00:00',
               '5am tomorrow'          => '25.11.2006 05:00:00',
               '8 pm'                  => '24.11.2006 20:00:00',
               '4pm'                   => '24.11.2006 16:00:00',
+              '4:20pm'                => '24.11.2006 16:20:00',
               '4pm yesterday'         => '23.11.2006 16:00:00',
               '4pm today'             => '24.11.2006 16:00:00',
               '4pm tomorrow'          => '25.11.2006 16:00:00',
@@ -160,7 +162,8 @@
                 '3 jan 2000'        => '03.01.2000 01:13:00',
                 '27/5/1979'         => '27.05.1979 01:13:00',
                 '4:00'              => '24.11.2006 04:00:00',
-                '17:00'             => '24.11.2006 17:00:00');
+                '17:00'             => '24.11.2006 17:00:00',
+                '3:20:00'           => '24.11.2006 03:20:00');
 
 compare(\%simple);
 compare(\%complex);




More information about the Pkg-perl-cvs-commits mailing list