diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2011-06-13 18:54:15 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2011-06-13 18:56:06 +0200 |
commit | d6cc0e56bdf1d657f16e5c4026f53d0a4e2dd37e (patch) | |
tree | 167db89b84e1f443c24a3a73961b5f004104c9e0 /activesupport/test/core_ext/time_ext_test.rb | |
parent | b12c2e4ebb85170467ac250219557d631c842d8d (diff) | |
download | rails-d6cc0e56bdf1d657f16e5c4026f53d0a4e2dd37e.tar.gz rails-d6cc0e56bdf1d657f16e5c4026f53d0a4e2dd37e.tar.bz2 rails-d6cc0e56bdf1d657f16e5c4026f53d0a4e2dd37e.zip |
Added Time#whole_day/week/quarter/year as a way of generating ranges (example: Event.where(created_at: Time.now.whole_week)) [DHH]
Diffstat (limited to 'activesupport/test/core_ext/time_ext_test.rb')
-rw-r--r-- | activesupport/test/core_ext/time_ext_test.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 44e02109b1..989a598ae0 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -767,6 +767,26 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase assert_equal false, Time === DateTime.civil(2000) end + def test_whole_day + assert_equal Time.local(2011,6,7,0,0,0)..Time.local(2011,6,7,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).whole_day + end + + def test_whole_week + assert_equal Time.local(2011,6,6,0,0,0)..Time.local(2011,6,12,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).whole_week + end + + def test_whole_month + assert_equal Time.local(2011,6,1,0,0,0)..Time.local(2011,6,30,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).whole_month + end + + def test_whole_quarter + assert_equal Time.local(2011,4,1,0,0,0)..Time.local(2011,6,30,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).whole_quarter + end + + def test_whole_year + assert_equal Time.local(2011,1,1,0,0,0)..Time.local(2011,12,31,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).whole_year + end + protected def with_env_tz(new_tz = 'US/Eastern') old_tz, ENV['TZ'] = ENV['TZ'], new_tz |