From 29e876f775a5bae0a8bf60c9ec75d89681717a9c Mon Sep 17 00:00:00 2001 From: yui-knk Date: Fri, 15 Apr 2016 00:54:57 +0900 Subject: Raise `ArgumentError` when an invalid form is passed to `Date#to_time` Before this commit `NoMethodError: undefined method `form_name' for Time:Class` is raised when an invalid argument is passed. It is better to raise `ArgumentError` and show list of valid arguments to developers. --- activesupport/lib/active_support/core_ext/date/conversions.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb index ed8bca77ac..9a6d7bb415 100644 --- a/activesupport/lib/active_support/core_ext/date/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date/conversions.rb @@ -80,6 +80,7 @@ class Date # # 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 -- cgit v1.2.3