aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorSiim Liiser <siim@wisemedia.ee>2016-01-13 11:19:23 +0200
committerAndrew White <andrew.white@unboxedconsulting.com>2016-04-04 00:00:31 +0100
commit9c2c677d903bcdea3feb1cad6c6d4c8c07cc8034 (patch)
tree6a91583bda2febe69db837af6eac54679b8ab22f /activesupport/lib
parent08073125a5bd4cae0f2e02723e7743a389d496cd (diff)
downloadrails-9c2c677d903bcdea3feb1cad6c6d4c8c07cc8034.tar.gz
rails-9c2c677d903bcdea3feb1cad6c6d4c8c07cc8034.tar.bz2
rails-9c2c677d903bcdea3feb1cad6c6d4c8c07cc8034.zip
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.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/string/conversions.rb3
1 files changed, 2 insertions, 1 deletions
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(