Query dateranges with day-to-month-in-year granularity
Change-Id: Idea73854cc17b8e67b536fdf7b8ae40080f1051e
diff --git a/lib/Krawfish/Koral/Corpus/Field/Date.pm b/lib/Krawfish/Koral/Corpus/Field/Date.pm
index cba1832..bd056a8 100644
--- a/lib/Krawfish/Koral/Corpus/Field/Date.pm
+++ b/lib/Krawfish/Koral/Corpus/Field/Date.pm
@@ -198,25 +198,25 @@
# 2005-07-14--2005-11
# 2005-07-14--2005-11-20
- # foreach my $month ($from->month + 1 .. $to->month - 1) {
- # push @terms, $self->term_all(
- # $self->new_to_value_string(
- # $from->year, $month
- # )
- # );
- # };
+ foreach my $month ($from->month + 1 .. $to->month - 1) {
+ push @terms, $self->term_all_or_part(
+ $self->new_to_value_string(
+ $from->year, $month
+ )
+ );
+ };
# No day defined
# 2005-07-14--2005-11
-# unless ($to->day) {
-# # Store the current month as all
-# push @terms, $self->term_all(
-# $self->new_to_value_string(
-# $to->year, $to->month
-# )
-# );
-# return @terms;
-# };
+ unless ($to->day) {
+ # Get the current month as part
+ push @terms, $self->term_all_or_part(
+ $self->new_to_value_string(
+ $to->year, $to->month
+ )
+ );
+ return @terms;
+ };
# 2005-07-14--2005-11-20
}
diff --git a/t/koral/corpus/range.t b/t/koral/corpus/range.t
index a3cdd89..9c7a6d7 100644
--- a/t/koral/corpus/range.t
+++ b/t/koral/corpus/range.t
@@ -297,7 +297,12 @@
is_deeply($dr->query('2005-02-08', '2005-02-11'), [1,2,3,7], 'Query d2d-in-month');
is_deeply($dr->query('2005-02-12', '2005-02-14'), [1,2,3], 'Query d2d-in-month');
-is_deeply($dr->query('2007-10-28', '2007-11-01'), [1,2], 'Query d2d-in-month');
+
+is_deeply($dr->query('2007-10-28', '2007-11-01'), [1,2], 'Query d2d-in-year');
+
+ok($dr->add_range(8 => "2007-11-04"), 'Add day');
+ok($dr->add_range(9 => "2007-11-04"), 'Add day');
+is_deeply($dr->query('2007-10-28', '2007-12'), [1,2,8,9], 'Query d2m-in-year');
# TODO:
# normalize 2007-01-01--2008-12-31