aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/string/conversions.rb
diff options
context:
space:
mode:
authorKelly Stannard <kwstannard@gmail.com>2013-01-02 23:50:55 +0000
committerKelly Stannard <kwstannard@gmail.com>2013-01-04 16:39:18 +0000
commitebd27d5714e20e6301a52989ae3c9e73f55ce29d (patch)
tree69380e2ad06fcb285f05ac5743af8b6f2d32422e /activesupport/lib/active_support/core_ext/string/conversions.rb
parentfba6a6a2d9137fb22cc8e6ca4d82a05dd9ba2cce (diff)
downloadrails-ebd27d5714e20e6301a52989ae3c9e73f55ce29d.tar.gz
rails-ebd27d5714e20e6301a52989ae3c9e73f55ce29d.tar.bz2
rails-ebd27d5714e20e6301a52989ae3c9e73f55ce29d.zip
Better error message for String#to_date
I did this because to_date gives a very unhelpful error message if you do not pass in a correct date. In the process I think this cleans up the code nicely and even better it tends to be slightly faster than the current implementation. Benchmark https://gist.github.com/4440875
Diffstat (limited to 'activesupport/lib/active_support/core_ext/string/conversions.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/string/conversions.rb6
1 files changed, 1 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb
index 9d3b81cf38..c795df124b 100644
--- a/activesupport/lib/active_support/core_ext/string/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/string/conversions.rb
@@ -32,11 +32,7 @@ class String
# "2012-12-13".to_date #=> Thu, 13 Dec 2012
# "12/13/2012".to_date #=> ArgumentError: invalid date
def to_date
- unless blank?
- date_values = ::Date._parse(self, false).values_at(:year, :mon, :mday)
-
- ::Date.new(*date_values)
- end
+ ::Date.parse(self, false) unless blank?
end
# Converts a string to a DateTime value.