class method
self.get
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
self.get(identifier)
Returns a timezone by its identifier (e.g. “Europe/London”, “America/Chicago” or “UTC”).
Raises InvalidTimezoneIdentifier if the timezone couldn’t be found.
Parameters
-
identifierreq
Source
# File activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb, line 78
def self.get(identifier)
instance = @@loaded_zones[identifier]
unless instance
raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier !~ /^[A-z0-9\+\-_]+(\/[A-z0-9\+\-_]+)*$/
identifier = identifier.gsub(/-/, '__m__').gsub(/\+/, '__p__')
begin
# Use a temporary variable to avoid an rdoc warning
file = "tzinfo/definitions/#{identifier}"
require file
m = Definitions
identifier.split(/\//).each {|part|
m = m.const_get(part)
}
info = m.get
# Could make Timezone subclasses register an interest in an info
# type. Since there are currently only two however, there isn't
# much point.
if info.kind_of?(DataTimezoneInfo)
instance = DataTimezone.new(info)
elsif info.kind_of?(LinkedTimezoneInfo)
instance = LinkedTimezone.new(info)
else
raise InvalidTimezoneIdentifier, "No handler for info type #{info.class}"
end
@@loaded_zones[instance.identifier] = instance
rescue LoadError, NameError => e
raise InvalidTimezoneIdentifier, e.message
end
end
instance
end
Defined in activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb line 78
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in TZInfo::Timezone