r72540 - in /branches/upstream/libdatetime-format-natural-perl/current: ./ lib/DateTime/Format/ lib/DateTime/Format/Natural/ lib/DateTime/Format/Natural/Lang/ t/

angelabad-guest at users.alioth.debian.org angelabad-guest at users.alioth.debian.org
Tue Apr 12 10:05:16 UTC 2011


Author: angelabad-guest
Date: Tue Apr 12 09:59:45 2011
New Revision: 72540

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=72540
Log:
[svn-upgrade] new version libdatetime-format-natural-perl (0.94)

Added:
    branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Extract.pm
    branches/upstream/libdatetime-format-natural-perl/current/t/12-extract_expression.t   (with props)
    branches/upstream/libdatetime-format-natural-perl/current/t/13-regression.t   (with props)
    branches/upstream/libdatetime-format-natural-perl/current/t/14-state.t   (with props)
    branches/upstream/libdatetime-format-natural-perl/current/t/15-trace.t   (with props)
Removed:
    branches/upstream/libdatetime-format-natural-perl/current/t/12-regression.t
    branches/upstream/libdatetime-format-natural-perl/current/t/13-state.t
    branches/upstream/libdatetime-format-natural-perl/current/t/14-trace.t
Modified:
    branches/upstream/libdatetime-format-natural-perl/current/Changes
    branches/upstream/libdatetime-format-natural-perl/current/MANIFEST
    branches/upstream/libdatetime-format-natural-perl/current/META.yml
    branches/upstream/libdatetime-format-natural-perl/current/Makefile.PL
    branches/upstream/libdatetime-format-natural-perl/current/README
    branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural.pm
    branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Calc.pm
    branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Formatted.pm
    branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/EN.pm
    branches/upstream/libdatetime-format-natural-perl/current/t/01-parse.t

Modified: branches/upstream/libdatetime-format-natural-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/Changes?rev=72540&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/Changes (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/Changes Tue Apr 12 09:59:45 2011
@@ -1,4 +1,35 @@
 Revision history for Perl extension DateTime::Format::Natural.
+
+0.94  2011-04-02  <schubiger at cpan.org>
+
+ - Merged development version to stable.
+
+0.93_02  2011-03-31  <schubiger at cpan.org>
+
+ - Set month and implicit day explicitly to avoid overlap parse
+   failures; add a regression test. [reported by Chifung Fan]
+
+ - Keep the minute or higher precision requirement when extracting
+   one token time expressions, but undo the grammar change.
+
+ - Test one token time expression with precision in hour.
+
+ - Use more descriptive variable names within the extract class.
+
+0.93_01  2011-03-21  <schubiger at cpan.org>
+
+ - Introduce a class to extract parsable expressions from strings.
+   [suggested by Colm Dougan]
+
+ - Add and document the extract_datetime() method.
+
+ - Test extracting parsable expressions.
+
+ - Require precision in hour or higher for one token time expressions,
+   otherwise extracting expressions would be impeded.
+
+ - Move the formatted string regex to the grammar class;
+   furthermore, move the according checks to the formatted class.
 
 0.93  2011-02-04  <schubiger at cpan.org>
 

Modified: branches/upstream/libdatetime-format-natural-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/MANIFEST?rev=72540&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/MANIFEST (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/MANIFEST Tue Apr 12 09:59:45 2011
@@ -7,6 +7,7 @@
 lib/DateTime/Format/Natural/Compat.pm
 lib/DateTime/Format/Natural/Duration.pm
 lib/DateTime/Format/Natural/Duration/Checks.pm
+lib/DateTime/Format/Natural/Extract.pm
 lib/DateTime/Format/Natural/Formatted.pm
 lib/DateTime/Format/Natural/Helpers.pm
 lib/DateTime/Format/Natural/Lang/Base.pm
@@ -31,8 +32,9 @@
 t/09-parse_success.t
 t/10-parse_failure.t
 t/11-parse_assert.t
-t/12-regression.t
-t/13-state.t
-t/14-trace.t
+t/12-extract_expression.t
+t/13-regression.t
+t/14-state.t
+t/15-trace.t
 t/pod-coverage.t
 t/pod.t

Modified: branches/upstream/libdatetime-format-natural-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/META.yml?rev=72540&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/META.yml (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/META.yml Tue Apr 12 09:59:45 2011
@@ -1,6 +1,6 @@
 ---
 name: DateTime-Format-Natural
-version: 0.93
+version: 0.94
 author:
   - 'Steven Schubiger <schubiger at cpan.org>'
 abstract: Create machine readable date/time with natural parsing logic
@@ -31,17 +31,17 @@
   Test::Pod: 1.14
   Test::Pod::Coverage: 1.04
 configure_requires:
-  Module::Build: 0.34
+  Module::Build: 0.340201
 provides:
   DateTime::Format::Natural:
     file: lib/DateTime/Format/Natural.pm
-    version: 0.93
+    version: 0.94
   DateTime::Format::Natural::Aliases:
     file: lib/DateTime/Format/Natural/Aliases.pm
     version: 0.03
   DateTime::Format::Natural::Calc:
     file: lib/DateTime/Format/Natural/Calc.pm
-    version: 1.37
+    version: 1.38
   DateTime::Format::Natural::Compat:
     file: lib/DateTime/Format/Natural/Compat.pm
     version: 0.07
@@ -51,9 +51,12 @@
   DateTime::Format::Natural::Duration::Checks:
     file: lib/DateTime/Format/Natural/Duration/Checks.pm
     version: 0.01
+  DateTime::Format::Natural::Extract:
+    file: lib/DateTime/Format/Natural/Extract.pm
+    version: 0.02
   DateTime::Format::Natural::Formatted:
     file: lib/DateTime/Format/Natural/Formatted.pm
-    version: 0.05
+    version: 0.06
   DateTime::Format::Natural::Helpers:
     file: lib/DateTime/Format/Natural/Helpers.pm
     version: 0.06
@@ -62,7 +65,7 @@
     version: 1.06
   DateTime::Format::Natural::Lang::EN:
     file: lib/DateTime/Format/Natural/Lang/EN.pm
-    version: 1.47
+    version: 1.49
   DateTime::Format::Natural::Test:
     file: lib/DateTime/Format/Natural/Test.pm
     version: 0.07
@@ -72,7 +75,7 @@
   DateTime::Format::Natural::Wrappers:
     file: lib/DateTime/Format/Natural/Wrappers.pm
     version: 0.02
-generated_by: Module::Build version 0.34
+generated_by: Module::Build version 0.340201
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
   version: 1.4

Modified: branches/upstream/libdatetime-format-natural-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/Makefile.PL?rev=72540&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/Makefile.PL (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/Makefile.PL Tue Apr 12 09:59:45 2011
@@ -1,4 +1,4 @@
-# Note: this file was auto-generated by Module::Build::Compat version 0.34
+# Note: this file was auto-generated by Module::Build::Compat version 0.340201
 use ExtUtils::MakeMaker;
 WriteMakefile
 (

Modified: branches/upstream/libdatetime-format-natural-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/README?rev=72540&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/README (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/README Tue Apr 12 09:59:45 2011
@@ -6,6 +6,9 @@
      use DateTime::Format::Natural;
 
      $parser = DateTime::Format::Natural->new;
+
+     $date_string  = $parser->extract_datetime($extract_string);
+     @date_strings = $parser->extract_datetime($extract_string);
 
      $dt = $parser->parse_datetime($date_string);
      @dt = $parser->parse_datetime_duration($date_string);
@@ -31,7 +34,6 @@
 
 CONSTRUCTOR
   new
-
     Creates a new `DateTime::Format::Natural' object. Arguments to `new()'
     are options and not necessarily required.
 
@@ -71,7 +73,6 @@
 
 METHODS
   parse_datetime
-
     Returns a DateTime object constructed from a human readable date/time
     string.
 
@@ -82,7 +83,6 @@
         The date string.
 
   parse_datetime_duration
-
     Returns one or two DateTime objects constructed from a human readable
     date/time string which may contain timespans/durations. *Same* interface
     and options as `parse_datetime()', but should be explicitly called in
@@ -91,17 +91,27 @@
      @dt = $parser->parse_datetime_duration($date_string);
      @dt = $parser->parse_datetime_duration(string => $date_string);
 
+  extract_datetime
+    Returns parsable date/time substrings (also known as expressions)
+    extracted from the string provided; in scalar context only the first
+    parsable substring is returned, whereas in list context all parsable
+    substrings are returned. Each extracted substring can then be passed to
+    the `parse_datetime()'/ `parse_datetime_duration()' methods.
+
+     $date_string  = $parser->extract_datetime($extract_string);
+     @date_strings = $parser->extract_datetime($extract_string);
+     # or
+     $date_string  = $parser->extract_datetime(string => $extract_string);
+     @date_strings = $parser->extract_datetime(string => $extract_string);
+
   success
-
     Returns a boolean indicating success or failure for parsing the
     date/time string given.
 
   error
-
     Returns the error message if the parsing did not succeed.
 
   trace
-
     Returns one or two strings with the grammar keyword for the valid
     expression parsed, traces of methods which were called within the Calc
     class and a summary how often certain units have been modified. More
@@ -168,6 +178,8 @@
      Vladimir Marek
      Rod Taylor
      Tim Esselens
+     Colm Dougan
+     Chifung Fan
 
 SEE ALSO
     DateTime, Date::Calc, http://datetime.perl.org

Modified: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural.pm?rev=72540&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural.pm (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural.pm Tue Apr 12 09:59:45 2011
@@ -6,6 +6,7 @@
     DateTime::Format::Natural::Aliases
     DateTime::Format::Natural::Calc
     DateTime::Format::Natural::Duration
+    DateTime::Format::Natural::Extract
     DateTime::Format::Natural::Formatted
     DateTime::Format::Natural::Helpers
 );
@@ -18,7 +19,7 @@
 use Scalar::Util qw(blessed);
 use Storable qw(dclone);
 
-our $VERSION = '0.93';
+our $VERSION = '0.94';
 
 validation_options(
     on_fail => sub
@@ -139,27 +140,22 @@
     $self->_rewrite_aliases(\$date_string);
     $date_string =~ tr/,//d;
 
-    my ($formatted) = $date_string =~ m!^((?:\d+?[-./])+ (?:\d+?)) \b!x;
-
-    my %count;
-    if (defined $formatted) {
-        my @count = $formatted =~ m![-./]!g;
-        $count{$_}++ foreach @count;
-    }
+    my ($formatted) = $date_string =~ $self->{data}->__regexes('format');
+    my %count = $self->_count_separators($formatted);
 
     $self->{tokens} = [];
     $self->{traces} = [];
 
-    if (scalar keys %count == 1 && $count{(keys %count)[0]} == 2) {
+    if ($self->_check_formatted('ymd', \%count)) {
         my $dt = $self->_parse_formatted_ymd($date_string, \%count);
         return $dt if blessed($dt);
     }
-    elsif (scalar keys %count == 1 && $count{(keys %count)[0]} == 1 && (keys %count)[0] eq '/') {
+    elsif ($self->_check_formatted('md', \%count)) {
         my $dt = $self->_parse_formatted_md($date_string);
         return $dt if blessed($dt);
 
         if ($self->{Prefer_future}) {
-            $self->_advance_future(qw(md));
+            $self->_advance_future('md');
         }
     }
     elsif ($date_string =~ /^([+-]) (\d+?) ([a-zA-Z]+)$/x) {
@@ -303,6 +299,18 @@
     }
 
     return @queue;
+}
+
+sub extract_datetime
+{
+    my $self = shift;
+
+    my $extract_string;
+    $self->_params_init(@_, { string => \$extract_string });
+
+    my @expressions = $self->_extract_expressions($extract_string);
+
+    return wantarray ? @expressions : $expressions[0];
 }
 
 sub success
@@ -565,6 +573,9 @@
 
  $parser = DateTime::Format::Natural->new;
 
+ $date_string  = $parser->extract_datetime($extract_string);
+ @date_strings = $parser->extract_datetime($extract_string);
+
  $dt = $parser->parse_datetime($date_string);
  @dt = $parser->parse_datetime_duration($date_string);
 
@@ -664,6 +675,20 @@
 
  @dt = $parser->parse_datetime_duration($date_string);
  @dt = $parser->parse_datetime_duration(string => $date_string);
+
+=head2 extract_datetime
+
+Returns parsable date/time substrings (also known as expressions) extracted
+from the string provided; in scalar context only the first parsable substring
+is returned, whereas in list context all parsable substrings are returned.
+Each extracted substring can then be passed to the C<parse_datetime()>/
+C<parse_datetime_duration()> methods.
+
+ $date_string  = $parser->extract_datetime($extract_string);
+ @date_strings = $parser->extract_datetime($extract_string);
+ # or
+ $date_string  = $parser->extract_datetime(string => $extract_string);
+ @date_strings = $parser->extract_datetime(string => $extract_string);
 
 =head2 success
 
@@ -743,6 +768,8 @@
  Vladimir Marek
  Rod Taylor
  Tim Esselens
+ Colm Dougan
+ Chifung Fan
 
 =head1 SEE ALSO
 

Modified: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Calc.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Calc.pm?rev=72540&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Calc.pm (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Calc.pm Tue Apr 12 09:59:45 2011
@@ -8,7 +8,7 @@
     DateTime::Format::Natural::Wrappers
 );
 
-our $VERSION = '1.37';
+our $VERSION = '1.38';
 
 use constant MORNING   => '08';
 use constant AFTERNOON => '14';
@@ -116,6 +116,7 @@
     $self->_register_trace;
     my $opts = pop;
     my ($value) = @_;
+    $self->{datetime}->set(day => 1) if $opts->{unit} eq 'month';
     if ($self->_valid_date($opts->{unit} => $value)) {
         $self->_set($opts->{unit} => $value);
     }

Added: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Extract.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Extract.pm?rev=72540&op=file
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Extract.pm (added)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Extract.pm Tue Apr 12 09:59:45 2011
@@ -1,0 +1,147 @@
+package DateTime::Format::Natural::Extract;
+
+use strict;
+use warnings;
+use base qw(DateTime::Format::Natural::Formatted);
+use boolean qw(true false);
+
+our $VERSION = '0.02';
+
+sub _extract_expressions
+{
+    my $self = shift;
+    my ($extract_string) = @_;
+
+    $extract_string =~ s/(?=[,;.])/ /g; # pretend punctuation marks are tokens
+
+    my @tokens = split /\s+/, $extract_string;
+    my %entries = %{$self->{data}->__grammar('')};
+
+    my @expressions;
+
+    my %lengths;
+    foreach my $keyword (keys %entries) {
+        $lengths{$keyword} = @{$entries{$keyword}->[0]};
+    }
+    my ($seen_expression, %skip);
+    do {
+        $seen_expression = false;
+        my $date_index;
+        for (my $i = 0; $i < @tokens; $i++) {
+            next if $skip{$i};
+            my ($formatted) = $tokens[$i] =~ $self->{data}->__regexes('format');
+            my %count = $self->_count_separators($formatted);
+            if ($self->_check_formatted('ymd', \%count)) {
+                $date_index = $i;
+                $skip{$i} = true;
+                last;
+            }
+        }
+        OUTER:
+        foreach my $keyword (sort { $lengths{$b} <=> $lengths{$a} } keys %entries) {
+            my @grammar = @{$entries{$keyword}};
+            my $types = shift @grammar;
+            my $pos = 0;
+            my @indexes;
+            for (my $i = 0; $i < @tokens; $i++) {
+                next if $skip{$i};
+                last unless defined $types->[$pos];
+                foreach my $expression (@grammar) {
+                    my $definition = $expression->[0];
+                    if ($types->[$pos] eq 'SCALAR' && defined $definition->{$pos} && $tokens[$i] =~ /^$definition->{$pos}$/i
+                     or $types->[$pos] eq 'REGEXP'                                && $tokens[$i] =~   $definition->{$pos}
+                    && (@indexes ? ($i - $indexes[-1] == 1) : true)
+                    ) {
+                        push @indexes, $i;
+                        $pos++;
+                        last;
+                    }
+                }
+                if (@indexes == $lengths{$keyword}
+                && (defined $date_index ? ($indexes[0] - $date_index == 1) : true)
+                ) {
+                    my $expression = join ' ', (defined $date_index ? $tokens[$date_index] : (), @tokens[@indexes]);
+                    my $start_index = defined $date_index ? $indexes[0] - 1 : $indexes[0];
+                    push @expressions, [ [ $start_index, $indexes[-1] ], $expression ];
+                    $skip{$_} = true foreach @indexes;
+                    $seen_expression = true;
+                    last OUTER;
+                }
+            }
+        }
+        if (defined $date_index && !$seen_expression) {
+            push @expressions, [ [ ($date_index) x 2 ], $tokens[$date_index] ];
+            $seen_expression = true;
+        }
+    } while ($seen_expression);
+
+    return $self->_finalize_expressions(\@expressions, \@tokens);
+}
+
+sub _finalize_expressions
+{
+    my $self = shift;
+    my ($expressions, $tokens) = @_;
+
+    my $timespan_sep = $self->{data}->__timespan('literal');
+    my @final_expressions;
+
+    my @duration_indexes;
+    foreach my $expression (sort { $a->[0][0] <=> $b->[0][0] } @$expressions) {
+        my $prev = $expression->[0][0] - 1;
+        my $next = $expression->[0][1] + 1;
+
+        if (defined $tokens->[$next] && $tokens->[$next] =~ /^$timespan_sep$/i) {
+            if (@final_expressions   && $tokens->[$prev] !~ /^$timespan_sep$/i) {
+                @duration_indexes = ();
+            }
+            push @duration_indexes, ($expression->[0][0] .. $expression->[0][1], $next);
+        }
+        elsif (defined $tokens->[$prev] && $tokens->[$prev] =~ /^$timespan_sep$/i) {
+            push @duration_indexes, ($expression->[0][0] .. $expression->[0][1]);
+
+            push @final_expressions, join ' ', @$tokens[@duration_indexes];
+            @duration_indexes = ();
+        }
+        else {
+            push @final_expressions, $expression->[1];
+        }
+    }
+
+    my $exclude = sub { $_[0] =~ /^\d{1,2}$/ };
+
+    return grep !$exclude->($_), @final_expressions;
+}
+
+1;
+__END__
+
+=head1 NAME
+
+DateTime::Format::Natural::Extract - Extract parsable expressions from strings
+
+=head1 SYNOPSIS
+
+ Please see the DateTime::Format::Natural documentation.
+
+=head1 DESCRIPTION
+
+C<DateTime::Format::Natural::Extract> extracts expressions from strings to be
+processed by the parse methods.
+
+=head1 SEE ALSO
+
+L<DateTime::Format::Natural>
+
+=head1 AUTHOR
+
+Steven Schubiger <schubiger at cpan.org>
+
+=head1 LICENSE
+
+This program is free software; you may redistribute it and/or
+modify it under the same terms as Perl itself.
+
+See L<http://dev.perl.org/licenses/>
+
+=cut

Modified: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Formatted.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Formatted.pm?rev=72540&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Formatted.pm (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Formatted.pm Tue Apr 12 09:59:45 2011
@@ -4,7 +4,7 @@
 use warnings;
 use boolean qw(true false);
 
-our $VERSION = '0.05';
+our $VERSION = '0.06';
 
 sub _parse_formatted_ymd
 {
@@ -150,6 +150,41 @@
     }
 }
 
+sub _count_separators
+{
+    my $self = shift;
+    my ($formatted) = @_;
+
+    my %count;
+    if (defined $formatted) {
+        my @count = $formatted =~ m![-./]!g;
+        $count{$_}++ foreach @count;
+    }
+
+    return %count;
+}
+
+sub _check_formatted
+{
+    my $self = shift;
+    my ($check, $count) = @_;
+
+    my %checks = (
+        ymd => sub
+        {
+            my ($count) = @_;
+            return scalar keys %$count == 1 && $count->{(keys %$count)[0]} == 2;
+        },
+        md => sub
+        {
+            my ($count) = @_;
+            return scalar keys %$count == 1 && $count->{(keys %$count)[0]} == 1 && (keys %$count)[0] eq '/';
+        },
+    );
+
+    return $checks{$check}->($count);
+}
+
 1;
 __END__
 

Modified: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/EN.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/EN.pm?rev=72540&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/EN.pm (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/EN.pm Tue Apr 12 09:59:45 2011
@@ -13,12 +13,13 @@
 
 use DateTime::Format::Natural::Helpers qw(%flag);
 
-our $VERSION = '1.47';
+our $VERSION = '1.49';
 
 our (%init,
      %timespan,
      %units,
      %suffixes,
+     %regexes,
      %RE,
      %data_weekdays,
      %data_weekdays_abbrev,
@@ -37,6 +38,7 @@
 %timespan = (literal => 'to');
 %units    = (ordered => [ qw(second minute hour day week month year) ]);
 %suffixes = (ordinal => join '|', qw(st nd rd th d));
+%regexes  = (format  => qr!^((?:\d+?[-./])+ (?:\d+?)) \b!x);
 
 %RE = (number    => qr/^(\d+)$/,
        year      => qr/^(\d{4})$/,
@@ -4570,7 +4572,7 @@
 
 Below are some examples of human readable date/time input in english (be aware
 that the parser does not distinguish between lower/upper case; furthermore,
-times are also parseable with precision in seconds):
+times are also parsable with precision in seconds):
 
 =head2 Simple
 

Modified: branches/upstream/libdatetime-format-natural-perl/current/t/01-parse.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/01-parse.t?rev=72540&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/01-parse.t (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/01-parse.t Tue Apr 12 09:59:45 2011
@@ -302,6 +302,7 @@
     { '3 jan 2000'                 => '03.01.2000 00:00:00'     },
     { '2010 october 28'            => '28.10.2010 00:00:00'     },
     { '27/5/1979'                  => '27.05.1979 00:00:00'     },
+    { '6'                          => '24.11.2006 06:00:00'     },
     { '4:00'                       => '24.11.2006 04:00:00'     },
     { '17:00'                      => '24.11.2006 17:00:00'     },
     { '3:20:00'                    => '24.11.2006 03:20:00'     },
@@ -309,7 +310,7 @@
     { '+2d'                        => '26.11.2006 01:13:08'     },
 );
 
-_run_tests(463, [ [ \@simple ], [ \@complex ], [ \@specific ] ], \&compare);
+_run_tests(464, [ [ \@simple ], [ \@complex ], [ \@specific ] ], \&compare);
 
 sub compare
 {

Added: branches/upstream/libdatetime-format-natural-perl/current/t/12-extract_expression.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/12-extract_expression.t?rev=72540&op=file
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/12-extract_expression.t (added)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/12-extract_expression.t Tue Apr 12 09:59:45 2011
@@ -1,0 +1,53 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use DateTime::Format::Natural;
+use DateTime::Format::Natural::Test qw($case_strings);
+use Test::More tests => 13 * 3; # case tests
+
+my @strings = (
+    { 'see you next tuesday for coffee',                    => [ 'next tuesday'                            ] },
+    { "I'll meet you on 15th march at the cinema"           => [ '15th march'                              ] },
+    { 'payment is due in 30 days'                           => [ 'in 30 days'                              ] },
+    { 'johann sebastian bach was born 21/03/1685'           => [ '21/03/1685'                              ] },
+    { '09/11/1989 18:57 was a historic moment'              => [ '09/11/1989 18:57'                        ] },
+    { 'readings start at 20:00 and 22:00'                   => [ qw(20:00 22:00)                           ] },
+    { 'conference will take place from wednesday to friday' => [ 'wednesday to friday'                     ] },
+    { 'free days are friday, saturday and sunday'           => [ qw(friday saturday sunday)                ] },
+    { 'system is stopped friday; started early monday'      => [ qw(friday monday)                         ] },
+    { '02/03/2011 midnight and 02/03/2011 noon'             => [ '02/03/2011 midnight', '02/03/2011 noon'  ] },
+    { '1969-07-20 and now'                                  => [ qw(1969-07-20 now)                        ] },
+    { '6:00 compared to 6'                                  => [ '6:00'                                    ] }, # ambiguous token missing
+    { 'yesterday to today and today to tomorrow'            => [ 'yesterday to today', 'today to tomorrow' ] },
+);
+
+compare(\@strings);
+
+sub compare
+{
+    my $aref = shift;
+
+    foreach my $href (@$aref) {
+        my $key = (keys %$href)[0];
+        foreach my $string ($case_strings->($key)) {
+            compare_strings($string, $href->{$key});
+        }
+    }
+}
+
+sub compare_strings
+{
+    my ($string, $result) = @_;
+
+    my $parser = DateTime::Format::Natural->new;
+    my @expressions = $parser->extract_datetime($string);
+
+    if (@expressions) {
+        is_deeply([ map lc, @expressions ], $result, $string);
+    }
+    else {
+        fail($string);
+    }
+}

Propchange: branches/upstream/libdatetime-format-natural-perl/current/t/12-extract_expression.t
------------------------------------------------------------------------------
    svn:executable = *

Added: branches/upstream/libdatetime-format-natural-perl/current/t/13-regression.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/13-regression.t?rev=72540&op=file
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/13-regression.t (added)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/13-regression.t Tue Apr 12 09:59:45 2011
@@ -1,0 +1,32 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::MockTime qw(set_fixed_time);
+use DateTime::Format::Natural;
+use Test::More tests => 3;
+
+{
+    local $@;
+    eval {
+        set_fixed_time('31.03.2009 04:32:22', '%d.%m.%Y %H:%M:%S');
+        DateTime::Format::Natural->new->parse_datetime('april 3');
+    };
+    ok(!$@, 'units set at once');
+}
+
+{
+    # rt #49326
+    set_fixed_time('31.08.2009', '%d.%m.%Y');
+    my $parser = DateTime::Format::Natural->new;
+    $parser->parse_datetime('30/11/2009');
+    ok($parser->success, '_check_date() sets at once');
+}
+
+{
+    set_fixed_time('29.03.2011', '%d.%m.%Y');
+    my $parser = DateTime::Format::Natural->new;
+    $parser->parse_datetime('february');
+    ok($parser->success, 'month set with current overlapping day');
+}

Propchange: branches/upstream/libdatetime-format-natural-perl/current/t/13-regression.t
------------------------------------------------------------------------------
    svn:executable = *

Added: branches/upstream/libdatetime-format-natural-perl/current/t/14-state.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/14-state.t?rev=72540&op=file
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/14-state.t (added)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/14-state.t Tue Apr 12 09:59:45 2011
@@ -1,0 +1,16 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use DateTime::Format::Natural;
+use Test::More tests => 1;
+
+{
+    # Expected to fail with first parse ('31/09/2009'), because
+    # parse_datetime_duration() retains the first failing state.
+    my $string = '31/09/2009 to 31/10/2009';
+    my $parser = DateTime::Format::Natural->new;
+    $parser->parse_datetime_duration($string);
+    ok(!$parser->success && defined $parser->error, $string);
+}

Propchange: branches/upstream/libdatetime-format-natural-perl/current/t/14-state.t
------------------------------------------------------------------------------
    svn:executable = *

Added: branches/upstream/libdatetime-format-natural-perl/current/t/15-trace.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/15-trace.t?rev=72540&op=file
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/15-trace.t (added)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/15-trace.t Tue Apr 12 09:59:45 2011
@@ -1,0 +1,66 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use DateTime::Format::Natural;
+use Test::More tests => 6;
+
+my $parser = DateTime::Format::Natural->new;
+my $stringify = sub { local $" = "\n"; "@_\n" };
+
+{
+    my $string;
+
+    $string = 'now';
+    $parser->parse_datetime($string);
+    is($stringify->(($parser->trace)[0]), <<'EOT', $string);
+now
+DateTime::Format::Natural::Calc::_no_op
+EOT
+    $string = 'yesterday 3 years ago';
+    $parser->parse_datetime($string);
+    is($stringify->(($parser->trace)[0]), <<'EOT', $string);
+ago_yesterday
+DateTime::Format::Natural::Calc::_unit_variant
+DateTime::Format::Natural::Calc::_ago_variant
+day: 1
+year: 1
+EOT
+    $string = 'monday to friday';
+    $parser->parse_datetime_duration($string);
+    is($stringify->($parser->trace), <<'EOT', $string);
+weekday
+DateTime::Format::Natural::Calc::_weekday
+day: 1
+weekday
+DateTime::Format::Natural::Calc::_weekday
+day: 1
+EOT
+}
+
+{
+    my ($string, @trace);
+
+    $string = 'bogus';
+    $parser->parse_datetime($string);
+    @trace = $parser->trace;
+    ok(!@trace, 'empty trace for parse_datetime');
+
+    $string = 'bogus to bogus';
+    $parser->parse_datetime_duration($string);
+    @trace = $parser->trace;
+    ok(!@trace, 'empty trace for parse_datetime_duration');
+}
+
+{
+    my $string = 'for 8 hours';
+    $parser->parse_datetime_duration($string);
+    is($stringify->($parser->trace), <<'EOT', $string);
+now
+DateTime::Format::Natural::Calc::_no_op
+for_count_unit
+DateTime::Format::Natural::Calc::_in_count_variant
+hour: 1
+EOT
+}

Propchange: branches/upstream/libdatetime-format-natural-perl/current/t/15-trace.t
------------------------------------------------------------------------------
    svn:executable = *




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