Skip to content

Commit

Permalink
Refactor - better error handling when no city or no timezone found
Browse files Browse the repository at this point in the history
  • Loading branch information
bryszard committed Nov 18, 2023
1 parent ba0165c commit 9863626
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions spec/dummy/app/avo/actions/show_current_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class ShowCurrentTime < Avo::BaseAction

def handle(**args)
city = args.dig(:fields, :city)
timezone_id = Course.timezones.find { |_, cities| cities.include?(city) }&.first

if city
timezone_id = Course.timezones.find { |_, cities| cities.include?(city) }.first
if timezone_id
formatted_current_time = TZInfo::Timezone.get(timezone_id).now.strftime('%H:%M:%S')

succeed "In #{city} it's now #{formatted_current_time}."
Expand Down

0 comments on commit 9863626

Please sign in to comment.