aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorNate Mueller <nate@nearbuysystems.com>2011-06-02 20:43:23 -0700
committerNate Mueller <nate@nearbuysystems.com>2011-06-02 20:51:09 -0700
commitf449da53ac69495e736c7f1ce0f1bc6ebe356081 (patch)
tree616efc7f8b607d33fa69b59ccca17731d61d4ac1 /activesupport
parentf064664de72a34d24568eadf7340f41876df4b20 (diff)
downloadrails-f449da53ac69495e736c7f1ce0f1bc6ebe356081.tar.gz
rails-f449da53ac69495e736c7f1ce0f1bc6ebe356081.tar.bz2
rails-f449da53ac69495e736c7f1ce0f1bc6ebe356081.zip
Make String.to_time respect timezones
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/string/conversions.rb4
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb1
2 files changed, 3 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb
index 5b2cb6e331..664537eea4 100644
--- a/activesupport/lib/active_support/core_ext/string/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/string/conversions.rb
@@ -34,9 +34,9 @@ class String
# Form can be either :utc (default) or :local.
def to_time(form = :utc)
return nil if self.blank?
- d = ::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction).map { |arg| arg || 0 }
+ d = ::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction, :offset).map { |arg| arg || 0 }
d[6] *= 1000000
- ::Time.send("#{form}_time", *d)
+ ::Time.send("#{form}_time", *d[0..6]) - d[7]
end
def to_date
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index 32675c884a..0fd0cb8ac7 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -158,6 +158,7 @@ class StringInflectionsTest < Test::Unit::TestCase
assert_equal Time.local(2005, 2, 27, 23, 50, 19, 275038), "2005-02-27T23:50:19.275038".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 Time.utc(2039, 2, 27, 23, 50), "2039-02-27 22:50 -0100".to_time
assert_nil "".to_time
end