aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-06-04 19:49:13 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-06-04 19:49:13 +0000
commit4685fa0c20fbf3e78eaad94756e0f4a644447a10 (patch)
tree461cc78b22b047c178093c6b7fac6333a0e40de6 /activesupport
parent601778e38af53c66d604fe31a3b84ba84d973511 (diff)
downloadrails-4685fa0c20fbf3e78eaad94756e0f4a644447a10.tar.gz
rails-4685fa0c20fbf3e78eaad94756e0f4a644447a10.tar.bz2
rails-4685fa0c20fbf3e78eaad94756e0f4a644447a10.zip
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
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/core_ext/string/conversions.rb6
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb3
3 files changed, 10 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 6e46216c91..c0a314ebe0 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* String#to_time overflows to DateTime. Add String#to_datetime. #8572 [Geoff Buesing]
+
* Date.yesterday and .tomorrow. #8571 [Geoff Buesing]
* Readable Date and DateTime#inspect. #8570 [Geoff Buesing]
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
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index cd2d12c3b1..b588fadf4f 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -78,7 +78,10 @@ class StringInflectionsTest < Test::Unit::TestCase
def test_string_to_time
assert_equal Time.utc(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time
assert_equal Time.local(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time(:local)
+ assert_equal DateTime.civil(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time
+ assert_equal Time.local_time(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time(:local)
assert_equal Date.new(2005, 2, 27), "2005-02-27".to_date
+ assert_equal DateTime.civil(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_datetime
end
def test_access