class Time
def find_zone!(time_zone)
Time.find_zone! false # => false
Time.find_zone! nil # => nil
Time.find_zone! -5.hours # => #
Time.find_zone! "EST" # => #
Time.find_zone! "America/New_York" # => #
Raises an +ArgumentError+ for invalid time zones.
Accepts the time zone in any format supported by Time.zone=.
Returns a TimeZone instance matching the time zone provided.
def find_zone!(time_zone) if !time_zone || time_zone.is_a?(ActiveSupport::TimeZone) time_zone else # Look up the timezone based on the identifier (unless we've been # passed a TZInfo::Timezone) unless time_zone.respond_to?(:period_for_local) time_zone = ActiveSupport::TimeZone[time_zone] || TZInfo::Timezone.get(time_zone) end # Return if a TimeZone instance, or wrap in a TimeZone instance if a TZInfo::Timezone if time_zone.is_a?(ActiveSupport::TimeZone) time_zone else ActiveSupport::TimeZone.create(time_zone.name, nil, time_zone) end end rescue TZInfo::InvalidTimezoneIdentifier raise ArgumentError, "Invalid Timezone: #{time_zone}" end