Module: LocalTimeGem

Defined in:
lib/local_time_gem.rb,
lib/local_time_gem/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.4"

Class Method Summary collapse

Class Method Details

.get_time(city_name) ⇒ Object

Get local time and UTC difference for a city



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/local_time_gem.rb', line 7

def self.get_time(city_name)
  timezone = TZInfo::Timezone.get(city_name)
  now = Time.now.utc

  # Get local time in the specified timezone
  local_time = now.in_time_zone(timezone)

  # Calculate UTC difference (hours)
  utc_offset = local_time.utc_offset / 3600

  # Return formatted information
  {
    local_time: local_time.strftime("%H:%M:%S %Z"),
    utc_difference: utc_offset
  }
end