aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/time_zone_test.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2014-02-18 09:35:11 +0100
committerXavier Noria <fxn@hashref.com>2014-02-18 09:42:06 +0100
commit65a7c571050da47ab997a5a07fb9f1e2302bf348 (patch)
treef56f672c3357bc5cf6f6ee41d2b78a1a5f298816 /activesupport/test/time_zone_test.rb
parentf43083609a0a16f91e5f1cfc98a289a23865aea8 (diff)
downloadrails-65a7c571050da47ab997a5a07fb9f1e2302bf348.tar.gz
rails-65a7c571050da47ab997a5a07fb9f1e2302bf348.tar.bz2
rails-65a7c571050da47ab997a5a07fb9f1e2302bf348.zip
time helpers honor the application time zone when passed a date
Rails applications are expected to be always aware of the application time zone. To be consistent with that contract, we have to assume that a bare date passed to time helpers is a date in the application time zone, not in the system time zone. The system time zone is irrelevant, we should totally ignore it. For example, travel_to user.birth_date + 40.years should make that user be 40th years old regardless of the system time zone. Without this patch that may not be true.
Diffstat (limited to 'activesupport/test/time_zone_test.rb')
-rw-r--r--activesupport/test/time_zone_test.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index cd79efbe8c..48bcfa6929 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -124,6 +124,20 @@ class TimeZoneTest < ActiveSupport::TestCase
travel_back
end
+ def test_travel_to_a_date
+ with_env_tz do
+ Time.use_zone('Hawaii') do
+ date = Date.new(2014, 2, 18)
+ time = date.midnight
+
+ travel_to date
+
+ assert_equal date, Date.current
+ assert_equal time, Time.current
+ end
+ end
+ end
+
def test_local
time = ActiveSupport::TimeZone["Hawaii"].local(2007, 2, 5, 15, 30, 45)
assert_equal Time.utc(2007, 2, 5, 15, 30, 45), time.time