module CityUTC::UTC_Time
Public Class Methods
for_city(city_name)
click to toggle source
Returns UTC time for city_name
.
@param [String] city_name
@return [String]
Pretty formatted Universal Time (UTC) for recognized city. when city unrecognized it returns 'UNKNOWN'.
# File sources/city_utc/utc_time.rb, line 15 def self.for_city(city_name) time_zone = City.timezone_for_biggest(city_name) if (tz = ::Timezone[time_zone]).is_a? ::Timezone::NilZone return "UNKNOWN" else utc_time = tz.utc_to_local(Time.now) return UTC_Time.pretty_formatted(utc_time, city_name) end end
pretty_formatted(time, prefix = nil)
click to toggle source
Presents time instance as pretty formatted string.
@example
time # ==> 2017-01-13 12:37:34 UTC pretty_formatted(time) # ==> "UTC: 2017-01-13 12:37:34"
@param [Time] time
@param [String] prefix
Overrides +UTC+ prefix when used.
@return [String]
# File sources/city_utc/utc_time.rb, line 41 def self.pretty_formatted(time, prefix = nil) time = time.utc unless time.utc? if prefix return time.strftime "#{prefix}: %Y-%m-%d %H:%M:%S" else return time.strftime "%Z: %Y-%m-%d %H:%M:%S" end end