How do you convert js values received as TZInfo identifiers to Rails TimeZone name/key?
FROM: \"America/New_York\"
returned fro
The magic I believe everyone is really after, and solves the problem that @ajbraus raised, is a one-liner that could be one of the strangely hardest things to find discussed anywhere:
timezone = ActiveSupport::TimeZone[TZInfo::Timezone.get('America/Vancouver').period_for_utc(Time.now.utc).utc_offset]
=> #<ActiveSupport::TimeZone:0x00007fc2baa6d900 @name="Pacific Time (US & Canada)", @utc_offset=nil, @tzinfo=#<TZInfo::TimezoneProxy: America/Los_Angeles>>
Otherwise, if you try searching through ActiveSupport's entire DB of zones, you get nada:
ActiveSupport::TimeZone.all.find{ |tz| tz.tzinfo == ActiveSupport::TimeZone.find_tzinfo('America/Vancouver') }
=> nil
The complexity boils down to the following:
Temporal includes the needed logic, but to answer your question:
Time.zone = ActiveSupport::TimeZone.new("America/New_York")
Edit, I guess my answer is incomplete. You want to get it from "America/New_York" to "Eastern Time (US & Canada)", correct? If that's the case this is the best solution I have -- though someone may be able to provide a better one.
ActiveSupport::TimeZone::MAPPING.select {|k, v| v == "America/New_York" }.keys.first