parent
d13a584188
commit
dd6d184da7
|
@ -9,32 +9,32 @@ use DateTime;
|
||||||
use DateTime::TimeZone;
|
use DateTime::TimeZone;
|
||||||
|
|
||||||
zci answer_type => 'timezonetime';
|
zci answer_type => 'timezonetime';
|
||||||
zci is_cached => 1;
|
zci is_cached => 0;
|
||||||
|
|
||||||
triggers start => ("what time in", "what time is it in", "time in");
|
triggers start => ("what time in", "what time is it in", "time in");
|
||||||
triggers startend => ("time", "now time", "time now");
|
triggers startend => ("time", "now time", "time now");
|
||||||
|
|
||||||
# Mapping short timezone names to one used by DateTime:Timezone module
|
# Mapping short timezone names to one used by DateTime:Timezone module
|
||||||
my $timezoneMapping = {
|
my $timezoneMapping = {
|
||||||
"IST" => "Asia/Kolkata",
|
"IST" => "Asia/Kolkata",
|
||||||
"EST" => "EST",
|
"EST" => "EST",
|
||||||
"UTC" => "UTC",
|
"UTC" => "UTC",
|
||||||
"GMT" => "GMT",
|
"GMT" => "GMT",
|
||||||
"BST" => "Europe/London",
|
"BST" => "Europe/London",
|
||||||
"PST" => "PST8PDT",
|
"PST" => "PST8PDT",
|
||||||
"CST" => "CST6CDT"
|
"CST" => "CST6CDT"
|
||||||
};
|
};
|
||||||
|
|
||||||
my $timezones = join('|', keys(%$timezoneMapping));
|
my $timezones = join('|', keys(%$timezoneMapping));
|
||||||
|
|
||||||
handle remainder => sub {
|
handle remainder => sub {
|
||||||
my $query = $_;
|
my $query = $_;
|
||||||
|
|
||||||
my $daylightStatus = "";
|
my $daylightStatus = "";
|
||||||
|
|
||||||
my $timezone = uc($query);
|
my $timezone = uc($query);
|
||||||
my $mappedTimezone = $timezoneMapping->{$timezone} // 0;
|
my $mappedTimezone = $timezoneMapping->{$timezone} // 0;
|
||||||
return unless $mappedTimezone;
|
return unless $mappedTimezone;
|
||||||
|
|
||||||
# Get time for desired timezone
|
# Get time for desired timezone
|
||||||
my $tz = DateTime::TimeZone->new( name => $mappedTimezone );
|
my $tz = DateTime::TimeZone->new( name => $mappedTimezone );
|
||||||
|
@ -43,14 +43,14 @@ handle remainder => sub {
|
||||||
$dt->add(seconds => $offset);
|
$dt->add(seconds => $offset);
|
||||||
my $time = $dt->hms(':');
|
my $time = $dt->hms(':');
|
||||||
|
|
||||||
# Check if timezone is in daylight saving or not
|
# Check if timezone is in daylight saving or not
|
||||||
if ($tz->is_dst_for_datetime( $dt )) {
|
if ($tz->is_dst_for_datetime( $dt )) {
|
||||||
$daylightStatus = "$timezone is in daylight saving";
|
$daylightStatus = "$timezone is in daylight saving";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$daylightStatus = "$timezone is not in daylight saving";
|
$daylightStatus = "$timezone is not in daylight saving";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "$time $timezone $daylightStatus",
|
return "$time $timezone $daylightStatus",
|
||||||
structured_answer => {
|
structured_answer => {
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,11 @@ use Test::Deep;
|
||||||
use DDG::Test::Goodie;
|
use DDG::Test::Goodie;
|
||||||
|
|
||||||
zci answer_type => 'timezonetime';
|
zci answer_type => 'timezonetime';
|
||||||
zci is_cached => 1;
|
zci is_cached => 0;
|
||||||
|
|
||||||
sub build_structured_answer {
|
sub build_structured_answer {
|
||||||
my ($time, $timezone, $daylightSaving) = @_;
|
my ($time, $timezone, $daylightSaving) = @_;
|
||||||
|
|
||||||
return "$time $timezone $daylightSaving",
|
return "$time $timezone $daylightSaving",
|
||||||
structured_answer => {
|
structured_answer => {
|
||||||
data => {
|
data => {
|
||||||
|
@ -33,7 +33,7 @@ set_fixed_time('2017-06-03T09:36:53Z');
|
||||||
|
|
||||||
ddg_goodie_test(
|
ddg_goodie_test(
|
||||||
['DDG::Goodie::Timezonetime'],
|
['DDG::Goodie::Timezonetime'],
|
||||||
|
|
||||||
#
|
#
|
||||||
# 1. Queries that SHOULD TRIGGER ~~ IN DAYLIGHT SAVINGS
|
# 1. Queries that SHOULD TRIGGER ~~ IN DAYLIGHT SAVINGS
|
||||||
#
|
#
|
||||||
|
@ -50,7 +50,7 @@ set_fixed_time('2016-01-03T09:36:53Z');
|
||||||
|
|
||||||
ddg_goodie_test(
|
ddg_goodie_test(
|
||||||
['DDG::Goodie::Timezonetime'],
|
['DDG::Goodie::Timezonetime'],
|
||||||
|
|
||||||
#
|
#
|
||||||
# 2. Queries that SHOULD TRIGGER ~~ NOT IN DAYLIGHT SAVINGS
|
# 2. Queries that SHOULD TRIGGER ~~ NOT IN DAYLIGHT SAVINGS
|
||||||
#
|
#
|
||||||
|
@ -61,7 +61,7 @@ ddg_goodie_test(
|
||||||
'ist now time' => build_test("15:06:53", "IST", "IST is not in daylight saving"),
|
'ist now time' => build_test("15:06:53", "IST", "IST is not in daylight saving"),
|
||||||
'time now cst' => build_test("03:36:53", "CST", "CST is not in daylight saving"),
|
'time now cst' => build_test("03:36:53", "CST", "CST is not in daylight saving"),
|
||||||
'time in pst' => build_test("01:36:53", "PST", "PST is not in daylight saving"),
|
'time in pst' => build_test("01:36:53", "PST", "PST is not in daylight saving"),
|
||||||
|
|
||||||
#
|
#
|
||||||
# 3. Queries that SHOULD NOT TRIGGER
|
# 3. Queries that SHOULD NOT TRIGGER
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue