diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2017-07-05 10:57:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-05 10:57:07 -0700 |
commit | 81492d8f914b39cba4ddb0569af28ebbbed73fa6 (patch) | |
tree | 78d2f15281aafecd981f4fcc20e5926cbc8e5080 /activesupport | |
parent | 2ae84d2fa09af85166f35ca44238a6a20d3c1554 (diff) | |
parent | a5ce433f11af8991451f71b53e6f6899d4d5d288 (diff) | |
download | rails-81492d8f914b39cba4ddb0569af28ebbbed73fa6.tar.gz rails-81492d8f914b39cba4ddb0569af28ebbbed73fa6.tar.bz2 rails-81492d8f914b39cba4ddb0569af28ebbbed73fa6.zip |
Merge pull request #28668 from Dorian/mention-time-parse-argument-error
Mention Time.zone.parse possibly throwing ArgumentError
Diffstat (limited to 'activesupport')
-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 0659b39981..890a2af51c 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -359,7 +359,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) @@ -398,6 +398,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") |