aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/time
diff options
context:
space:
mode:
authorclaudiob <claudiob@gmail.com>2014-12-17 15:42:28 -0800
committerclaudiob <claudiob@gmail.com>2014-12-17 15:42:28 -0800
commita4069cdb4253c4db880bac8dcbb7378e8a0053c3 (patch)
tree6bec1f9a3d625f43dd437aa70ef839f5b0e94664 /activesupport/lib/active_support/core_ext/time
parent0de9a6ed2149c26648b37dba647605c182c4fc66 (diff)
downloadrails-a4069cdb4253c4db880bac8dcbb7378e8a0053c3.tar.gz
rails-a4069cdb4253c4db880bac8dcbb7378e8a0053c3.tar.bz2
rails-a4069cdb4253c4db880bac8dcbb7378e8a0053c3.zip
Add docs for Time#find_zone
Also improves docs for `Time#find_zone!` [ci skip]
Diffstat (limited to 'activesupport/lib/active_support/core_ext/time')
-rw-r--r--activesupport/lib/active_support/core_ext/time/zones.rb17
1 files changed, 16 insertions, 1 deletions
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 <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 @@ 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 <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