class method
self.[]
Ruby on Rails 5.2.8.1
Since v2.2.3Signature
self.[](arg)
Locate a specific time zone object. If the argument is a string, it is interpreted to mean the name of the timezone to locate. If it is a numeric value it is either the hour offset, or the second offset, of the timezone to find. (The first one with that offset will be returned.) Returns nil if no such time zone is known to the system.
Parameters
-
argreq
Source
# File activesupport/lib/active_support/values/time_zone.rb, line 230
def [](arg)
case arg
when String
begin
@lazy_zones_map[arg] ||= create(arg)
rescue TZInfo::InvalidTimezoneIdentifier
nil
end
when Numeric, ActiveSupport::Duration
arg *= 3600 if arg.abs <= 13
all.find { |z| z.utc_offset == arg.to_i }
else
raise ArgumentError, "invalid argument to TimeZone[]: #{arg.inspect}"
end
end
Defined in activesupport/lib/active_support/values/time_zone.rb line 230
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::TimeZone