From 2483d63417a1ec1bfcde4690334bae69930c34d5 Mon Sep 17 00:00:00 2001 From: Christoph Petschnig Date: Fri, 15 May 2009 10:06:25 +0200 Subject: [PATCH] String#to_datetime handles timezones correctly --- .../active_support/core_ext/string/conversions.rb | 2 +- activesupport/test/core_ext/string_ext_test.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 2b9f8c7..f9c5a00 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -17,6 +17,6 @@ class String end def to_datetime - ::DateTime.civil(*::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec).map { |arg| arg || 0 }) + ::DateTime.civil(*::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec, :zone).map { |arg| arg || 0 }) end end diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 237a843..b31a5cf 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -120,6 +120,7 @@ class StringInflectionsTest < Test::Unit::TestCase assert_equal DateTime.civil(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_datetime assert_equal 0, "2039-02-27 23:50".to_datetime.offset # use UTC offset assert_equal ::Date::ITALY, "2039-02-27 23:50".to_datetime.start # use Ruby's default start value + assert_equal DateTime.civil(2009, 5, 15, 9, 51, 33), "2009-05-15T09:51:33Z".to_datetime + assert_equal DateTime.civil(2009, 5, 15, 9, 51, 33, 2/24.0), "2009-05-15T09:51:33+02:00".to_datetime end def test_string_to_date -- 1.5.6.3