Merge pull request #2711 from swapagarwal/stardate

New Stardate Goodie
master
Rob Emery 2016-04-17 21:34:02 +01:00
commit f754a300e1
2 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,34 @@
package DDG::Goodie::Stardate;
# ABSTRACT: Returns stardate (see Star Trek)
use DDG::Goodie;
use strict;
with 'DDG::GoodieRole::Dates';
zci answer_type => 'stardate';
zci is_cached => 0;
triggers start => 'stardate';
handle remainder => sub {
my $query = $_;
my $parsed_date = parse_datestring_to_date($query || "today");
return unless $parsed_date;
my $seconds = $parsed_date->strftime("%s");
my $answer = $parsed_date->strftime("%Y%m%d.").int($seconds % 86400 / 86400 * 100000);
return $answer,
structured_answer => {
data => {
title => $answer,
subtitle => "Stardate for ".date_output_string($parsed_date, 1),
},
templates => {
group => "text",
}
};
};
1;

32
t/Stardate.t Normal file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use DDG::Test::Goodie;
zci answer_type => "stardate";
zci is_cached => 0;
sub build_structured_answer {
return qr/[0-9]{8}\.[0-9]{1,5}/,
structured_answer => {
data => '-ANY-',
templates => {
group => 'text',
},
};
}
sub build_test { test_zci(build_structured_answer(@_)) }
ddg_goodie_test(
[qw( DDG::Goodie::Stardate )],
'stardate' => build_test(),
'stardate 2 months ago' => build_test(),
'stardate in 2 years' => build_test(),
'star date' => undef,
'stardate 29 feb 2015' => undef,
);
done_testing;