Skip to content

Instantly share code, notes, and snippets.

View vittorius's full-sized avatar

Viktor Zahorodnii vittorius

View GitHub Profile
class Time
TZ_ABBREVIATION_MAP = ActiveSupport::TimeZone.all.each_with_object({}) do |tz, hash|
[tz.tzinfo.current_period.start_transition, tz.tzinfo.current_period.end_transition].each do |transition|
hash.merge!(transition.offset.abbreviation.to_s => tz.tzinfo.name) if transition.present?
end
end.merge('UTC' => 'Etc/UTC').freeze
class << self
def tz_name_for(time_like)
TZ_ABBREVIATION_MAP[time_like.zone]