From 4685fa0c20fbf3e78eaad94756e0f4a644447a10 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 4 Jun 2007 19:49:13 +0000 Subject: String#to_time overflows to DateTime. Add String#to_datetime. Closes #8572. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6935 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/core_ext/string/conversions.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext/string') diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index cfb767d1f9..096778e26f 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -7,12 +7,16 @@ module ActiveSupport #:nodoc: module Conversions # Form can be either :utc (default) or :local. def to_time(form = :utc) - ::Time.send(form, *ParseDate.parsedate(self)) + ::Time.send("#{form}_time", *ParseDate.parsedate(self)[0..5].map {|arg| arg || 0}) end def to_date ::Date.new(*ParseDate.parsedate(self)[0..2]) end + + def to_datetime + ::DateTime.civil(*ParseDate.parsedate(self)[0..5].map {|arg| arg || 0} << 0 << 0) + end end end end -- cgit v1.2.3