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