提交 a4069cdb 编写于 作者: C claudiob

Add docs for Time#find_zone

Also improves docs for `Time#find_zone!`

[ci skip]
上级 0de9a6ed
......@@ -51,7 +51,16 @@ def use_zone(time_zone)
end
end
# Returns a TimeZone instance or nil, or raises an ArgumentError for invalid timezones.
# Returns a TimeZone instance matching the time zone provided.
# Accepts the time zone in any format supported by <tt>Time.zone=</tt>.
# 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
def find_zone!(time_zone)
if !time_zone || time_zone.is_a?(ActiveSupport::TimeZone)
time_zone
......@@ -72,6 +81,12 @@ def find_zone!(time_zone)
raise ArgumentError, "Invalid Timezone: #{time_zone}"
end
# Returns a TimeZone instance matching the time zone provided.
# Accepts the time zone in any format supported by <tt>Time.zone=</tt>.
# Returns +nil+ for invalid time zones.
#
# Time.find_zone "America/New_York" #=> #<ActiveSupport::TimeZone @name="America/New_York" ...>
# Time.find_zone "NOT-A-TIMEZONE" #=> nil
def find_zone(time_zone)
find_zone!(time_zone) rescue nil
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册