diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG.md | 11 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/conversions.rb | 3 | ||||
-rw-r--r-- | activesupport/test/core_ext/string_ext_test.rb | 1 |
3 files changed, 14 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 5b7077a846..32c87ecc64 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,12 @@ +* Match `String#to_time`'s behaviour to that of ruby's implementation for edge cases. + + `nil` is now returned instead of the current date if the string provided does + contain time information, but none that is used to build the `Time` object. + + Fixes #22958. + + *Siim Liiser* + * Rely on the native DateTime#<=> implementation to handle non-datetime like objects instead of returning `nil` ourselves. This restores the ability of `DateTime` instances to be compared with a `Numeric` that represents an @@ -57,6 +66,7 @@ *Jon Moss* + ## Rails 5.0.0.beta2 (February 01, 2016) ## * Change `number_to_currency` behavior for checking negativity. @@ -94,6 +104,7 @@ *Akshay Vishnoi* + ## Rails 5.0.0.beta1 (December 18, 2015) ## * Add thread_m/cattr_accessor/reader/writer suite of methods for declaring class and module variables that live per-thread. 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( diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 4761ce580c..f38b225b38 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -456,6 +456,7 @@ class StringConversionsTest < ActiveSupport::TestCase assert_equal Time.local(2011, 2, 27, 17, 50), "2011-02-27 13:50 -0100".to_time assert_equal Time.utc(2011, 2, 27, 23, 50), "2011-02-27 22:50 -0100".to_time(:utc) assert_equal Time.local(2005, 2, 27, 22, 50), "2005-02-27 14:50 -0500".to_time + assert_nil "010".to_time assert_nil "".to_time end end |