r53206 - 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
Mon Feb 22 19:32:40 UTC 2010
Author: angelabad-guest
Date: Mon Feb 22 19:32:24 2010
New Revision: 53206
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=53206
Log:
[svn-upgrade] Integrating new upstream version, libdatetime-format-natural-perl (0.84)
Added:
branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Aliases.pm
branches/upstream/libdatetime-format-natural-perl/current/t/09-parse_aliases.t (with props)
branches/upstream/libdatetime-format-natural-perl/current/t/10-regression.t (with props)
branches/upstream/libdatetime-format-natural-perl/current/t/11-state.t (with props)
branches/upstream/libdatetime-format-natural-perl/current/t/12-trace.t (with props)
Removed:
branches/upstream/libdatetime-format-natural-perl/current/t/09-regression.t
branches/upstream/libdatetime-format-natural-perl/current/t/10-state.t
branches/upstream/libdatetime-format-natural-perl/current/t/11-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/README
branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural.pm
branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Compat.pm
branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/Base.pm
branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/EN.pm
branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Test.pm
branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Utils.pm
branches/upstream/libdatetime-format-natural-perl/current/t/00-load.t
branches/upstream/libdatetime-format-natural-perl/current/t/01-parse.t
branches/upstream/libdatetime-format-natural-perl/current/t/02-parse_format.t
branches/upstream/libdatetime-format-natural-perl/current/t/03-parse_daytime.t
branches/upstream/libdatetime-format-natural-perl/current/t/04-parse_durations.t
branches/upstream/libdatetime-format-natural-perl/current/t/05-parse_time_zone.t
branches/upstream/libdatetime-format-natural-perl/current/t/06-parse_prefer_future.t
branches/upstream/libdatetime-format-natural-perl/current/t/07-parse_datetime.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=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/Changes (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/Changes Mon Feb 22 19:32:24 2010
@@ -1,4 +1,37 @@
Revision history for Perl extension DateTime::Format::Natural.
+
+0.84 2010-02-22 <schubiger at cpan.org>
+
+ - Merged development version to stable.
+
+0.83_04 2010-02-16 <schubiger at cpan.org>
+
+ - Enhance the regular expression matching a non-word alias.
+
+ - Correct the indentation of _Nth_Weekday_of_Month_Year().
+
+0.83_03 2010-02-14 <schubiger at cpan.org>
+
+ - Introduce short name aliases. [rt #53976 - Kevin Field]
+
+ - Support shortened relative dates with a +/- prefix.
+ [rt #53976 - Kevin Field]
+
+ - Add according tests for aliases and prefixed dates.
+
+ - Test for case-insensitive processing of input strings.
+
+ - Test compile-time loading of Aliases.pm.
+
+0.83_02 Wed Jan 27 10:42:41 CET 2010
+
+ - New supported formats: <time> <weekday> and <time> on <weekday>.
+ [rt #53979 - Kevin Field]
+
+0.83_01 Mon Jan 18 10:28:42 CET 2010
+
+ - Pass the time zone object instead of name to the final DateTime
+ constructor. [rt #53268 - Eric Wilhelm]
0.83 Wed Jan 13 15:51:11 CET 2010
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=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/MANIFEST (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/MANIFEST Mon Feb 22 19:32:24 2010
@@ -2,6 +2,7 @@
Changes
INSTALL
lib/DateTime/Format/Natural.pm
+lib/DateTime/Format/Natural/Aliases.pm
lib/DateTime/Format/Natural/Base.pm
lib/DateTime/Format/Natural/Compat.pm
lib/DateTime/Format/Natural/Duration.pm
@@ -26,8 +27,9 @@
t/06-parse_prefer_future.t
t/07-parse_datetime.t
t/08-parse_failure.t
-t/09-regression.t
-t/10-state.t
-t/11-trace.t
+t/09-parse_aliases.t
+t/10-regression.t
+t/11-state.t
+t/12-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=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/META.yml (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/META.yml Mon Feb 22 19:32:24 2010
@@ -1,6 +1,6 @@
---
name: DateTime-Format-Natural
-version: 0.83
+version: 0.84
author:
- 'Steven Schubiger <schubiger at cpan.org>'
abstract: Create machine readable date/time with natural parsing logic
@@ -29,13 +29,16 @@
provides:
DateTime::Format::Natural:
file: lib/DateTime/Format/Natural.pm
- version: 0.83
+ version: 0.84
+ DateTime::Format::Natural::Aliases:
+ file: lib/DateTime/Format/Natural/Aliases.pm
+ version: 0.02
DateTime::Format::Natural::Base:
file: lib/DateTime/Format/Natural/Base.pm
version: 1.31
DateTime::Format::Natural::Compat:
file: lib/DateTime/Format/Natural/Compat.pm
- version: 0.06
+ version: 0.07
DateTime::Format::Natural::Duration:
file: lib/DateTime/Format/Natural/Duration.pm
version: 0.04
@@ -47,16 +50,16 @@
version: 0.05
DateTime::Format::Natural::Lang::Base:
file: lib/DateTime/Format/Natural/Lang/Base.pm
- version: 1.03
+ version: 1.04
DateTime::Format::Natural::Lang::EN:
file: lib/DateTime/Format/Natural/Lang/EN.pm
- version: 1.29
+ version: 1.31
DateTime::Format::Natural::Test:
file: lib/DateTime/Format/Natural/Test.pm
- version: 0.04
+ version: 0.05
DateTime::Format::Natural::Utils:
file: lib/DateTime/Format/Natural/Utils.pm
- version: 0.03
+ version: 0.04
DateTime::Format::Natural::Wrappers:
file: lib/DateTime/Format/Natural/Wrappers.pm
version: 0.02
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=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/README (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/README Mon Feb 22 19:32:24 2010
@@ -160,6 +160,8 @@
Christian Brink
Giovanni Pensa
Andrew Sterling Hanenkamp
+ Eric Wilhelm
+ Kevin Field
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=53206&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 Mon Feb 22 19:32:24 2010
@@ -3,6 +3,7 @@
use strict;
use warnings;
use base qw(
+ DateTime::Format::Natural::Aliases
DateTime::Format::Natural::Base
DateTime::Format::Natural::Duration
DateTime::Format::Natural::Formatted
@@ -12,12 +13,12 @@
use Carp qw(croak);
use DateTime ();
-use List::MoreUtils qw(all any);
+use List::MoreUtils qw(all any none);
use Params::Validate ':all';
use Scalar::Util qw(blessed);
use Storable qw(dclone);
-our $VERSION = '0.83';
+our $VERSION = '0.84';
validation_options(
on_fail => sub
@@ -136,6 +137,8 @@
$self->{Input_string} = $self->{Date_string};
my $date_string = $self->{Date_string};
+
+ $self->_rewrite_aliases(\$date_string);
$date_string =~ tr/,//d;
my ($formatted) = $date_string =~ m!^((?:\d+?[-./])+ (?:\d+?)) \b!x;
@@ -160,6 +163,24 @@
if ($self->{Prefer_future}) {
$self->_advance_future(qw(md));
}
+ }
+ elsif ($date_string =~ /^([+-]) (\d+?) ([a-zA-Z]+)$/x) {
+ my ($prefix, $value, $unit) = ($1, $2, lc $3);
+
+ my %methods = (
+ '+' => '_add',
+ '-' => '_subtract',
+ );
+ my $method = $methods{$prefix};
+
+ if (none { $unit =~ /${_}s?/ } @{$self->{data}->__units('ordered')}) {
+ $self->_set_failure;
+ $self->_set_error("(invalid unit)");
+ return $self->_get_datetime_object;
+ }
+ $self->$method($unit => $value);
+
+ $self->_set_valid_exp;
}
else {
@{$self->{tokens}} = split /\s+/, $date_string;
@@ -482,7 +503,7 @@
my $self = shift;
my $dt = DateTime->new(
- time_zone => $self->{datetime}->time_zone->name,
+ time_zone => $self->{datetime}->time_zone,
year => $self->{datetime}->year,
month => $self->{datetime}->month,
day => $self->{datetime}->day_of_month,
@@ -695,6 +716,8 @@
Christian Brink
Giovanni Pensa
Andrew Sterling Hanenkamp
+ Eric Wilhelm
+ Kevin Field
=head1 SEE ALSO
Added: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Aliases.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Aliases.pm?rev=53206&op=file
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Aliases.pm (added)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Aliases.pm Mon Feb 22 19:32:24 2010
@@ -1,0 +1,66 @@
+package DateTime::Format::Natural::Aliases;
+
+use strict;
+use warnings;
+
+our $VERSION = '0.02';
+
+sub _rewrite_aliases
+{
+ my $self = shift;
+ my ($date_string) = @_;
+
+ my $aliases = $self->{data}->{aliases};
+
+ if ($$date_string =~ /\s+/) {
+ foreach my $type (qw(all tokens)) {
+ foreach my $alias (keys %{$aliases->{$type}}) {
+ if ($alias =~ /^\w+$/) {
+ $$date_string =~ s/\b $alias \b/$aliases->{$type}{$alias}/ix;
+ }
+ else {
+ $$date_string =~ s/(?:^|(?<=\s)) $alias (?:(?=\s)|$)/$aliases->{$type}{$alias}/ix;
+ }
+ }
+ }
+ }
+ else {
+ foreach my $type (qw(all short)) {
+ foreach my $alias (keys %{$aliases->{$type}}) {
+ $$date_string =~ s/$alias $/$aliases->{$type}{$alias}/ix;
+ }
+ }
+ }
+}
+
+1;
+__END__
+
+=head1 NAME
+
+DateTime::Format::Natural::Aliases - Aliasing of date strings
+
+=head1 SYNOPSIS
+
+ Please see the DateTime::Format::Natural documentation.
+
+=head1 DESCRIPTION
+
+The C<DateTime::Format::Natural::Aliases> class handles aliases for date strings.
+
+=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/Compat.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Compat.pm?rev=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Compat.pm (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Compat.pm Mon Feb 22 19:32:24 2010
@@ -8,7 +8,7 @@
our ($VERSION, $Pure);
-$VERSION = '0.06';
+$VERSION = '0.07';
BEGIN
{
@@ -99,22 +99,22 @@
sub _Nth_Weekday_of_Month_Year
{
- my $self = shift;
+ my $self = shift;
- if ($Pure) {
- my ($year, $month, $weekday, $count) = @_;
- my $dt = $self->{datetime}->clone;
- $dt->set_year($year);
- $dt->set_month($month);
- $dt->set_day(1);
- $dt->set_day($dt->day + 1)
- while ($weekday ne $dt->dow);
- $dt->set_day($dt->day + 7 * ($count - 1));
- return ($dt->year, $dt->month, $dt->day);
- }
- else {
- return Nth_Weekday_of_Month_Year(@_);
- }
+ if ($Pure) {
+ my ($year, $month, $weekday, $count) = @_;
+ my $dt = $self->{datetime}->clone;
+ $dt->set_year($year);
+ $dt->set_month($month);
+ $dt->set_day(1);
+ $dt->set_day($dt->day + 1)
+ while ($weekday ne $dt->dow);
+ $dt->set_day($dt->day + 7 * ($count - 1));
+ return ($dt->year, $dt->month, $dt->day);
+ }
+ else {
+ return Nth_Weekday_of_Month_Year(@_);
+ }
}
sub _check_date
Modified: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/Base.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/Base.pm?rev=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/Base.pm (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Lang/Base.pm Mon Feb 22 19:32:24 2010
@@ -5,7 +5,7 @@
our ($VERSION, $AUTOLOAD);
-$VERSION = '1.03';
+$VERSION = '1.04';
sub __new
{
@@ -23,6 +23,7 @@
$obj->{conversion} = \%{"${class}::data_conversion"};
$obj->{helpers} = \%{"${class}::data_helpers"};
$obj->{duration} = \%{"${class}::data_duration"};
+ $obj->{aliases} = \%{"${class}::data_aliases"};
return bless $obj, ref($class) || $class;
}
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=53206&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 Mon Feb 22 19:32:24 2010
@@ -9,10 +9,11 @@
use DateTime::Format::Natural::Helpers qw(%flag);
-our $VERSION = '1.29';
+our $VERSION = '1.31';
our (%init,
%timespan,
+ %units,
%RE,
%data_weekdays,
%data_weekdays_abbrev,
@@ -23,11 +24,13 @@
%data_conversion,
%data_helpers,
%data_duration,
+ %data_aliases,
%extended_checks,
%grammar);
-%init = (tokens => sub {});
+%init = (tokens => sub {});
%timespan = (literal => 'to');
+%units = (ordered => [ qw(second minute hour day week month year) ]);
%RE = (number => qr/^(\d+)$/,
year => qr/^(\d{4})$/,
@@ -79,7 +82,7 @@
);
%data_helpers = (
- suffix => qr/s$/,
+ suffix => qr/s$/i,
normalize => sub { ${$_[0]} = ucfirst lc ${$_[0]} },
abbreviated => sub { length ${$_[0]} == 3 },
);
@@ -105,6 +108,21 @@
return (@$date_strings == 2
&& $date_strings->[0] =~ /^$date \s+ $time$/x
&& $date_strings->[1] =~ /^$time$/);
+ },
+ );
+
+ %data_aliases = (
+ all => {
+ tues => 'tue',
+ thurs => 'thu',
+ },
+ tokens => {
+ mins => 'minutes',
+ '@' => 'at',
+ },
+ short => {
+ min => 'minute',
+ d => 'day',
},
);
}
@@ -1507,6 +1525,40 @@
truncate_to => 'minute',
},
],
+ [
+ { 0 => $RE{time_am}, 1 => $RE{weekday} },
+ [],
+ [],
+ [
+ [ 0 ],
+ [
+ { 1 => [ $flag{weekday_name}, $flag{weekday_num} ] },
+ ],
+ ],
+ [ {}, {} ],
+ [ '_at', '_weekday' ],
+ {
+ prefer_future => true,
+ truncate_to => 'minute',
+ },
+ ],
+ [
+ { 0 => $RE{time_pm}, 1 => $RE{weekday} },
+ [],
+ [],
+ [
+ [ 0 ],
+ [
+ { 1 => [ $flag{weekday_name}, $flag{weekday_num} ] },
+ ],
+ ],
+ [ { hours => 12 }, {} ],
+ [ '_at', '_weekday' ],
+ {
+ prefer_future => true,
+ truncate_to => 'minute',
+ },
+ ],
],
time => [
[ 'REGEXP' ],
@@ -1944,7 +1996,7 @@
weekday_ago_at_time => [
[ 'REGEXP', 'REGEXP', 'REGEXP', 'SCALAR', 'SCALAR', 'REGEXP' ],
[
- { 0 => $RE{weekday}, 1 => $RE{number}, 2 => qr/^(months?)$/, 3 => 'ago', 4 => 'at', 5 => $RE{time_am} },
+ { 0 => $RE{weekday}, 1 => $RE{number}, 2 => qr/^(months?)$/i, 3 => 'ago', 4 => 'at', 5 => $RE{time_am} },
[ [ 1, 2 ] ],
[ $extended_checks{suffix} ],
[
@@ -1959,7 +2011,7 @@
{ truncate_to => 'minute' },
],
[
- { 0 => $RE{weekday}, 1 => $RE{number}, 2 => qr/^(months?)$/, 3 => 'ago', 4 => 'at', 5 => $RE{time_pm} },
+ { 0 => $RE{weekday}, 1 => $RE{number}, 2 => qr/^(months?)$/i, 3 => 'ago', 4 => 'at', 5 => $RE{time_pm} },
[ [ 1, 2 ] ],
[ $extended_checks{suffix} ],
[
@@ -2983,6 +3035,43 @@
],
[ {}, { hours => 12 } ],
[ '_weekday', '_at' ],
+ {
+ prefer_future => true,
+ truncate_to => 'minute',
+ },
+ ],
+ ],
+ time_on_weekday => [
+ [ 'REGEXP', 'SCALAR', 'REGEXP' ],
+ [
+ { 0 => $RE{time_am}, 1 => 'on', 2 => $RE{weekday} },
+ [],
+ [],
+ [
+ [ 0 ],
+ [
+ { 2 => [ $flag{weekday_name}, $flag{weekday_num} ] },
+ ],
+ ],
+ [ {}, {} ],
+ [ '_at', '_weekday' ],
+ {
+ prefer_future => true,
+ truncate_to => 'minute',
+ },
+ ],
+ [
+ { 0 => $RE{time_pm}, 1 => 'on', 2 => $RE{weekday} },
+ [],
+ [],
+ [
+ [ 0 ],
+ [
+ { 2 => [ $flag{weekday_name}, $flag{weekday_num} ] },
+ ],
+ ],
+ [ { hours => 12 }, {} ],
+ [ '_at', '_weekday' ],
{
prefer_future => true,
truncate_to => 'minute',
@@ -3489,6 +3578,10 @@
4pm
4:20pm
mon 2:35
+ 1am sun
+ 1pm sun
+ 1am on sun
+ 1pm on sun
=head2 Complex
@@ -3606,7 +3699,7 @@
for 4 months
for 4 years
-=head2 Specific Dates
+=head2 Specific
march
January 11
@@ -3627,6 +3720,17 @@
4:00
17:00
3:20:00
+ -5min
+ +2d
+
+=head2 Aliases
+
+ 5 mins ago
+ yesterday @ noon
+ tues this week
+ final thurs in sep
+ tues
+ thurs
=head1 SEE ALSO
Modified: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Test.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Test.pm?rev=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Test.pm (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Test.pm Mon Feb 22 19:32:24 2010
@@ -7,11 +7,11 @@
use Test::More;
-our ($VERSION, @EXPORT, %time);
+our ($VERSION, @EXPORT, %time, $case_strings);
-$VERSION = '0.04';
+$VERSION = '0.05';
- at EXPORT = qw(%time _run_tests _result_string _message);
+ at EXPORT = qw(%time $case_strings _run_tests _result_string _message);
%time = map { split /:/ }
split /\n/,
@@ -20,9 +20,13 @@
chomp;
$_ };
+$case_strings = sub { ($_[0], lc $_[0], uc $_[0]) };
+
sub _run_tests
{
my ($tests, $sets, $check) = @_;
+
+ $tests *= 3; # case tests
local $@;
Modified: branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Utils.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Utils.pm?rev=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Utils.pm (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/lib/DateTime/Format/Natural/Utils.pm Mon Feb 22 19:32:24 2010
@@ -4,7 +4,7 @@
use warnings;
use boolean qw(true false);
-our $VERSION = '0.03';
+our $VERSION = '0.04';
sub _valid_date
{
@@ -64,7 +64,7 @@
return undef unless (@$trace || %$modified);
my $i;
- my %order = map { $_ => $i++ } qw(second minute hour day week month year);
+ my %order = map { $_ => $i++ } @{$self->{data}->__units('ordered')};
return join "\n", @$trace,
map { my $unit = $_; "$unit: $modified->{$unit}" }
Modified: branches/upstream/libdatetime-format-natural-perl/current/t/00-load.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/00-load.t?rev=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/00-load.t (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/00-load.t Mon Feb 22 19:32:24 2010
@@ -3,12 +3,13 @@
use strict;
use warnings;
-use Test::More tests => 11;
+use Test::More tests => 12;
BEGIN
{
my @modules = qw(
DateTime::Format::Natural
+ DateTime::Format::Natural::Aliases
DateTime::Format::Natural::Base
DateTime::Format::Natural::Compat
DateTime::Format::Natural::Duration
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=53206&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 Mon Feb 22 19:32:24 2010
@@ -126,6 +126,10 @@
{ '4pm' => '24.11.2006 16:00:00' },
{ '4:20pm' => '24.11.2006 16:20:00' },
{ 'mon 2:35' => '20.11.2006 02:35:00' },
+ { '1am sun' => '26.11.2006 01:00:00' },
+ { '1pm sun' => '26.11.2006 13:00:00' },
+ { '1am on sun' => '26.11.2006 01:00:00' },
+ { '1pm on sun' => '26.11.2006 13:00:00' },
);
my @complex = (
@@ -241,16 +245,21 @@
{ '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' },
+ { '-5min' => '24.11.2006 01:08:08' },
+ { '+2d' => '26.11.2006 01:13:08' },
);
-_run_tests(226, [ [ \@simple ], [ \@complex ], [ \@specific ] ], \&compare);
+_run_tests(232, [ [ \@simple ], [ \@complex ], [ \@specific ] ], \&compare);
sub compare
{
my $aref = shift;
+
foreach my $href (@$aref) {
my $key = (keys %$href)[0];
- compare_strings($key, $href->{$key});
+ foreach my $string ($case_strings->($key)) {
+ compare_strings($string, $href->{$key});
+ }
}
}
Modified: branches/upstream/libdatetime-format-natural-perl/current/t/02-parse_format.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/02-parse_format.t?rev=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/02-parse_format.t (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/02-parse_format.t Mon Feb 22 19:32:24 2010
@@ -22,9 +22,12 @@
sub compare
{
my $aref = shift;
+
foreach my $href (@$aref) {
my $key = (keys %$href)[0];
- compare_strings($key, $href->{$key}->[0], $href->{$key}->[1]);
+ foreach my $string ($case_strings->($key)) {
+ compare_strings($string, $href->{$key}->[0], $href->{$key}->[1]);
+ }
}
}
Modified: branches/upstream/libdatetime-format-natural-perl/current/t/03-parse_daytime.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/03-parse_daytime.t?rev=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/03-parse_daytime.t (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/03-parse_daytime.t Mon Feb 22 19:32:24 2010
@@ -30,9 +30,12 @@
sub compare
{
my ($aref, $opts) = @_;
+
foreach my $href (@$aref) {
my $key = (keys %$href)[0];
- compare_strings($key, $href->{$key}, $opts);
+ foreach my $string ($case_strings->($key)) {
+ compare_strings($string, $href->{$key}, $opts);
+ }
}
}
Modified: branches/upstream/libdatetime-format-natural-perl/current/t/04-parse_durations.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/04-parse_durations.t?rev=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/04-parse_durations.t (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/04-parse_durations.t Mon Feb 22 19:32:24 2010
@@ -42,9 +42,12 @@
sub compare
{
my $aref = shift;
+
foreach my $href (@$aref) {
my $key = (keys %$href)[0];
- compare_strings($key, $href->{$key});
+ foreach my $string ($case_strings->($key)) {
+ compare_strings($string, $href->{$key});
+ }
}
}
Modified: branches/upstream/libdatetime-format-natural-perl/current/t/05-parse_time_zone.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/05-parse_time_zone.t?rev=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/05-parse_time_zone.t (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/05-parse_time_zone.t Mon Feb 22 19:32:24 2010
@@ -81,9 +81,12 @@
sub compare
{
my $aref = shift;
+
foreach my $href (@$aref) {
my $key = (keys %$href)[0];
- compare_strings($key, $href->{$key});
+ foreach my $string ($case_strings->($key)) {
+ compare_strings($string, $href->{$key});
+ }
}
}
Modified: branches/upstream/libdatetime-format-natural-perl/current/t/06-parse_prefer_future.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/06-parse_prefer_future.t?rev=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/06-parse_prefer_future.t (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/06-parse_prefer_future.t Mon Feb 22 19:32:24 2010
@@ -47,6 +47,10 @@
{ 'friday 03:00 pm' => '24.11.2006 15:00:00' },
{ 'monday at 03:00 am' => '27.11.2006 03:00:00' },
{ 'monday at 03:00 pm' => '27.11.2006 15:00:00' },
+ { '4am thu' => '30.11.2006 04:00:00' },
+ { '4pm thu' => '30.11.2006 16:00:00' },
+ { '4am on thu' => '30.11.2006 04:00:00' },
+ { '4pm on thu' => '30.11.2006 16:00:00' },
);
my @formatted = (
@@ -54,14 +58,17 @@
{ '12/24' => '24.12.2006 00:00:00' },
);
-_run_tests(28, [ [ \@simple ], [ \@combined ], [ \@formatted ] ], \&compare);
+_run_tests(32, [ [ \@simple ], [ \@combined ], [ \@formatted ] ], \&compare);
sub compare
{
my $aref = shift;
+
foreach my $href (@$aref) {
my $key = (keys %$href)[0];
- compare_strings($key, $href->{$key});
+ foreach my $string ($case_strings->($key)) {
+ compare_strings($string, $href->{$key});
+ }
}
}
Modified: branches/upstream/libdatetime-format-natural-perl/current/t/07-parse_datetime.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/07-parse_datetime.t?rev=53206&op=diff
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/07-parse_datetime.t (original)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/07-parse_datetime.t Mon Feb 22 19:32:24 2010
@@ -16,9 +16,12 @@
sub compare
{
my $aref = shift;
+
foreach my $href (@$aref) {
my $key = (keys %$href)[0];
- compare_strings($key, $href->{$key});
+ foreach my $string ($case_strings->($key)) {
+ compare_strings($string, $href->{$key});
+ }
}
}
Added: branches/upstream/libdatetime-format-natural-perl/current/t/09-parse_aliases.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/09-parse_aliases.t?rev=53206&op=file
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/09-parse_aliases.t (added)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/09-parse_aliases.t Mon Feb 22 19:32:24 2010
@@ -1,0 +1,48 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use DateTime::Format::Natural;
+use DateTime::Format::Natural::Test;
+use Test::More;
+
+my @aliases = (
+ { '5 mins ago' => '24.11.2006 01:08:08' },
+ { 'yesterday @ noon' => '23.11.2006 12:00:00' },
+ { 'tues this week' => '21.11.2006 00:00:00' },
+ { 'final thurs in sep' => '28.09.2006 00:00:00' },
+ { 'tues' => '21.11.2006 00:00:00' },
+ { 'thurs' => '23.11.2006 00:00:00' },
+);
+
+_run_tests(6, [ [ \@aliases ] ], \&compare);
+
+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;
+ $parser->_set_datetime(\%time);
+
+ my $dt = $parser->parse_datetime($string);
+
+ if ($parser->success) {
+ is(_result_string($dt), $result, _message($string));
+ }
+ else {
+ fail(_message($string));
+ }
+}
Propchange: branches/upstream/libdatetime-format-natural-perl/current/t/09-parse_aliases.t
------------------------------------------------------------------------------
svn:executable = *
Added: branches/upstream/libdatetime-format-natural-perl/current/t/10-regression.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/10-regression.t?rev=53206&op=file
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/10-regression.t (added)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/10-regression.t Mon Feb 22 19:32:24 2010
@@ -1,0 +1,23 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::MockTime qw(set_fixed_time);
+use DateTime::Format::Natural;
+use Test::More tests => 2;
+
+{
+ 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');
+}
Propchange: branches/upstream/libdatetime-format-natural-perl/current/t/10-regression.t
------------------------------------------------------------------------------
svn:executable = *
Added: branches/upstream/libdatetime-format-natural-perl/current/t/11-state.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/11-state.t?rev=53206&op=file
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/11-state.t (added)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/11-state.t Mon Feb 22 19:32:24 2010
@@ -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/11-state.t
------------------------------------------------------------------------------
svn:executable = *
Added: branches/upstream/libdatetime-format-natural-perl/current/t/12-trace.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdatetime-format-natural-perl/current/t/12-trace.t?rev=53206&op=file
==============================================================================
--- branches/upstream/libdatetime-format-natural-perl/current/t/12-trace.t (added)
+++ branches/upstream/libdatetime-format-natural-perl/current/t/12-trace.t Mon Feb 22 19:32:24 2010
@@ -1,0 +1,50 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use DateTime::Format::Natural;
+use Test::More tests => 5;
+
+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);
+DateTime::Format::Natural::Base::_no_op
+EOT
+ $string = 'yesterday 3 years ago';
+ $parser->parse_datetime($string);
+ is($stringify->(($parser->trace)[0]), <<'EOT', $string);
+DateTime::Format::Natural::Base::_unit_variant
+DateTime::Format::Natural::Base::_ago_variant
+day: 1
+year: 1
+EOT
+ $string = 'monday to friday';
+ $parser->parse_datetime_duration($string);
+ is($stringify->($parser->trace), <<'EOT', $string);
+DateTime::Format::Natural::Base::_weekday
+day: 1
+DateTime::Format::Natural::Base::_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');
+}
Propchange: branches/upstream/libdatetime-format-natural-perl/current/t/12-trace.t
------------------------------------------------------------------------------
svn:executable = *
More information about the Pkg-perl-cvs-commits
mailing list