From dd6d184da72292e9e9b36c7888892016dd43609f Mon Sep 17 00:00:00 2001 From: Zaahir Moolla Date: Thu, 30 May 2019 23:13:47 -0400 Subject: [PATCH] Fix timezonetime (#4712) * Disable caching of result * Cleanup whitespace --- lib/DDG/Goodie/Timezonetime.pm | 24 ++++++++++++------------ t/Timezonetime.t | 10 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/DDG/Goodie/Timezonetime.pm b/lib/DDG/Goodie/Timezonetime.pm index d6a48be8b..cfad0a12d 100644 --- a/lib/DDG/Goodie/Timezonetime.pm +++ b/lib/DDG/Goodie/Timezonetime.pm @@ -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 => { diff --git a/t/Timezonetime.t b/t/Timezonetime.t index 69c6fbff3..ea09b0006 100644 --- a/t/Timezonetime.t +++ b/t/Timezonetime.t @@ -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 #