From 9c2c677d903bcdea3feb1cad6c6d4c8c07cc8034 Mon Sep 17 00:00:00 2001 From: Siim Liiser Date: Wed, 13 Jan 2016 11:19:23 +0200 Subject: Match `String#to_time`'s behaviour to ruby Previously `String#to_time` returned the midnight of the current date in some cases where there was no relavant information in the string. Now the method returns `nil` instead in those cases. Fixes #22958. --- activesupport/lib/active_support/core_ext/string/conversions.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index fd79a40e31..71612e09fa 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -18,7 +18,8 @@ class String # "12/13/2012".to_time # => ArgumentError: argument out of range def to_time(form = :local) parts = Date._parse(self, false) - return if parts.empty? + used_keys = %i(year mon mday hour min sec sec_fraction offset) + return if (parts.keys & used_keys).empty? now = Time.now time = Time.new( -- cgit v1.2.3