aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/time/zones.rb
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2014-12-20 14:26:21 +0000
committerVijay Dev <vijaydev.cse@gmail.com>2014-12-20 14:26:21 +0000
commit15590c1a2a76b6560840cfa55c5a2485b4566460 (patch)
tree66c08538f97e39caf48559f603c578df044d4a4d /activesupport/lib/active_support/core_ext/time/zones.rb
parenta8015865d24c5cd4551c3be06abd8211f79888ea (diff)
parent78ae8eebe5c7cfef114d1e6266a8b3d198545d2a (diff)
downloadrails-15590c1a2a76b6560840cfa55c5a2485b4566460.tar.gz
rails-15590c1a2a76b6560840cfa55c5a2485b4566460.tar.bz2
rails-15590c1a2a76b6560840cfa55c5a2485b4566460.zip
Merge branch 'master' of github.com:rails/docrails
Diffstat (limited to 'activesupport/lib/active_support/core_ext/time/zones.rb')
-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..0668eadb1e 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