Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions activesupport/lib/active_support/values/time_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ def at(*args)
# If the string is invalid then an +ArgumentError+ will be raised unlike +parse+
# which usually returns +nil+ when given an invalid date string.
def iso8601(str)
raise ArgumentError, "invalid date" if str.nil?

parts = Date._iso8601(str)

raise ArgumentError, "invalid date" if parts.empty?
Expand Down
10 changes: 10 additions & 0 deletions activesupport/test/time_zone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ def test_iso8601_with_zone
assert_equal zone, twz.time_zone
end

def test_iso8601_with_nil
zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"]

exception = assert_raises(ArgumentError) do
zone.iso8601(nil)
end

assert_equal "invalid date", exception.message
end

def test_iso8601_with_invalid_string
zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"]

Expand Down