SunInfo: expand triggering.

Allow for different ordering of terms.
master
Matt Miller 2014-10-10 10:59:21 +02:00
parent cd2b374fe4
commit 227e930310
2 changed files with 7 additions and 6 deletions

View File

@ -10,7 +10,7 @@ use DateTime::Event::Sunrise;
zci answer_type => "sun_info";
zci is_cached => 0;
triggers start => 'sunrise', 'sunset', 'what time is sunset', 'what time is sunrise';
triggers startend => 'sunrise', 'sunset', 'what time is sunset', 'what time is sunrise';
primary_example_queries 'sunrise', 'sunset';
secondary_example_queries 'sunrise for aug 30', 'sunset on 2015-01-01';
@ -44,7 +44,7 @@ handle remainder => sub {
my $dt;
if (!$remainder) {
$dt = DateTime->now;
} elsif ($remainder =~ /^(?:on|for)\s+(?<when>$datestring_regex)$/) {
} elsif ($remainder =~ /^(?:on|for)?\s*(?<when>$datestring_regex)$/) {
$dt = parse_datestring_to_date($+{'when'});
}
return unless $dt; # Also going to need to know which day.

View File

@ -16,18 +16,19 @@ my @exact = (
html => qr{^<div class='zci--suninfo'><div class='suninfo--header text--secondary'><span class='ddgsi'>.*4:46pm</div></div></div>$},
);
ddg_goodie_test([qw(
DDG::Goodie::SunInfo
)
],
ddg_goodie_test(
[qw( DDG::Goodie::SunInfo )],
'sunrise' => test_zci(@now),
'what time is sunrise' => test_zci(@now),
'sunset' => test_zci(@now),
'what time is sunset' => test_zci(@now),
'sunrise for aug 30' => test_zci(@aug),
'sunrise 30 aug' => test_zci(@aug),
'sunset for aug 30?' => test_zci(@aug),
'sunset aug 30th' => test_zci(@aug),
'sunset on 2015-01-01' => test_zci(@exact),
'what time is sunrise on 2015-01-01?' => test_zci(@exact),
'January 1st, 2015 sunrise' => test_zci(@exact),
'sunset for philly' => undef,
'sunrise on mars' => undef,
'sunset boulevard' => undef,