Skip to content

Commit

Permalink
Fix timezonetime (duckduckgo#4712)
Browse files Browse the repository at this point in the history
* Disable caching of result

* Cleanup whitespace
  • Loading branch information
moollaza authored May 31, 2019
1 parent d13a584 commit dd6d184
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
24 changes: 12 additions & 12 deletions lib/DDG/Goodie/Timezonetime.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 => {

Expand Down
10 changes: 5 additions & 5 deletions t/Timezonetime.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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
#
Expand All @@ -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
#
Expand All @@ -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
#
Expand Down

0 comments on commit dd6d184

Please sign in to comment.