diff options
author | Dorian MariƩ <dorian@doma.io> | 2017-04-04 14:37:02 -0700 |
---|---|---|
committer | Dorian MariƩ <dorian@doma.io> | 2017-04-08 16:16:27 -0700 |
commit | a5ce433f11af8991451f71b53e6f6899d4d5d288 (patch) | |
tree | 09fb57b3b9fd97fa1637e907befa286e932ceb12 | |
parent | c866cf9df8b7d767f8be8272b120b44f453212cb (diff) | |
download | rails-a5ce433f11af8991451f71b53e6f6899d4d5d288.tar.gz rails-a5ce433f11af8991451f71b53e6f6899d4d5d288.tar.bz2 rails-a5ce433f11af8991451f71b53e6f6899d4d5d288.zip |
Mention and test for possible ArgumentError when parsing times
-rw-r--r-- | activesupport/lib/active_support/values/time_zone.rb | 4 | ||||
-rw-r--r-- | activesupport/test/time_zone_test.rb | 10 |
2 files changed, 13 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index ce5207546d..dd69383f5f 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -358,7 +358,7 @@ module ActiveSupport # Time.zone.iso8601('1999-12-31') # => Fri, 31 Dec 1999 00:00:00 HST -10:00 # # If the string is invalid then an +ArgumentError+ will be raised unlike +parse+ - # which returns +nil+ when given an invalid date string. + # which usually returns +nil+ when given an invalid date string. def iso8601(str) parts = Date._iso8601(str) @@ -397,6 +397,8 @@ module ActiveSupport # components are supplied, then the day of the month defaults to 1: # # Time.zone.parse('Mar 2000') # => Wed, 01 Mar 2000 00:00:00 HST -10:00 + # + # If the string is invalid then an +ArgumentError+ could be raised. def parse(str, now = now()) parts_to_time(Date._parse(str, false), now) end diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index de111cc40e..6d7c313610 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -403,6 +403,16 @@ class TimeZoneTest < ActiveSupport::TestCase end end + def test_parse_with_invalid_date + zone = ActiveSupport::TimeZone["UTC"] + + exception = assert_raises(ArgumentError) do + zone.parse("9000") + end + + assert_equal "argument out of range", exception.message + end + def test_rfc3339 zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] twz = zone.rfc3339("1999-12-31T14:00:00-10:00") |