diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 29a88b07ad..e84a3909a1 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -18,6 +18,7 @@ class String # "2012-12-13T06:12".to_time # => 2012-12-13 06:12:00 +0100 # "2012-12-13T06:12".to_time(:utc) # => 2012-12-13 06:12:00 UTC # "12/13/2012".to_time # => ArgumentError: argument out of range + # "1604326192".to_time # => ArgumentError: argument out of range def to_time(form = :local) parts = Date._parse(self, false) used_keys = %i(year mon mday hour min sec sec_fraction offset) diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index f27a4423d3..cfde3a92bc 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -573,6 +573,14 @@ class StringConversionsTest < ActiveSupport::TestCase end end + def test_timestamp_string_to_time + exception = assert_raises(ArgumentError) do + "1604326192".to_time + end + + assert_equal "argument out of range", exception.message + end + def test_string_to_time_utc_offset with_env_tz "US/Eastern" do if ActiveSupport.to_time_preserves_timezone