Rasika Pohankar 7ebdcdfbd2 Countdown: Continue PR #3485 (#3936)
* Implement changed design, fix #3500

* Remove comment

* Update test file to use ISO8601 dates and avoid testing of Role

* Include subtitle in the template

* Take current time using momentjs, calculate difference in JS

* Remove subtitle from the template, make corrections to endCountdown

* Pass date string to JS and find difference in moment objects, change toggling at countdown end

* Remove use of difference passed from the backend

* Update test file
2017-04-24 09:40:05 -04:00

50 lines
1.1 KiB
Perl

package DDG::Goodie::Countdown;
# ABSTRACT: Provides a countdown to a particular date or time
use DDG::Goodie;
with 'DDG::GoodieRole::Dates';
use DateTime;
use strict;
zci answer_type => 'countdown';
zci is_cached => 1;
my $goodieVersion = $DDG::GoodieBundle::OpenSourceDuckDuckGo::VERSION // 999;
triggers startend => 'countdown to','time until','how long until';
# Handle statement
handle remainder => sub {
my $remainder = $_;
my $date = parse_datestring_to_date($remainder) or return;
my $current = parse_datestring_to_date('now');
my $diff = $date->epoch - $current->epoch;
return if $diff <= 0;
return $diff,
structured_answer => {
data => {
remainder => $_,
countdown_to => $date->strftime("%B %d, %Y, %r"), #remove after the Dates Role is updated
goodie_version => $goodieVersion,
input_date => $date->datetime()
},
templates => {
group => "text",
options => {
title_content => 'DDH.countdown.countdown'
}
}
};
};
1;