From 38f28dca3aa16efd6cc3af6453f2e6b9e9655ec1 Mon Sep 17 00:00:00 2001 From: bUg Date: Tue, 14 Aug 2012 20:28:26 +0200 Subject: Added ability to compare date/time with infinity Date, DateTime, Time and TimeWithZone can now be compared to infinity, so it's now possible to create ranges with one infinite bound and date/time object as another bound. Ex.: @range = Range.new(Date.today, Float::INFINITY) Also it's possible to check inclusion of date/time in range with conversion. Ex.: @range.include?(Time.now + 1.year) # => true @range.include?(DateTime.now + 1.year) # => true Ability to create date/time ranges with infinite bound is required for handling postgresql range types. --- activesupport/test/core_ext/time_with_zone_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activesupport/test/core_ext/time_with_zone_test.rb') diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 56020da035..76dc6a35c8 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -1081,3 +1081,15 @@ class TimeWithZoneMethodsForString < ActiveSupport::TestCase Time.zone = old_tz end end + +class TimeWithZoneExtBehaviorTest < ActiveSupport::TestCase + def test_compare_with_infinity + time_zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + twz = ActiveSupport::TimeWithZone.new(Time.now, time_zone) + + assert_nothing_raised do + assert_equal(-1, twz <=> Float::INFINITY) + assert_equal(1, twz <=> -Float::INFINITY) + end + end +end -- cgit v1.2.3