Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise ArgumentError when an invalid form is passed to Date#to_time #24552

Merged
merged 1 commit into from
Apr 19, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def readable_inspect
#
# date.to_time(:utc) # => 2007-11-10 00:00:00 UTC
def to_time(form = :local)
raise ArgumentError, "Expected :local or :utc, got #{form.inspect}." unless [:local, :utc].include?(form)
::Time.send(form, year, month, day)
end

Expand Down
4 changes: 4 additions & 0 deletions activesupport/test/core_ext/date_ext_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def test_to_time
end
end
end

assert_raise(ArgumentError) do
Date.new(2005, 2, 21).to_time(:tokyo)
end
end

def test_compare_to_time
Expand Down