diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-01-21 12:30:48 +0000 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-01-21 12:33:49 +0000 |
commit | ee3458217b4332c832be4fc47c091be8f2029064 (patch) | |
tree | a15cbe6147b2b88c6b5a8e2529ebf7764d02e5ad /activesupport/test/core_ext | |
parent | b79adc4323ff289aed3f5787fdfbb9542aa4f89f (diff) | |
download | rails-ee3458217b4332c832be4fc47c091be8f2029064.tar.gz rails-ee3458217b4332c832be4fc47c091be8f2029064.tar.bz2 rails-ee3458217b4332c832be4fc47c091be8f2029064.zip |
Use `DateTime.parse` inside `String#to_datetime`
Use the standard library's `DateTime.parse` because it's marginally
faster and supports partial date/time strings.
Benchmark:
user system total real
old 3.980000 0.000000 3.980000 ( 3.987606)
new 3.640000 0.010000 3.650000 ( 3.641342)
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/string_ext_test.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 951e6bac07..db1cf14abf 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -327,6 +327,12 @@ class StringConversionsTest < ActiveSupport::TestCase assert_nil "".to_datetime end + def test_partial_string_to_datetime + now = DateTime.now + assert_equal DateTime.civil(now.year, now.month, now.day, 23, 50), "23:50".to_datetime + assert_equal DateTime.civil(now.year, now.month, now.day, 23, 50, 0, "-04:00"), "23:50 -0400".to_datetime + end + def test_string_to_date assert_equal Date.new(2005, 2, 27), "2005-02-27".to_date assert_nil "".to_date |