提交 81492d8f 编写于 作者: A Aaron Patterson 提交者: GitHub

Merge pull request #28668 from Dorian/mention-time-parse-argument-error

Mention Time.zone.parse possibly throwing ArgumentError
......@@ -359,7 +359,7 @@ def at(secs)
# 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 @@ def iso8601(str)
# 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
......
......@@ -403,6 +403,16 @@ def test_parse_handles_dst_jump
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")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册