aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/date_ext_test.rb
diff options
context:
space:
mode:
authorHenrik Nyh <henrik@nyh.se>2016-05-09 16:06:19 +0100
committerHenrik Nyh <henrik@nyh.se>2016-05-11 21:25:06 +0100
commitf005202972cdb864327c854404fd18510e00f963 (patch)
tree095b34506f4c1a86dac30186ff1e9e862617aa88 /activesupport/test/core_ext/date_ext_test.rb
parenta0b3de3002bd9f608b3a9e41e702762b10430207 (diff)
downloadrails-f005202972cdb864327c854404fd18510e00f963.tar.gz
rails-f005202972cdb864327c854404fd18510e00f963.tar.bz2
rails-f005202972cdb864327c854404fd18510e00f963.zip
Introduce Date#all_day
Useful for queries like: Item.where(created_at: Date.current.all_day) There was already a Time#all_day with the same behaviour, but for queries like the above, Date is more convenient.
Diffstat (limited to 'activesupport/test/core_ext/date_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb
index 932675a50d..8052d38c33 100644
--- a/activesupport/test/core_ext/date_ext_test.rb
+++ b/activesupport/test/core_ext/date_ext_test.rb
@@ -284,6 +284,23 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
end
end
+ def test_all_day
+ beginning_of_day = Time.local(2011,6,7,0,0,0)
+ end_of_day = Time.local(2011,6,7,23,59,59,Rational(999999999, 1000))
+ assert_equal beginning_of_day..end_of_day, Date.new(2011,6,7).all_day
+ end
+
+ def test_all_day_when_zone_is_set
+ zone = ActiveSupport::TimeZone["Hawaii"]
+ with_env_tz "UTC" do
+ with_tz_default zone do
+ beginning_of_day = zone.local(2011,6,7,0,0,0)
+ end_of_day = zone.local(2011,6,7,23,59,59,Rational(999999999, 1000))
+ assert_equal beginning_of_day..end_of_day, Date.new(2011,6,7).all_day
+ end
+ end
+ end
+
def test_all_week
assert_equal Date.new(2011,6,6)..Date.new(2011,6,12), Date.new(2011,6,7).all_week
assert_equal Date.new(2011,6,5)..Date.new(2011,6,11), Date.new(2011,6,7).all_week(:sunday)