Merge branch 'master' into mintsoft/relative_dates
Conflicts: lib/DDG/GoodieRole/Dates.pmmaster
commit
4d9b70faee
|
@ -0,0 +1,72 @@
|
|||
package DDG::Goodie::Hiragana;
|
||||
# ABSTRACT: converts romaji syllables into hiragana
|
||||
|
||||
use DDG::Goodie;
|
||||
triggers startend =>'japanese hiragana','japanese','hiragana';
|
||||
zci answer_type => 'hiragana';
|
||||
|
||||
zci is_cached => 1;
|
||||
|
||||
primary_example_queries "hiragana a";
|
||||
secondary_example_queries "nihon hiragana";
|
||||
|
||||
description "Converts romaji syllables into hiragana";
|
||||
name "Hiragana";
|
||||
|
||||
category "language";
|
||||
topics "special_interest";
|
||||
|
||||
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Hiragana.pm';
|
||||
attribution github => "mintsoft";
|
||||
|
||||
my %hiragana = (
|
||||
# gojuuon
|
||||
a => 'あ', i => 'い', u => 'う', e => 'え', o => 'お',
|
||||
ka => 'か', ki => 'き', ku => 'く', ke => 'け', ko => 'こ',
|
||||
sa => 'さ', shi => 'し', su => 'す', se => 'せ', so => 'そ',
|
||||
ta => 'た', chi => 'ち', tsu => 'つ', te => 'て', to => 'と',
|
||||
na => 'な', ni => 'に', nu => 'ぬ', ne => 'ね', no => 'の',
|
||||
ha => 'は', hi => 'ひ', hu => 'ふ', he => 'へ', ho => 'ほ',
|
||||
ma => 'ま', mi => 'み', mu => 'む', me => 'め', mo => 'も',
|
||||
ya => 'や', yu => 'ゆ', yo => 'よ',
|
||||
ra => 'ら', ri => 'り', ru => 'る', re => 'れ', ro => 'ろ',
|
||||
wa => 'わ', wi => 'ゐ', we => 'ゑ', wo => 'を',
|
||||
# yooon
|
||||
kya => 'きゃ', kyu => 'きゅ', kyo => 'きょ',
|
||||
sha => 'しゃ', shu => 'しゅ', sho => 'しゅ',
|
||||
cha => 'ちゃ', chu => 'ちゅ', cho => 'ちょ',
|
||||
nya => 'にゃ', nyu => 'にゅ', nyo =>'にょ',
|
||||
mya => 'みゃ', myu => 'みゅ', myo =>'みょ',
|
||||
rya => 'りゃ', ryu => 'りゅ', ryo =>'りょ',
|
||||
# gojuuon with dakuten
|
||||
ga => 'が', gi => 'ぎ', gu => 'ぐ', ge => 'げ', go => 'ご',
|
||||
za => 'ざ', zi => 'じ', zu => 'ず', ze => 'ぜ', zo => 'ぞ',
|
||||
da => 'だ', ji => 'ぢ', du => 'づ', de => 'で', do => 'ど',
|
||||
ba => 'ば', bi => 'び', bu => 'ぶ', be => 'べ', bo => 'ぼ',
|
||||
pa => 'ぱ', pi => 'ぴ', pu => 'ぷ', pe => 'ぺ', po => 'ぽ',
|
||||
# yooon with dakuten
|
||||
gya => 'ぎゃ', gyu => 'ぎゅ', gyo => 'ぎょ',
|
||||
ja => 'じゃ', ju => 'じゅ', jo => 'じょ',
|
||||
# ja => 'ぢゃ', ju => 'ぢゅ', jo => 'ぢょ',
|
||||
bya => 'びゃ', byu => 'びゅ', byo => 'びょ',
|
||||
pya => 'ぴゃ', pyu => 'ぴゅ', pyo => 'ぴょ',
|
||||
vu => 'ゔ',
|
||||
n => 'ん'
|
||||
);
|
||||
|
||||
my @keys_in_replace_order = sort { length ($b) <=> length ($a) } keys %hiragana;
|
||||
|
||||
handle remainder => sub {
|
||||
my $output_string = $_;
|
||||
return unless $output_string;
|
||||
foreach my $syllable ( @keys_in_replace_order ) {
|
||||
$output_string =~ s/$syllable/$hiragana{$syllable}/gi;
|
||||
}
|
||||
|
||||
#If there were unconvertable syllables, then it's not valid romaji
|
||||
return if $output_string =~ /[A-Za-z]/;
|
||||
utf8::decode($output_string);
|
||||
return $output_string, html => "<div class='zci--hiragana text--primary'>".html_enc($output_string)."</div>";
|
||||
};
|
||||
|
||||
1;
|
|
@ -0,0 +1,86 @@
|
|||
package DDG::Goodie::IndependenceDay;
|
||||
# ABSTRACT: Goodie answer for different countries' national independence days
|
||||
|
||||
use DDG::Goodie;
|
||||
use JSON;
|
||||
|
||||
zci answer_type => "independence_day";
|
||||
zci is_cached => 1;
|
||||
|
||||
name "independence day";
|
||||
description "Gives the date of when a nation assumed independence";
|
||||
primary_example_queries "what is the independence day of norway", "independence day, papua new guinea";
|
||||
category "dates";
|
||||
topics "trivia";
|
||||
code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/IndependenceDay.pm";
|
||||
attribution github => ["jarmokivekas", "Jarmo Kivekäs"],
|
||||
web => ["http://guttula.com", "Jarmo Kivekäs"],
|
||||
github => ["YouriAckx", "Youri Ackx"],
|
||||
twitter => "YouriAckx";
|
||||
|
||||
|
||||
# Triggers
|
||||
triggers any => "independence day", "day of independence";
|
||||
|
||||
|
||||
# uses https://en.wikipedia.org/wiki/List_of_national_independence_days as data source
|
||||
my $data = share('independence_days.json')->slurp;
|
||||
$data = decode_json($data);
|
||||
|
||||
|
||||
# define aliases for some countries to improve hit rate
|
||||
my $alias_lookup = share('country_aliases.json')->slurp;
|
||||
$alias_lookup = decode_json($alias_lookup);
|
||||
|
||||
|
||||
# Handle statement
|
||||
handle query_clean => sub {
|
||||
|
||||
# delete noise from query string
|
||||
s/(national|independence of|independence|day of|day|when|what|is the|for|)//g;
|
||||
# delete the whitespace left from query noise (spaces between words)
|
||||
s/^\s*|\s*$//g;
|
||||
# only the name of the country should be left in the string at this point
|
||||
|
||||
|
||||
# convert a possible alias into the proper name
|
||||
my $country_key = $alias_lookup->{$_} || $_;
|
||||
|
||||
|
||||
# return if the string is not one of the countries
|
||||
return unless $data->{$country_key};
|
||||
|
||||
|
||||
# Format the country name properly for display
|
||||
my $country = $country_key;
|
||||
# Title Case The Country Name
|
||||
$country =~ s/(\w\S*)/\u\L$1/g;
|
||||
# lowercase the words 'of', 'the' and 'and'
|
||||
$country =~ s/\sThe\s/ the /;
|
||||
$country =~ s/\sOf\s/ of /;
|
||||
$country =~ s/\sAnd\s/ and /;
|
||||
|
||||
|
||||
# ouput string formatting
|
||||
my $prolog = 'Independence Day of ' . $country;
|
||||
# date and year of independence
|
||||
my $date_str = $data->{$country_key}[0]{'date'} . ', ' . $data->{$country_key}[0]{'year'};
|
||||
# Some coutries have two dates, add it to the answer if a second one exists.
|
||||
if ($data->{$country_key}[1]){
|
||||
$date_str .= ' and ' . $data->{$country_key}[1]{'date'} . ', ' . $data->{$country_key}[1]{'year'};
|
||||
}
|
||||
|
||||
|
||||
# html formatted answer
|
||||
my $html = '<div class="zci--independence-day">';
|
||||
$html .= '<div class="text--primary">' . $date_str . '</div>';
|
||||
$html .= '<div class="text--secondary">' . $prolog . '</div>';
|
||||
$html .= '</div>';
|
||||
# plain text answer
|
||||
my $text = $prolog . ' ' . $date_str;
|
||||
|
||||
return $text, html => $html;
|
||||
|
||||
};
|
||||
|
||||
1;
|
|
@ -5,6 +5,8 @@ use 5.010;
|
|||
use strict;
|
||||
use warnings;
|
||||
use DDG::Goodie;
|
||||
|
||||
use DateTime;
|
||||
use POSIX qw(fmod);
|
||||
|
||||
attribution github => ['https://github.com/GlitchMr', 'GlitchMr'];
|
||||
|
@ -55,10 +57,25 @@ my %timezones = qw(
|
|||
YEKT 5
|
||||
);
|
||||
|
||||
sub parse_timezone(_) {
|
||||
my $default_tz = 'UTC';
|
||||
my $localtime_re = qr/(?:(?:my|local|my local)\s*time(?:zone)?)/i;
|
||||
my $timezone_re = qr/(?:\w+(?:\s*[+-]0*[0-9]{1,5}(?::[0-5][0-9])?)?|$localtime_re)?/;
|
||||
|
||||
sub parse_timezone {
|
||||
my $timezone = shift;
|
||||
my ( $name, $modifier, $minutes )
|
||||
= $timezone =~ /\A(\w+)(?:([+-]\d+)(?::(\d\d))?)?\z/;
|
||||
|
||||
# They said "my timezone" or similar.
|
||||
if ($timezone =~ /$localtime_re/i) {
|
||||
my $dt = DateTime->now(time_zone => $loc->time_zone || $default_tz );
|
||||
return ($dt->time_zone_short_name, $dt->offset / 3600);
|
||||
}
|
||||
|
||||
# Normalize
|
||||
$timezone ||= $default_tz;
|
||||
$timezone = uc $timezone;
|
||||
$timezone =~ s/\s+//g;
|
||||
|
||||
my ($name, $modifier, $minutes) = $timezone =~ /\A(\w+)(?:([+-]\d+)(?::(\d\d))?)?\z/;
|
||||
|
||||
# If timezone doesn't exist, skip it
|
||||
return unless defined $timezones{$name};
|
||||
|
@ -68,11 +85,13 @@ sub parse_timezone(_) {
|
|||
|
||||
# Minutes can be skipped too
|
||||
$minutes //= 0;
|
||||
return $timezones{$name} + $modifier + $minutes / 60;
|
||||
|
||||
return ($timezone, $timezones{$name} + $modifier + $minutes / 60);
|
||||
}
|
||||
|
||||
sub to_time {
|
||||
my ($hours, $american) = @_;
|
||||
|
||||
my $pm = "";
|
||||
my $seconds = 3600 * fmod $hours, 1 / 60;
|
||||
|
||||
|
@ -87,17 +106,15 @@ sub to_time {
|
|||
# Special case certain hours
|
||||
return 'midnight' if $hours == 0;
|
||||
return 'noon' if $hours == 12;
|
||||
$pm = ' A.M.';
|
||||
$pm = ' AM';
|
||||
if ($hours > 12) {
|
||||
$pm = ' P.M.';
|
||||
$pm = ' PM';
|
||||
$hours -= 12 if (int($hours) > 12);
|
||||
}
|
||||
}
|
||||
sprintf "%i:%02.0f$seconds_format$pm", $hours, $minutes, $seconds;
|
||||
}
|
||||
|
||||
my $timezone_re = qr/(?:\w+(?:\s*[+-]0*[0-9]{1,5}(?::[0-5][0-9])?)?)?/;
|
||||
|
||||
handle query => sub {
|
||||
my $query = $_;
|
||||
$query =~ m{
|
||||
|
@ -136,23 +153,15 @@ handle query => sub {
|
|||
|
||||
my ($hours, $minutes, $seconds) = map { $_ // 0 } ($+{'h'}, $+{'m'}, $+{'s'});
|
||||
my $american = $+{'american'};
|
||||
my $pm = ($+{'pm'} && $hours != 12) ? 12 : 0;
|
||||
my $input_timezone = uc $+{'from_tz'} || 'UTC';
|
||||
my $output_timezone = uc $+{'to_tz'};
|
||||
my $pm = ($+{'pm'} && $hours != 12) ? 12 : (!$+{'pm'} && $hours == 12) ? -12 : 0;
|
||||
|
||||
my $modifier = 0;
|
||||
for ( $input_timezone, $output_timezone ) {
|
||||
s/\s+//g;
|
||||
}
|
||||
my $gmt_input_timezone = parse_timezone $input_timezone;
|
||||
# parse_timezone returns undef if the timezone name parsed
|
||||
# from #input_timezone is not found in %timezones
|
||||
# parse_timezone returns undef if the timezone cannot be parsed
|
||||
my ($input_timezone, $gmt_input_timezone) = parse_timezone($+{'from_tz'});
|
||||
return unless defined $gmt_input_timezone;
|
||||
|
||||
my $gmt_output_timezone = parse_timezone $output_timezone;
|
||||
my ($output_timezone, $gmt_output_timezone) = parse_timezone($+{'to_tz'});
|
||||
return unless defined($gmt_output_timezone);
|
||||
|
||||
$modifier += $gmt_output_timezone - $gmt_input_timezone;
|
||||
my $modifier = $gmt_output_timezone - $gmt_input_timezone;
|
||||
for ( $gmt_input_timezone, $gmt_output_timezone ) {
|
||||
$_ = to_time $_;
|
||||
s/\A\b/+/;
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
.zci--hiragana {
|
||||
font-size: 1.5em;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"antigua": "antigua and barbuda",
|
||||
"arab emirates": "united arab emirates",
|
||||
"barbuda": "antigua and barbuda",
|
||||
"bosnia": "bosnia and herzegovina",
|
||||
"democratic republic of congo": "democratic republic of the congo",
|
||||
"gambia": "the gambia",
|
||||
"grenadines": "saint vincent and the grenadines",
|
||||
"guinea bissau": "guinea-bissau",
|
||||
"herzegovina": "bosnia and herzegovina",
|
||||
"macedonia": "republic of macedonia",
|
||||
"nevis": "saint kitts and nevis",
|
||||
"principe": "são tomé and príncipe",
|
||||
"republic of congo": "republic of the congo",
|
||||
"saint kitts": "saint kitts and nevis",
|
||||
"saint vincent": "saint vincent and the grenadines",
|
||||
"sao tome and principe": "são tomé and príncipe",
|
||||
"sao tome": "são tomé and príncipe",
|
||||
"tobago": "trinidad and tobago",
|
||||
"trinidad": "trinidad and tobago",
|
||||
"united states": "united states of america",
|
||||
"usa": "united states of america"
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package MyParser;
|
||||
use base qw(HTML::Parser);
|
||||
# ABSTRACT: Parses specific data from html table on wikipedia into json
|
||||
# uses the the table from https://en.wikipedia.org/wiki/List_of_national_independence_days
|
||||
# as data source
|
||||
|
||||
# parser state information
|
||||
my $column = 0;
|
||||
my $field;
|
||||
|
||||
# prints out relevant data (as json)
|
||||
sub text{
|
||||
my ($self, $origtext) = @_;
|
||||
if($field eq 'country'){
|
||||
# lowercase country names
|
||||
$origtext = lc($origtext);
|
||||
$origtext =~ s/(.*), (.*)/$2 $1/;
|
||||
print "\t'$origtext' => [{";
|
||||
}elsif($field eq 'date'){
|
||||
# replace html entities with regular space
|
||||
$origtext =~ s/ / /g;
|
||||
# add proper suffix to day number
|
||||
$origtext =~ s/ 1$/ 1st/;
|
||||
$origtext =~ s/ 2$/ 2nd/;
|
||||
$origtext =~ s/ 3$/ 3rd/;
|
||||
$origtext =~ s/( [0987654321]+)$/$1th/;
|
||||
|
||||
print "$field => \"$origtext\", ";
|
||||
}elsif($field eq 'year'){
|
||||
print "$field => \"$origtext\"}],\n";
|
||||
}
|
||||
# make sure we dont print unintended data form subsequent fields
|
||||
$field = '';
|
||||
}
|
||||
|
||||
# triggered when parser encouters tag start
|
||||
sub start {
|
||||
my ($self, $tagname, $attr, $attrseq, $origtext) = @_;
|
||||
# stated parsing new table row
|
||||
if ($tagname eq 'tr'){
|
||||
$column = 0;
|
||||
}
|
||||
# parser reached next column
|
||||
if ($tagname eq 'td') {
|
||||
$column++;
|
||||
}
|
||||
# country names are inside link tags in the first column
|
||||
if ($tagname eq 'a' && $column eq 1) {
|
||||
$field = 'country';
|
||||
}
|
||||
# dates are inside span with class 'sorttext' in column 2
|
||||
elsif ($tagname eq 'span' && $attr->{ class } eq 'sorttext' && $column eq 2){
|
||||
$field = 'date';
|
||||
}
|
||||
# years are just plain in the 3rd column
|
||||
elsif ($tagname eq 'td' && $column eq 3){
|
||||
$field = 'year';
|
||||
}
|
||||
}
|
||||
|
||||
package main;
|
||||
|
||||
|
||||
my $file = "wikipedia_html_table";
|
||||
my $parser = MyParser->new;
|
||||
print "my \%data = (\n";
|
||||
$parser->parse_file( $file );
|
||||
print ");\n";
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
.zci--independence-day .text--primary{
|
||||
font-size: 1.5em;
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
{
|
||||
"abkhazia": [{"date": "July 4th", "year": "1993"}],
|
||||
"afghanistan": [{"date": "August 19th", "year": "1919"}],
|
||||
"albania": [{"date": "November 28th", "year": "1912"}],
|
||||
"algeria": [{"date": "July 5th", "year": "1962"}],
|
||||
"angola": [{"date": "November 11th", "year": "1975"}],
|
||||
"antigua and barbuda": [{"date": "November 1st", "year": "1981"}],
|
||||
"argentina": [{"date": "July 9th", "year": "1816"}],
|
||||
"armenia": [{"date": "May 28th", "year": "1918"},{"date": "September 21th", "year": "1991"}],
|
||||
"austria": [{"date": "October 26th", "year": "1955"}],
|
||||
"azerbaijan": [{"date": "May 28th", "year": "1918"},{"date": "October 18th", "year": "1991"}],
|
||||
"bahamas": [{"date": "July 10th", "year": "1973"}],
|
||||
"bahrain": [{"date": "August 15th", "year": "1971"}],
|
||||
"bangladesh": [{"date": "March 26th", "year": "1971"}],
|
||||
"barbados": [{"date": "November 30th", "year": "1966"}],
|
||||
"belarus": [{"date": "July 3rd", "year": "1944"}],
|
||||
"belgium": [{"date": "July 21th", "year": "1831"}],
|
||||
"belize": [{"date": "September 21th", "year": "1981"}],
|
||||
"benin": [{"date": "August 1st", "year": "1960"}],
|
||||
"bolivia": [{"date": "August 6th", "year": "1825"}],
|
||||
"bosnia and herzegovina": [{"date": "March 1st", "year": "1992"}],
|
||||
"botswana": [{"date": "September 30th", "year": "1966"}],
|
||||
"brazil": [{"date": "September 7th", "year": "1822"}],
|
||||
"brunei": [{"date": "January 1st", "year": "1984"}],
|
||||
"bulgaria": [{"date": "September 22th", "year": "1908"}],
|
||||
"burkina faso": [{"date": "August 5th", "year": "1960"}],
|
||||
"burma": [{"date": "January 4th", "year": "1948"}],
|
||||
"burundi": [{"date": "July 1st", "year": "1962"}],
|
||||
"cambodia": [{"date": "November 9th", "year": "1953"}],
|
||||
"cameroon": [{"date": "January 1st", "year": "1960"}],
|
||||
"canada": [{"date": "July 1st", "year": "1867"}],
|
||||
"cape verde": [{"date": "July 5th", "year": "1975"}],
|
||||
"central african republic": [{"date": "August 13th", "year": "1960"}],
|
||||
"chad": [{"date": "August 11th", "year": "1960"}],
|
||||
"chile": [{"date": "February 12 and September 18th", "year": "1810"}],
|
||||
"colombia": [{"date": "July 20 and August 7th", "year": "1810"}],
|
||||
"comoros": [{"date": "July 6th", "year": "1975"}],
|
||||
"democratic republic of the congo": [{"date": "June 30th", "year": "1960"}],
|
||||
"republic of the congo": [{"date": "August 15th", "year": "1960"}],
|
||||
"costa rica": [{"date": "September 15th", "year": "1821"}],
|
||||
"croatia": [{"date": "October 8th", "year": "1991"}],
|
||||
"cuba": [{"date": "May 20th", "year": "1902"}],
|
||||
"cyprus": [{"date": "October 1st", "year": "1960"}],
|
||||
"czech republic": [{"date": "October 28th", "year": "1918"},{"date": "January 1st", "year": "1993"}],
|
||||
"denmark": [{"date": "June 5th", "year": "1849"}],
|
||||
"djibouti": [{"date": "June 27th", "year": "1977"}],
|
||||
"dominica": [{"date": "November 3rd", "year": "1978"}],
|
||||
"dominican republic": [{"date": "December 1st", "year": "1821"},{"date": "February 27th", "year": "1844"}],
|
||||
"east timor": [{"date": "May 20th", "year": "2002"}],
|
||||
"ecuador": [{"date": "August 10th", "year": "1809"}],
|
||||
"ecuador": [{"date": "May 24th", "year": "1822"}],
|
||||
"el salvador": [{"date": "September 15th", "year": "1821"}],
|
||||
"equatorial guinea": [{"date": "October 12th", "year": "1968"}],
|
||||
"eritrea": [{"date": "May 24th", "year": "1993"}],
|
||||
"estonia": [{"date": "February 24th", "year": "1918"},{"date": "August 20th", "year": "1991"}],
|
||||
"fiji": [{"date": "October 10th", "year": "1970"}],
|
||||
"finland": [{"date": "December 6th", "year": "1917"}],
|
||||
"gabon": [{"date": "August 17th", "year": "1960"}],
|
||||
"the gambia": [{"date": "February 18th", "year": "1965"}],
|
||||
"georgia": [{"date": "May 26th", "year": "1918"},{"date": "April 9th", "year": "1991"}],
|
||||
"ghana": [{"date": "March 6th", "year": "1957"}],
|
||||
"greece": [{"date": "March 25th", "year": "1821"}],
|
||||
"grenada": [{"date": "February 7th", "year": "1974"}],
|
||||
"guatemala": [{"date": "September 15th", "year": "1821"}],
|
||||
"guinea": [{"date": "October 2nd", "year": "1958"}],
|
||||
"guinea-bissau": [{"date": "September 24th", "year": "1973"}],
|
||||
"guyana": [{"date": "May 26th", "year": "1966"}],
|
||||
"haiti": [{"date": "January 1st", "year": "1804"}],
|
||||
"honduras": [{"date": "September 15th", "year": "1821"}],
|
||||
"hungary": [{"date": "August 20th", "year": "1000"}],
|
||||
"iceland": [{"date": "December 1st", "year": "1918"}],
|
||||
"india": [{"date": "August 15th", "year": "1947"}],
|
||||
"indonesia": [{"date": "August 17th", "year": "1945"}],
|
||||
"iraq": [{"date": "October 3rd", "year": "1932"}],
|
||||
"ireland": [{"date": "April 24th", "year": "1916"}],
|
||||
"israel": [{"date": "Iyar 5th", "year": "1948"}],
|
||||
"ivory coast": [{"date": "August 7th", "year": "1960"}],
|
||||
"jamaica": [{"date": "August 6th", "year": "1962"}],
|
||||
"japan": [{"date": "February 11th", "year": "660 B.C."}],
|
||||
"jordan": [{"date": "May 25th", "year": "1946"}],
|
||||
"kazakhstan": [{"date": "December 16th", "year": "1991"}],
|
||||
"kenya": [{"date": "December 12th", "year": "1963"}],
|
||||
"north korea": [{"date": "September 9th", "year": "1948"}],
|
||||
"south korea": [{"date": "August 15th", "year": "1945"}],
|
||||
"kosovo": [{"date": "February 8th", "year": "2008"}],
|
||||
"kuwait": [{"date": "February 25th", "year": "1961"}],
|
||||
"kyrgyzstan": [{"date": "August 31th", "year": "1991"}],
|
||||
"laos": [{"date": "October 22th", "year": "1953"}],
|
||||
"latvia": [{"date": "November 18th", "year": "1918"}],
|
||||
"latvia": [{"date": "May 4th", "year": "1990"}],
|
||||
"lebanon": [{"date": "November 22th", "year": "1943"}],
|
||||
"lesotho": [{"date": "October 4th", "year": "1966"}],
|
||||
"liberia": [{"date": "July 26th", "year": "1847"}],
|
||||
"libya": [{"date": "December 24th", "year": "1951"}],
|
||||
"lithuania": [{"date": "February 16th", "year": "1918"},{"date": "March 11th", "year": "1990"}],
|
||||
"republic of macedonia": [{"date": "September 8th", "year": "1991"}],
|
||||
"madagascar": [{"date": "June 26th", "year": "1960"}],
|
||||
"malawi": [{"date": "July 6th", "year": "1964"}],
|
||||
"malaysia": [{"date": "August 31th", "year": "1957"},{"date": "September 16th", "year": "1963"}],
|
||||
"maldives": [{"date": "July 26th", "year": "1965"}],
|
||||
"mali": [{"date": "September 22th", "year": "1960"}],
|
||||
"malta": [{"date": "September 21th", "year": "1964"}],
|
||||
"mauritius": [{"date": "March 12th", "year": "1968"}],
|
||||
"mexico": [{"date": "September 16th", "year": "1810"}],
|
||||
"moldova": [{"date": "August 27th", "year": "1991"}],
|
||||
"mongolia": [{"date": "December 29th", "year": "1911"}],
|
||||
"montenegro": [{"date": "May 21th", "year": "2006"}],
|
||||
"morocco": [{"date": "November 18th", "year": "1956"}],
|
||||
"mozambique": [{"date": "June 25th", "year": "1975"}],
|
||||
"nagorno-karabakh": [{"date": "September 2nd", "year": "1991"}],
|
||||
"namibia": [{"date": "March 21th", "year": "1990"}],
|
||||
"nauru": [{"date": "January 31th", "year": "1968"}],
|
||||
"netherlands": [{"date": "May 5th", "year": "1945"}],
|
||||
"nicaragua": [{"date": "September 15th", "year": "1821"}],
|
||||
"niger": [{"date": "August 3rd", "year": "1960"}],
|
||||
"nigeria": [{"date": "October 1st", "year": "1960"}],
|
||||
"northern cyprus": [{"date": "September 2nd", "year": "1983"}],
|
||||
"norway": [{"date": "May 17th", "year": "1814"}],
|
||||
"pakistan": [{"date": "August 14th", "year": "1947"}],
|
||||
"panama": [{"date": "November 28th", "year": "1821"},{"date": "November 3rd", "year": "1903"}],
|
||||
"papua new guinea": [{"date": "September 16th", "year": "1975"}],
|
||||
"paraguay": [{"date": "May 15th", "year": "1811"}],
|
||||
"peru": [{"date": "July 28th", "year": "1821"}],
|
||||
"philippines": [{"date": "June 12th", "year": "1898"}],
|
||||
"poland": [{"date": "November 11th", "year": "1918"}],
|
||||
"portugal": [{"date": "December 1st", "year": "1640"}],
|
||||
"qatar": [{"date": "December 18th", "year": "1971"}],
|
||||
"rhodesia": [{"date": "November 11th", "year": "1965"}],
|
||||
"romania": [{"date": "May 10th", "year": "1866"}],
|
||||
"rwanda": [{"date": "July 1st", "year": "1962"}],
|
||||
"saint kitts and nevis": [{"date": "September 19th", "year": "1983"}],
|
||||
"saint lucia": [{"date": "February 22th", "year": "1979"}],
|
||||
"saint vincent and the grenadines": [{"date": "October 27th", "year": "1979"}],
|
||||
"samoa": [{"date": "January 1st", "year": "1962"}],
|
||||
"são tomé and príncipe": [{"date": "July 12th", "year": "1975"}],
|
||||
"senegal": [{"date": "April 4th", "year": "1960"}],
|
||||
"serbia": [{"date": "February 15th", "year": "1804"}],
|
||||
"seychelles": [{"date": "June 29th", "year": "1976"}],
|
||||
"sierra leone": [{"date": "April 27th", "year": "1961"}],
|
||||
"singapore": [{"date": "August 9th", "year": "1965"}],
|
||||
"slovakia": [{"date": "July 17th", "year": "1992"},{"date": "December 26 and June 25th", "year": "1990"}],
|
||||
"solomon islands": [{"date": "July 7th", "year": "1978"}],
|
||||
"somalia": [{"date": "July 1st", "year": "1960"}],
|
||||
"south africa": [{"date": "December 11th", "year": "1931"}],
|
||||
"south sudan": [{"date": "July 9th", "year": "2011"}],
|
||||
"sri lanka": [{"date": "February 4th", "year": "1948"}],
|
||||
"sudan": [{"date": "January 1st", "year": "1956"}],
|
||||
"suriname": [{"date": "November 25th", "year": "1975"}],
|
||||
"swaziland": [{"date": "September 6th", "year": "1968"}],
|
||||
"sweden": [{"date": "June 6th", "year": "1523"}],
|
||||
"switzerland": [{"date": "August 1st", "year": "1291"}],
|
||||
"syria": [{"date": "April 17th", "year": "1946"}],
|
||||
"tajikistan": [{"date": "September 9th", "year": "1991"}],
|
||||
"tanzania": [{"date": "December 9th", "year": "1961"}],
|
||||
"togo": [{"date": "April 27th", "year": "1960"}],
|
||||
"tibet": [{"date": "February 13th", "year": "1913"}],
|
||||
"tonga": [{"date": "June 4th", "year": "1970"}],
|
||||
"trinidad and tobago": [{"date": "August 31th", "year": "1962"}],
|
||||
"tunisia": [{"date": "March 20th", "year": "1956"}],
|
||||
"turkmenistan": [{"date": "October 27th", "year": "1991"}],
|
||||
"ukraine": [{"date": "August 24th", "year": "1991"}],
|
||||
"ukraine": [{"date": "January 22th", "year": "1919"}],
|
||||
"united arab emirates": [{"date": "December 2nd", "year": "1971"}],
|
||||
"united states of america": [{"date": "July 4th", "year": "1776"}],
|
||||
"uruguay": [{"date": "August 25th", "year": "1825"}],
|
||||
"uzbekistan": [{"date": "September 1st", "year": "1991"}],
|
||||
"vanuatu": [{"date": "July 30th", "year": "1980"}],
|
||||
"venezuela": [{"date": "July 5th", "year": "1811"}],
|
||||
"vietnam": [{"date": "September 2nd", "year": "1945"}],
|
||||
"yemen": [{"date": "November 30th", "year": "1967"}],
|
||||
"zambia": [{"date": "October 24th", "year": "1964"}],
|
||||
"zimbabwe": [{"date": "April 18th", "year": "1980"}]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use DDG::Test::Goodie;
|
||||
|
||||
use utf8;
|
||||
|
||||
zci answer_type => 'hiragana';
|
||||
zci is_cached => 1;
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw(
|
||||
DDG::Goodie::Hiragana
|
||||
)],
|
||||
|
||||
"hiragana a" => test_zci('あ', html => "<div class='zci--hiragana text--primary'>あ</div>"),
|
||||
"hiragana konnichiwa" => test_zci('こんにちわ', html => "<div class='zci--hiragana text--primary'>こんにちわ</div>"),
|
||||
"nihon hiragana" => test_zci('にほん', html => "<div class='zci--hiragana text--primary'>にほん</div>"),
|
||||
"hiragana tsukue no ue" => test_zci('つくえ の うえ', html => "<div class='zci--hiragana text--primary'>つくえ の うえ</div>"),
|
||||
"what is hiragana?" => undef,
|
||||
"hiragana" => undef,
|
||||
);
|
||||
|
||||
done_testing();
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use DDG::Test::Goodie;
|
||||
|
||||
zci answer_type => "independence_day";
|
||||
zci is_cached => 1;
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw(
|
||||
DDG::Goodie::IndependenceDay
|
||||
)],
|
||||
# primary example queries
|
||||
'what is the independence day of norway' => test_zci('Independence Day of Norway May 17th, 1814', html=>qr/.*/),
|
||||
'independence day, papua new guinea' => test_zci('Independence Day of Papua New Guinea September 16th, 1975', html=>qr/.*/),
|
||||
# question marks
|
||||
'what is the independence day of norway?' => test_zci('Independence Day of Norway May 17th, 1814', html=>qr/.*/),
|
||||
# some aliases
|
||||
'when is the independence day of republic of congo' => test_zci('Independence Day of Republic of the Congo August 15th, 1960', html=>qr/.*/),
|
||||
'when is the independence day of republic of the congo' => test_zci('Independence Day of Republic of the Congo August 15th, 1960', html=>qr/.*/),
|
||||
'gambia independence day' => test_zci('Independence Day of The Gambia February 18th, 1965', html=>qr/.*/),
|
||||
'the gambia independence day' => test_zci('Independence Day of The Gambia February 18th, 1965', html=>qr/.*/),
|
||||
'usa independence day' => test_zci('Independence Day of United States of America July 4th, 1776', html=>qr/.*/),
|
||||
# data points with two dates
|
||||
'independence day of panama' => test_zci('Independence Day of Panama November 28th, 1821 and November 3rd, 1903', html=>qr/.*/),
|
||||
'independence day of armenia' => test_zci('Independence Day of Armenia May 28th, 1918 and September 21th, 1991', html=>qr/.*/),
|
||||
# miscellaneous
|
||||
'independence day of papua new guinea' => test_zci('Independence Day of Papua New Guinea September 16th, 1975', html=>qr/.*/),
|
||||
'day of independence of sri lanka' => test_zci('Independence Day of Sri Lanka February 4th, 1948', html=>qr/.*/),
|
||||
'when is the day of independence for norway' => test_zci('Independence Day of Norway May 17th, 1814', html=>qr/.*/),
|
||||
'day of independence, norway' => test_zci('Independence Day of Norway May 17th, 1814', html=>qr/.*/),
|
||||
'norway independence day' => test_zci('Independence Day of Norway May 17th, 1814', html=>qr/.*/),
|
||||
'what day is the independence day of norway' => test_zci('Independence Day of Norway May 17th, 1814', html=>qr/.*/),
|
||||
|
||||
);
|
||||
|
||||
done_testing;
|
|
@ -4,9 +4,10 @@ use strict;
|
|||
use warnings;
|
||||
use Test::More;
|
||||
use DDG::Test::Goodie;
|
||||
use Test::MockTime qw( :all );
|
||||
|
||||
zci answer_type => 'timezone_converter';
|
||||
zci is_cached => 1;
|
||||
zci is_cached => 1;
|
||||
|
||||
ddg_goodie_test(
|
||||
['DDG::Goodie::TimezoneConverter'],
|
||||
|
@ -14,80 +15,162 @@ ddg_goodie_test(
|
|||
test_zci('3:14 (UTC) is 3:14 (GMT).',
|
||||
html => qr/.*3:14.*\(UTC\) is.*3:14.*\(GMT\)./
|
||||
),
|
||||
'8:10 A.M. AZOST into CAT' =>
|
||||
test_zci('8:10 A.M. (AZOST, UTC-1) is 11:10 A.M. (CAT, UTC+2).',
|
||||
html => qr/./
|
||||
'8:10 AM AZOST into CAT' =>
|
||||
test_zci('8:10 AM (AZOST, UTC-1) is 11:10 AM (CAT, UTC+2).',
|
||||
html => '-ANY-'
|
||||
),
|
||||
'1pm EDT into UTC+2' =>
|
||||
test_zci('1:00 P.M. (EDT, UTC-4) is 7:00 P.M. (UTC+2).',
|
||||
html => qr/./
|
||||
test_zci('1:00 PM (EDT, UTC-4) is 7:00 PM (UTC+2).',
|
||||
html => '-ANY-'
|
||||
),
|
||||
'0pm into GMT' =>
|
||||
test_zci('Noon (UTC) is noon (GMT).',
|
||||
html => qr/./
|
||||
html => '-ANY-'
|
||||
),
|
||||
'0am into UTC' =>
|
||||
test_zci('Midnight (UTC) is midnight (UTC).',
|
||||
html => qr/./
|
||||
html => '-ANY-'
|
||||
),
|
||||
'1 into UTC -2 ' =>
|
||||
test_zci('1:00 (UTC) is 23:00, 1 day prior (UTC-2).',
|
||||
html => qr/./
|
||||
html => '-ANY-'
|
||||
),
|
||||
' 1 into UTC-1' =>
|
||||
test_zci('1:00 (UTC) is 0:00 (UTC-1).',
|
||||
html => qr/./
|
||||
html => '-ANY-'
|
||||
),
|
||||
'21 FNT into EET' =>
|
||||
test_zci('21:00 (FNT, UTC-2) is 1:00, 1 day after (EET, UTC+2).',
|
||||
html => qr/./
|
||||
html => '-ANY-'
|
||||
),
|
||||
'23:00:00 InTo UTC+1' =>
|
||||
test_zci('23:00 (UTC) is 0:00, 1 day after (UTC+1).',
|
||||
html => qr/./
|
||||
html => '-ANY-'
|
||||
),
|
||||
'23:00:01 Into UTC+1' =>
|
||||
test_zci('23:00:01 (UTC) is 0:00:01, 1 day after (UTC+1).',
|
||||
html => qr/./
|
||||
html => '-ANY-'
|
||||
),
|
||||
'13:15:00 UTC-0:30 into UTC+0:30' =>
|
||||
test_zci('13:15 (UTC-0:30) is 13:15 (UTC+0:30).',
|
||||
html => qr/./
|
||||
html => '-ANY-'
|
||||
),
|
||||
# ok, this is unlikely to happen without trying to do that
|
||||
'19:42:42 BIT into GMT+100' =>
|
||||
test_zci('19:42:42 (BIT, UTC-12) is 11:42:42, 5 days after (GMT+100).',
|
||||
html => qr/./
|
||||
html => '-ANY-'
|
||||
),
|
||||
'19:42:42 CHADT into GMT-100' =>
|
||||
test_zci('19:42:42 (CHADT, UTC+13:45) is 1:57:42, 4 days prior (GMT-100).',
|
||||
html => qr/./
|
||||
html => '-ANY-'
|
||||
),
|
||||
'12 in binary' => undef,
|
||||
'10:00AM MST to PST' =>
|
||||
test_zci('10:00 A.M. (MST, UTC-7) is 9:00 A.M. (PST, UTC-8).',
|
||||
html => qr/./
|
||||
test_zci('10:00 AM (MST, UTC-7) is 9:00 AM (PST, UTC-8).',
|
||||
html => '-ANY-'
|
||||
),
|
||||
'19:00 UTC to EST' =>
|
||||
test_zci('19:00 (UTC) is 14:00 (EST, UTC-5).',
|
||||
html => qr/./
|
||||
html => '-ANY-'
|
||||
),
|
||||
'1am UTC to PST' =>
|
||||
test_zci('1:00 A.M. (UTC) is 5:00 P.M., 1 day prior (PST, UTC-8).',
|
||||
html => qr/./
|
||||
test_zci('1:00 AM (UTC) is 5:00 PM, 1 day prior (PST, UTC-8).',
|
||||
html => '-ANY-'
|
||||
),
|
||||
'12:40pm PST into JST' =>
|
||||
test_zci('12:40 P.M. (PST, UTC-8) is 5:40 A.M., 1 day after (JST, UTC+9).',
|
||||
html => qr/./
|
||||
test_zci('12:40 PM (PST, UTC-8) is 5:40 AM, 1 day after (JST, UTC+9).',
|
||||
html => '-ANY-'
|
||||
),
|
||||
'12:40 pm from PST to JST' =>
|
||||
test_zci('12:40 P.M. (PST, UTC-8) is 5:40 A.M., 1 day after (JST, UTC+9).',
|
||||
html => qr/.*12:40 P.M..*\(PST, UTC-8\) is.*5:40 A.M., 1 day after.*\(JST, UTC\+9\)./
|
||||
test_zci('12:40 PM (PST, UTC-8) is 5:40 AM, 1 day after (JST, UTC+9).',
|
||||
html => qr/.*12:40 PM.*\(PST, UTC-8\) is.*5:40 AM, 1 day after.*\(JST, UTC\+9\)./
|
||||
),
|
||||
'11:22am est in utc' =>
|
||||
test_zci('11:22 A.M. (EST, UTC-5) is 4:22 P.M. (UTC).',
|
||||
html => qr/.*11:22 A.M..*\(EST, UTC-5\) is.*4:22 P.M..*\(UTC\)./
|
||||
test_zci('11:22 AM (EST, UTC-5) is 4:22 PM (UTC).',
|
||||
html => qr/.*11:22 AM.*\(EST, UTC-5\) is.*4:22 PM.*\(UTC\)./
|
||||
),
|
||||
# Intentional non-answers
|
||||
'12 in binary' => undef,
|
||||
);
|
||||
|
||||
# Summertime
|
||||
my $test_location_tz = qr/\(EDT, UTC-4\)/;
|
||||
set_fixed_time("2014-10-14T00:00:00");
|
||||
ddg_goodie_test(
|
||||
['DDG::Goodie::TimezoneConverter'],
|
||||
# Location-specific tests (variable with DST)
|
||||
'13:00 GMT in my time' =>
|
||||
test_zci(qr/13:00 \(GMT\) is 9:00 $test_location_tz/,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'11:22am cest in my timezone' =>
|
||||
test_zci(qr/11:22 AM \(CEST, UTC\+2\) is 5:22 AM $test_location_tz/,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'11:22am cest in localtime' =>
|
||||
test_zci(qr/11:22 AM \(CEST, UTC\+2\) is 5:22 AM $test_location_tz/,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'11:22am cest in my local timezone' =>
|
||||
test_zci(qr/11:22 AM \(CEST, UTC\+2\) is 5:22 AM $test_location_tz/,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'12pm my time in CEST' =>
|
||||
test_zci(qr/Noon $test_location_tz is 6:00 PM \(CEST, UTC\+2\)./,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'12pm local timezone in CEST' =>
|
||||
test_zci(qr/Noon $test_location_tz is 6:00 PM \(CEST, UTC\+2\)./,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'12am my timezone in UTC' =>
|
||||
test_zci(qr/Midnight $test_location_tz is 4:00 AM \(UTC\)./,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'12am local time in UTC' =>
|
||||
test_zci(qr/Midnight $test_location_tz is 4:00 AM \(UTC\)./,
|
||||
html => '-ANY-'
|
||||
),
|
||||
);
|
||||
restore_time();
|
||||
|
||||
set_fixed_time("2014-11-02T11:00:00");
|
||||
$test_location_tz = qr/\(EST, UTC-5\)/;
|
||||
ddg_goodie_test(
|
||||
['DDG::Goodie::TimezoneConverter'],
|
||||
# Location-specific tests (variable with DST)
|
||||
'13:00 GMT in my time' =>
|
||||
test_zci(qr/13:00 \(GMT\) is 8:00 $test_location_tz/,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'11:22am cest in my timezone' =>
|
||||
test_zci(qr/11:22 AM \(CEST, UTC\+2\) is 4:22 AM $test_location_tz/,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'11:22am cest in localtime' =>
|
||||
test_zci(qr/11:22 AM \(CEST, UTC\+2\) is 4:22 AM $test_location_tz/,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'11:22am cest in my local timezone' =>
|
||||
test_zci(qr/11:22 AM \(CEST, UTC\+2\) is 4:22 AM $test_location_tz/,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'12pm my time in CEST' =>
|
||||
test_zci(qr/Noon $test_location_tz is 7:00 PM \(CEST, UTC\+2\)./,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'12pm local timezone in CEST' =>
|
||||
test_zci(qr/Noon $test_location_tz is 7:00 PM \(CEST, UTC\+2\)./,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'12am my timezone in UTC' =>
|
||||
test_zci(qr/Midnight $test_location_tz is 5:00 AM \(UTC\)./,
|
||||
html => '-ANY-'
|
||||
),
|
||||
'12am local time in UTC' =>
|
||||
test_zci(qr/Midnight $test_location_tz is 5:00 AM \(UTC\)./,
|
||||
html => '-ANY-'
|
||||
),
|
||||
);
|
||||
|
||||
restore_time();
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue