commit
4050a5dffc
|
@ -0,0 +1,64 @@
|
|||
package DDG::Goodie::DayOfWeek;
|
||||
# ABSTRACT: Calculates day of the week a given date falls on
|
||||
|
||||
use strict;
|
||||
use DDG::Goodie;
|
||||
with 'DDG::GoodieRole::Dates';
|
||||
|
||||
|
||||
zci answer_type => 'day_of_week';
|
||||
zci is_cached => 1;
|
||||
|
||||
primary_example_queries 'day of week for June 22 1907';
|
||||
secondary_example_queries 'day of week for 1/1/2012', 'what day will 15 Jan 2025 be', 'what day was 2015-01-02', '01/13/2015 was what day';
|
||||
description 'calculate day of the week for a date';
|
||||
name 'DayOfWeek';
|
||||
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/DayOfWeek.pm';
|
||||
category 'time_sensitive';
|
||||
topics 'everyday';
|
||||
attribution github => ['http://github.com/cngarrison', 'cngarrison'];
|
||||
|
||||
|
||||
my @trigger_words = (
|
||||
'day of week', 'day of the week',
|
||||
'what day of week', 'what day of the week',
|
||||
'what was day of week', 'what was day of the week',
|
||||
'what was the day of the week',
|
||||
'what day will',
|
||||
'what day was',
|
||||
'will be what day',
|
||||
'was what day',
|
||||
);
|
||||
triggers startend => @trigger_words;
|
||||
|
||||
my $datestring_regex = datestring_regex();
|
||||
|
||||
# Handle statement
|
||||
handle remainder => sub {
|
||||
my $remainder = $_;
|
||||
return unless $remainder =~ qr/(?<date>$datestring_regex)/x;
|
||||
|
||||
my $input_date = parse_datestring_to_date($+{date});
|
||||
return unless $input_date;
|
||||
|
||||
my $out_date = date_output_string($input_date);
|
||||
my $day_of_week = $input_date->day_name;
|
||||
|
||||
my $text = "Day of the Week: $day_of_week";
|
||||
|
||||
return $text,
|
||||
structured_answer => {
|
||||
id => 'day_of_week',
|
||||
name => 'Answer',
|
||||
data => {
|
||||
title => $day_of_week,
|
||||
subtitle => "Day of the week for: $out_date",
|
||||
},
|
||||
templates => {
|
||||
group => "text",
|
||||
moreAt => 0
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
1;
|
|
@ -0,0 +1,73 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use DDG::Test::Goodie;
|
||||
use Test::MockTime qw( :all );
|
||||
|
||||
zci answer_type => "day_of_week";
|
||||
zci is_cached => 1;
|
||||
|
||||
sub build_answer {
|
||||
my ($answer, $sub) = @_;
|
||||
$sub = '' unless $sub;
|
||||
|
||||
return sprintf("Day of the Week: %s",$answer) , structured_answer => {
|
||||
id => 'day_of_week',
|
||||
name => 'Answer',
|
||||
data => {
|
||||
title => $answer,
|
||||
subtitle => "Day of the week for: $sub"
|
||||
},
|
||||
templates => {
|
||||
group => 'text',
|
||||
moreAt => 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set_fixed_time('2015-07-14T12:00:00');
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw( DDG::Goodie::DayOfWeek )],
|
||||
|
||||
'day of week june 22 1907' => test_zci( build_answer( 'Saturday', '22 Jun 1907' ) ),
|
||||
'day of week for 1/1/2012' => test_zci( build_answer( 'Sunday', '01 Jan 2012' ) ),
|
||||
'day of week for 01/01/2012' => test_zci( build_answer( 'Sunday', '01 Jan 2012' ) ),
|
||||
|
||||
'day of week 1/1/2005' => test_zci( build_answer( 'Saturday', '01 Jan 2005' ) ),
|
||||
'day of the week 1/1/2005' => test_zci( build_answer( 'Saturday', '01 Jan 2005' ) ),
|
||||
'what day of week was 1/1/2005' => test_zci( build_answer( 'Saturday', '01 Jan 2005' ) ),
|
||||
'what day of the week was 1/1/2005' => test_zci( build_answer( 'Saturday', '01 Jan 2005' ) ),
|
||||
'what was day of the week for 1/1/2005' => test_zci( build_answer( 'Saturday', '01 Jan 2005' ) ),
|
||||
'what was the day of the week for 1/1/2005' => test_zci( build_answer( 'Saturday', '01 Jan 2005' ) ),
|
||||
|
||||
'what day was 1/1/2005' => test_zci( build_answer( 'Saturday', '01 Jan 2005' ) ),
|
||||
'1/1/2005 was what day' => test_zci( build_answer( 'Saturday', '01 Jan 2005' ) ),
|
||||
|
||||
'1/1/2025 will be what day' => test_zci( build_answer( 'Wednesday', '01 Jan 2025' ) ),
|
||||
'what day will 1/1/2025 be' => test_zci( build_answer( 'Wednesday', '01 Jan 2025' ) ),
|
||||
'What day will November 23 2050 be?' => test_zci( build_answer( 'Wednesday', '23 Nov 2050' ) ),
|
||||
'What day will 23 November 2050 be?' => test_zci( build_answer( 'Wednesday', '23 Nov 2050' ) ),
|
||||
|
||||
'day of week 1/12/2005' => test_zci( build_answer( 'Wednesday', '12 Jan 2005' ) ),
|
||||
'day of week 12/1/2005' => test_zci( build_answer( 'Thursday', '01 Dec 2005' ) ),
|
||||
'day of week 13/1/2005' => test_zci( build_answer( 'Thursday', '13 Jan 2005' ) ),
|
||||
'day of week 12-1-2005' => test_zci( build_answer( 'Thursday', '01 Dec 2005' ) ),
|
||||
'day of week 2005-01-02' => test_zci( build_answer( 'Sunday', '02 Jan 2005' ) ),
|
||||
'day of week 15 Jan 2005' => test_zci( build_answer( 'Saturday', '15 Jan 2005' ) ),
|
||||
|
||||
'day of week today' => test_zci( build_answer( 'Tuesday', '14 Jul 2015' ) ),
|
||||
'day of week tomorrow' => test_zci( build_answer( 'Wednesday', '15 Jul 2015' ) ),
|
||||
'day of week yesterday' => test_zci( build_answer( 'Monday', '13 Jul 2015' ) ),
|
||||
|
||||
'day of week' => undef,
|
||||
'day of the week' => undef,
|
||||
'what day was' => undef,
|
||||
'what day will' => undef,
|
||||
);
|
||||
|
||||
restore_time();
|
||||
|
||||
done_testing;
|
Loading…
Reference in New Issue