class method
self.find_zone!
Ruby on Rails 7.2.3
Since v3.1.12Signature
self.find_zone!(time_zone)
Returns a TimeZone instance matching the time zone provided. Accepts the time zone in any format supported by Time.zone=. Raises an ArgumentError for invalid time zones.
Time.find_zone! "America/New_York" # => #<ActiveSupport::TimeZone @name="America/New_York" ...> Time.find_zone! "EST" # => #<ActiveSupport::TimeZone @name="EST" ...> Time.find_zone! -5.hours # => #<ActiveSupport::TimeZone @name="Bogota" ...> Time.find_zone! nil # => nil Time.find_zone! false # => false Time.find_zone! "NOT-A-TIMEZONE" # => ArgumentError: Invalid Timezone: NOT-A-TIMEZONE
Parameters
-
time_zonereq
Source
# File activesupport/lib/active_support/core_ext/time/zones.rb, line 81
def find_zone!(time_zone)
return time_zone unless time_zone
ActiveSupport::TimeZone[time_zone] || raise(ArgumentError, "Invalid Timezone: #{time_zone}")
end
Defined in activesupport/lib/active_support/core_ext/time/zones.rb line 81
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Time