Subject: | Fix parsing of "<=" |
Date::RangeParser::EN was parsing "<= 12/31/2012" identically to "< 12/31/2012" (both were excluding the 31st). This fixes that issue, while enhancing the parsing to also allow "<=12/31/2012" (with no space after the <=).
Subject: | range_parser_less_than.patch |
diff --git a/Date-RangeParser-EN-0.07/Changes b/Date-RangeParser-EN-0.07/Changes
index 9ae2856..79309b0 100644
--- a/Date-RangeParser-EN-0.07/Changes
+++ b/Date-RangeParser-EN-0.07/Changes
@@ -1,5 +1,10 @@
Revision history for Perl extension Date::RangeParser::EN
+0.08 Wed May 07 09:55:24 2014
+ - Fix bug where "<= [element]" returned the same as "< [element]"
+ - Add support for comparison operators without a following space
+ * eg. ">[element]"
+
0.07 Fri Apr 18 12:26:13 2014
- Add support for infinite datetimes
- Add support for parsing
diff --git a/Date-RangeParser-EN-0.07/lib/Date/RangeParser/EN.pm b/Date-RangeParser-EN-0.07/lib/Date/RangeParser/EN.pm
index a6417de..1ec74d3 100644
--- a/Date-RangeParser-EN-0.07/lib/Date/RangeParser/EN.pm
+++ b/Date-RangeParser-EN-0.07/lib/Date/RangeParser/EN.pm
@@ -6,7 +6,7 @@ use warnings;
use Date::Manip;
use DateTime;
-our $VERSION = '0.07';
+our $VERSION = '0.08';
=head1 NAME
@@ -668,8 +668,13 @@ sub parse_range
(undef, $end) = $self->parse_range($second);
}
- elsif ($string =~ /^(?:before|<) /i) {
- $string =~ s/^(?:before|<) //i;
+ elsif ($string =~ /^<=/) {
+ $string =~ s/^<=//;
+ $beg = $self->_infinite_past_class->new();
+ (undef, $end) = $self->parse_range($string);
+ }
+ elsif ($string =~ /^(?:before |<)/i) {
+ $string =~ s/^(?:before |<)//i;
($end) = $self->parse_range($string);
if ( defined $end ) {
@@ -677,14 +682,14 @@ sub parse_range
$end = $end->subtract(seconds => 1);
}
}
- elsif ($string =~ /^<= /) {
- $string =~ s/^<= //;
- $beg = $self->_infinite_past_class->new();
- ($end) = $self->parse_range($string);
- }
- elsif ($string =~ /^(?:after|>) /i) {
- $string =~ s/^(?:after|>) //i;
+ elsif ($string =~ /^>=/) {
+ $string =~ s/^>=//;
+ ($beg) = $self->parse_range($string);
+ $end = $self->_infinite_future_class->new();
+ }
+ elsif ($string =~ /^(?:after |>)/i) {
+ $string =~ s/^(?:after |>)//i;
(undef, $beg) = $self->parse_range($string);
if ( defined $beg ) {
@@ -692,11 +697,6 @@ sub parse_range
$end = $self->_infinite_future_class->new();
}
}
- elsif ($string =~ /^>= /) {
- $string =~ s/^>= //;
- ($beg) = $self->parse_range($string);
- $end = $self->_infinite_future_class->new();
- }
elsif ($string =~ /^since /i) {
$string =~ s/^since //i;
diff --git a/Date-RangeParser-EN-0.07/t/01-parse_range.t b/Date-RangeParser-EN-0.07/t/01-parse_range.t
index 248804b..107a107 100644
--- a/Date-RangeParser-EN-0.07/t/01-parse_range.t
+++ b/Date-RangeParser-EN-0.07/t/01-parse_range.t
@@ -401,10 +401,22 @@ my @tests = (
beg => '-inf',
end => '04/17/2014 11:59PM',
}, {
+ # same as previous test, w/o a space after <
+ date_range_string => '<4/18/2014',
+ as_of => '2010-01-28',
+ beg => '-inf',
+ end => '04/17/2014 11:59PM',
+ }, {
date_range_string => '<= 12/25/2013',
as_of => '2014-04-18',
beg => '-inf',
- end => '12/25/2013 12:00AM',
+ end => '12/25/2013 11:59PM',
+ }, {
+ # same as previous test, w/o a space after <=
+ date_range_string => '<=12/25/2013',
+ as_of => '2014-04-18',
+ beg => '-inf',
+ end => '12/25/2013 11:59PM',
}, {
date_range_string => 'after 2/5/1990',
as_of => '2014-04-18',
@@ -416,11 +428,23 @@ my @tests = (
beg => '02/06/1990 12:00AM',
end => 'inf',
}, {
+ # same as previous test, w/o a space after >
+ date_range_string => '>2/5/1990',
+ as_of => '2010-01-28',
+ beg => '02/06/1990 12:00AM',
+ end => 'inf',
+ }, {
date_range_string => '>= 07/04/2776',
as_of => '1776-07-04',
beg => '07/04/2776 12:00AM',
end => 'inf',
}, {
+ # same as previous test, w/o a space after >=
+ date_range_string => '>=07/04/2776',
+ as_of => '1776-07-04',
+ beg => '07/04/2776 12:00AM',
+ end => 'inf',
+ }, {
# "after X" means "after the end of X"
# "after today" extends into infinity (it doesn't end)
# thus "after after today" means "after the end of infinity"