aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2013-01-21 12:30:48 +0000
committerAndrew White <andyw@pixeltrix.co.uk>2013-01-21 12:33:49 +0000
commitee3458217b4332c832be4fc47c091be8f2029064 (patch)
treea15cbe6147b2b88c6b5a8e2529ebf7764d02e5ad /activesupport/lib/active_support
parentb79adc4323ff289aed3f5787fdfbb9542aa4f89f (diff)
downloadrails-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/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/string/conversions.rb9
1 files changed, 1 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb
index 07495923a2..428fa1f826 100644
--- a/activesupport/lib/active_support/core_ext/string/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/string/conversions.rb
@@ -52,13 +52,6 @@ class String
# "2012-12-13 12:50".to_datetime #=> Thu, 13 Dec 2012 12:50:00 +0000
# "12/13/2012".to_datetime #=> ArgumentError: invalid date
def to_datetime
- unless blank?
- date_values = ::Date._parse(self, false).
- values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :sec_fraction).
- map! { |arg| arg || 0 }
- date_values[5] += date_values.pop
-
- ::DateTime.civil(*date_values)
- end
+ ::DateTime.parse(self, false) unless blank?
end
end