diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-03-05 08:34:42 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-03-05 08:34:42 +0000 |
commit | df57f53d09575f8bc6542f87a3384240b66f9b4b (patch) | |
tree | d6644d733c525485ca9b8a968b12aec31387adf1 /activesupport/test | |
parent | 28628858bebbade2501dfa329b96f921aad90dde (diff) | |
download | rails-df57f53d09575f8bc6542f87a3384240b66f9b4b.tar.gz rails-df57f53d09575f8bc6542f87a3384240b66f9b4b.tar.bz2 rails-df57f53d09575f8bc6542f87a3384240b66f9b4b.zip |
Time#since overflows to DateTime. Introduce Time#to_datetime. Closes #7715.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6335 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/time_ext_test.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index ebeaf264a4..8616129348 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -167,6 +167,8 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal Time.local(2005,2,22,11,10,10), Time.local(2005,2,22,10,10,10).since(3600) assert_equal Time.local(2005,2,24,10,10,10), Time.local(2005,2,22,10,10,10).since(86400*2) assert_equal Time.local(2005,2,24,11,10,35), Time.local(2005,2,22,10,10,10).since(86400*2 + 3600 + 25) + # when out of range of Time, returns a DateTime + assert_equal DateTime.civil(2038,1,20,11,59,59), Time.utc(2038,1,18,11,59,59).since(86400*2) end def test_daylight_savings_time_crossings_forward_start @@ -351,6 +353,16 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_nothing_raised { Time.now.xmlschema } end + def test_to_datetime + assert_equal Time.utc(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, 0, 0) + with_timezone 'US/Eastern' do + assert_equal Time.local(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, DateTime.now.offset, 0) + end + with_timezone 'NZ' do + assert_equal Time.local(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, DateTime.now.offset, 0) + end + end + protected def with_timezone new_tz='US/Eastern' old_tz, ENV['TZ'] = ENV['TZ'], new_tz |