mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Create unit test to use to_time for timestamp in string
This commit is contained in:
parent
22584d0cbf
commit
a52ca5fddc
2 changed files with 9 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue