From a4069cdb4253c4db880bac8dcbb7378e8a0053c3 Mon Sep 17 00:00:00 2001 From: claudiob Date: Wed, 17 Dec 2014 15:42:28 -0800 Subject: Add docs for Time#find_zone Also improves docs for `Time#find_zone!` [ci skip] --- activesupport/lib/active_support/core_ext/time/zones.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/time/zones.rb b/activesupport/lib/active_support/core_ext/time/zones.rb index 64c3b7201b..7f295a88ed 100644 --- a/activesupport/lib/active_support/core_ext/time/zones.rb +++ b/activesupport/lib/active_support/core_ext/time/zones.rb @@ -51,7 +51,16 @@ class Time 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 Time.zone=. + # Raises an ArgumentError for invalid time zones. + # + # Time.find_zone! "America/New_York" #=> # + # Time.find_zone! "EST" #=> # + # Time.find_zone! -5.hours #=> # + # 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 @@ class Time 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 Time.zone=. + # Returns +nil+ for invalid time zones. + # + # Time.find_zone "America/New_York" #=> # + # Time.find_zone "NOT-A-TIMEZONE" #=> nil def find_zone(time_zone) find_zone!(time_zone) rescue nil end -- cgit v1.2.3