class method self.find_zone!

Ruby on Rails 4.1.16

Since v3.1.12

Available in: v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

self.find_zone!(time_zone)

Returns a TimeZone instance or nil, or raises an ArgumentError for invalid timezones.

Parameters

time_zone req
Source
# File activesupport/lib/active_support/core_ext/time/zones.rb, line 55
    def find_zone!(time_zone)
      if !time_zone || time_zone.is_a?(ActiveSupport::TimeZone)
        time_zone
      else
        # lookup timezone based on 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

Defined in activesupport/lib/active_support/core_ext/time/zones.rb line 55 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Time

Type at least 2 characters to search.

↑↓ navigate · open · esc close