diff options
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/date_ext_test.rb | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 3e003b3ed4..59c168d33d 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -286,19 +286,59 @@ class DateExtCalculationsTest < ActiveSupport::TestCase def test_since assert_equal Time.local(2005,2,21,0,0,45), Date.new(2005,2,21).since(45) end + + def test_since_when_zone_default_is_set + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + with_env_tz 'UTC' do + with_tz_default zone do + assert_equal zone.local(2005,2,21,0,0,45), Date.new(2005,2,21).since(45) + assert_equal zone, Date.new(2005,2,21).since(45).time_zone + end + end + end def test_ago assert_equal Time.local(2005,2,20,23,59,15), Date.new(2005,2,21).ago(45) end + + def test_ago_when_zone_default_is_set + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + with_env_tz 'UTC' do + with_tz_default zone do + assert_equal zone.local(2005,2,20,23,59,15), Date.new(2005,2,21).ago(45) + assert_equal zone, Date.new(2005,2,21).ago(45).time_zone + end + end + end def test_beginning_of_day assert_equal Time.local(2005,2,21,0,0,0), Date.new(2005,2,21).beginning_of_day end + + def test_beginning_of_day_when_zone_default_is_set + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + with_env_tz 'UTC' do + with_tz_default zone do + assert_equal zone.local(2005,2,21,0,0,0), Date.new(2005,2,21).beginning_of_day + assert_equal zone, Date.new(2005,2,21).beginning_of_day.time_zone + end + end + end def test_end_of_day assert_equal Time.local(2005,2,21,23,59,59,999999.999), Date.new(2005,2,21).end_of_day end - + + def test_end_of_day_when_zone_default_is_set + zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + with_env_tz 'UTC' do + with_tz_default zone do + assert_equal zone.local(2005,2,21,23,59,59,999999.999), Date.new(2005,2,21).end_of_day + assert_equal zone, Date.new(2005,2,21).end_of_day.time_zone + end + end + end + def test_xmlschema with_env_tz 'US/Eastern' do assert_match(/^1980-02-28T00:00:00-05:?00$/, Date.new(1980, 2, 28).xmlschema) @@ -310,6 +350,15 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end end end + + def test_xmlschema_when_zone_default_is_set + with_env_tz 'UTC' do + with_tz_default ActiveSupport::TimeZone['Eastern Time (US & Canada)'] do # UTC -5 + assert_match(/^1980-02-28T00:00:00-05:?00$/, Date.new(1980, 2, 28).xmlschema) + assert_match(/^1980-06-28T00:00:00-04:?00$/, Date.new(1980, 6, 28).xmlschema) + end + end + end def test_today Date.stubs(:current).returns(Date.new(2000, 1, 1)) |