* Add "Days until" as a trigger * Added tests * Added test for specific date in the future * Added anchors * Updated test for fixed date in the futuremaster
parent
27868745d5
commit
efb39d76e1
|
@ -6,7 +6,7 @@ use DDG::Goodie;
|
|||
use DateTime;
|
||||
with 'DDG::GoodieRole::Dates';
|
||||
|
||||
triggers start => "days between", "days", "daysbetween", "days_between", "number of days between", "how many days between", "number of days from", "days from", "days since", "how many days since", "number of days since";
|
||||
triggers start => "days between", "days", "daysbetween", "days_between", "number of days between", "how many days between", "number of days from", "days from", "days since", "how many days since", "number of days since", "days until";
|
||||
|
||||
# 'Days since' will calculate days from the specified date to the present date, therefore answer cannot be cached
|
||||
zci is_cached => 0;
|
||||
|
@ -16,7 +16,7 @@ my $datestring_regex = datestring_regex();
|
|||
my @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
|
||||
|
||||
handle remainder => sub {
|
||||
return unless ($_ =~ qr/^($datestring_regex)$/i) || ($_ =~ qr/^($datestring_regex) (?:(?:and|to) )?($datestring_regex)(?:[,]? inclusive)?$/i);
|
||||
return unless ($_ =~ qr/^($datestring_regex) (?:(?:and|to|until) )?($datestring_regex)(?:[,]? inclusive)?$/i) || ($_ =~ qr/^($datestring_regex)$/i);
|
||||
my ($date1, $date2);
|
||||
if ($1 && $2) {
|
||||
($date1, $date2) = parse_all_datestrings_to_date($1, $2);
|
||||
|
|
|
@ -10,6 +10,8 @@ use Test::MockTime qw( :all );
|
|||
zci answer_type => 'days_between';
|
||||
zci is_cached => 0;
|
||||
|
||||
my $test_inclusive = ", inclusive";
|
||||
|
||||
sub build_structured_answer{
|
||||
my($startDate, $endDate, $daysBetween, $inclusive) = @_;
|
||||
return "There are $daysBetween days between $startDate and $endDate$inclusive",
|
||||
|
@ -28,8 +30,6 @@ sub build_test{ test_zci(build_structured_answer(@_))}
|
|||
|
||||
set_fixed_time('2016-08-03T22:36:00');
|
||||
|
||||
my $test_inclusive = ", inclusive";
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw( DDG::Goodie::DaysBetween)],
|
||||
'days between today and tomorrow' => build_test('03 Aug 2016', '04 Aug 2016', 1, ''),
|
||||
|
@ -46,9 +46,14 @@ ddg_goodie_test(
|
|||
'number of days from 2015-02-02 and 2016-02-02' => build_test('02 Feb 2015', '02 Feb 2016', 365, ''),
|
||||
'number of days from 2015-02-02 and 2016-02-02 inclusive' => build_test('02 Feb 2015', '02 Feb 2016', 366, $test_inclusive),
|
||||
'number of days between 2014-02-02 and 2015-02-02' => build_test('02 Feb 2014', '02 Feb 2015', 365, ''),
|
||||
'days since 2016-07-31' => build_test('31 Jul 2016', '03 Aug 2016', 3, ''),
|
||||
'days until tomorrow' => build_test('03 Aug 2016', '04 Aug 2016', 1, ''),
|
||||
'the day before yesterday' => undef,
|
||||
'weekdays between 2015-02-02 and 2016-02-02' => undef,
|
||||
'number of days between 2014-02-02 and 2015-02-02 inclusive' => build_test('02 Feb 2014', '02 Feb 2015', 366, $test_inclusive),
|
||||
'days since 2016-07-31' => build_test('31 Jul 2016', '03 Aug 2016', 3, ''),
|
||||
'days between jan 1 2012 and jan 1 123456' => undef
|
||||
'days until 2017-09-05' => build_test('03 Aug 2016', '05 Sep 2017', 398, ''),
|
||||
'days between jan 1 2012 and jan 1 123456' => undef,
|
||||
);
|
||||
|
||||
restore_time();
|
||||
|
|
Loading…
Reference in New Issue