diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-02-27 22:53:54 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-02-27 22:53:54 +0000 |
commit | 3582bce6fdb30730b34b91a17b8bb33066eed7b8 (patch) | |
tree | 320082700df722023dce4d362e4ecf81979600cb /activesupport/test | |
parent | 558c5ff251fa790cd0d623468cc0e45d7efa45ed (diff) | |
download | rails-3582bce6fdb30730b34b91a17b8bb33066eed7b8.tar.gz rails-3582bce6fdb30730b34b91a17b8bb33066eed7b8.tar.bz2 rails-3582bce6fdb30730b34b91a17b8bb33066eed7b8.zip |
Adding Time#end_of_day, _quarter, _week, and _year. Closes #9312.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8934 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/date_ext_test.rb | 23 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_ext_test.rb | 35 |
2 files changed, 58 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index cd74be8321..2e363c439a 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -60,6 +60,29 @@ class DateExtCalculationsTest < Test::Unit::TestCase assert_equal Date.new(2005,4,1), Date.new(2005,6,30).beginning_of_quarter end + def test_end_of_week + assert_equal Date.new(2008,2,24), Date.new(2008,2,22).end_of_week + assert_equal Date.new(2008,3,2), Date.new(2008,2,25).end_of_week #monday + assert_equal Date.new(2008,3,2), Date.new(2008,2,26).end_of_week #tuesday + assert_equal Date.new(2008,3,2), Date.new(2008,2,27).end_of_week #wednesday + assert_equal Date.new(2008,3,2), Date.new(2008,2,28).end_of_week #thursday + assert_equal Date.new(2008,3,2), Date.new(2008,2,29).end_of_week #friday + assert_equal Date.new(2008,3,2), Date.new(2008,3,01).end_of_week #saturday + assert_equal Date.new(2008,3,2), Date.new(2008,3,02).end_of_week #sunday + end + + def test_end_of_quarter + assert_equal Date.new(2008,3,31), Date.new(2008,2,15).end_of_quarter + assert_equal Date.new(2008,3,31), Date.new(2008,3,31).end_of_quarter + assert_equal Date.new(2008,12,31), Date.new(2008,10,8).end_of_quarter + assert_equal Date.new(2008,6,30), Date.new(2008,4,14).end_of_quarter + assert_equal Date.new(2008,9,30), Date.new(2008,8,21).end_of_quarter + end + + def test_end_of_year + assert_equal Date.new(2008,12,31).to_s, Date.new(2008,2,22).end_of_year.to_s + end + def test_end_of_month assert_equal Date.new(2005,3,31), Date.new(2005,3,20).end_of_month assert_equal Date.new(2005,2,28), Date.new(2005,2,20).end_of_month diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index d4a555d55e..628f07d6c4 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -83,12 +83,47 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal Time.local(2005,4,1,0,0,0), Time.local(2005,6,30,23,59,59).beginning_of_quarter end + def test_end_of_day + assert_equal Time.local(2007,8,12,23,59,59), Time.local(2007,8,12,10,10,10).end_of_day + with_env_tz 'US/Eastern' do + assert_equal Time.local(2007,4,2,23,59,59), Time.local(2007,4,2,10,10,10).end_of_day, 'start DST' + assert_equal Time.local(2007,10,29,23,59,59), Time.local(2007,10,29,10,10,10).end_of_day, 'ends DST' + end + with_env_tz 'NZ' do + assert_equal Time.local(2006,3,19,23,59,59), Time.local(2006,3,19,10,10,10).end_of_day, 'ends DST' + assert_equal Time.local(2006,10,1,23,59,59), Time.local(2006,10,1,10,10,10).end_of_day, 'start DST' + end + end + + def test_end_of_week + assert_equal Time.local(2008,1,6,23,59,59), Time.local(2007,12,31,10,10,10).end_of_week + assert_equal Time.local(2007,9,2,23,59,59), Time.local(2007,8,27,0,0,0).end_of_week #monday + assert_equal Time.local(2007,9,2,23,59,59), Time.local(2007,8,28,0,0,0).end_of_week #tuesday + assert_equal Time.local(2007,9,2,23,59,59), Time.local(2007,8,29,0,0,0).end_of_week #wednesday + assert_equal Time.local(2007,9,2,23,59,59), Time.local(2007,8,30,0,0,0).end_of_week #thursday + assert_equal Time.local(2007,9,2,23,59,59), Time.local(2007,8,31,0,0,0).end_of_week #friday + assert_equal Time.local(2007,9,2,23,59,59), Time.local(2007,9,01,0,0,0).end_of_week #saturday + assert_equal Time.local(2007,9,2,23,59,59), Time.local(2007,9,02,0,0,0).end_of_week #sunday + end + def test_end_of_month assert_equal Time.local(2005,3,31,23,59,59), Time.local(2005,3,20,10,10,10).end_of_month assert_equal Time.local(2005,2,28,23,59,59), Time.local(2005,2,20,10,10,10).end_of_month assert_equal Time.local(2005,4,30,23,59,59), Time.local(2005,4,20,10,10,10).end_of_month end + def test_end_of_quarter + assert_equal Time.local(2007,3,31,23,59,59), Time.local(2007,2,15,10,10,10).end_of_quarter + assert_equal Time.local(2007,3,31,23,59,59), Time.local(2007,3,31,0,0,0).end_of_quarter + assert_equal Time.local(2007,12,31,23,59,59), Time.local(2007,12,21,10,10,10).end_of_quarter + assert_equal Time.local(2007,6,30,23,59,59), Time.local(2007,4,1,0,0,0).end_of_quarter + end + + def test_end_of_year + assert_equal Time.local(2007,12,31,23,59,59), Time.local(2007,2,22,10,10,10).end_of_year + assert_equal Time.local(2007,12,31,23,59,59), Time.local(2007,12,31,10,10,10).end_of_year + end + def test_beginning_of_year assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,2,22,10,10,10).beginning_of_year end |