aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorShigeya Suzuki <shigeya@wide.ad.jp>2012-02-09 22:08:28 -0800
committerShigeya Suzuki <shigeya@wide.ad.jp>2012-02-09 22:08:28 -0800
commit6f68e632746f72469cbd1c1b6cb9d3f1ed1730a0 (patch)
treefbef94df48e7bab274826ad24fa9f278b8c5db99 /activesupport
parent75ffd8701d04d943eddcafee08e19b90bce8936c (diff)
downloadrails-6f68e632746f72469cbd1c1b6cb9d3f1ed1730a0.tar.gz
rails-6f68e632746f72469cbd1c1b6cb9d3f1ed1730a0.tar.bz2
rails-6f68e632746f72469cbd1c1b6cb9d3f1ed1730a0.zip
make Range#overlaps? accept Range of Time
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/range/overlaps.rb2
-rw-r--r--activesupport/test/core_ext/range_ext_test.rb12
2 files changed, 13 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/range/overlaps.rb b/activesupport/lib/active_support/core_ext/range/overlaps.rb
index 7df653b53f..603657c180 100644
--- a/activesupport/lib/active_support/core_ext/range/overlaps.rb
+++ b/activesupport/lib/active_support/core_ext/range/overlaps.rb
@@ -3,6 +3,6 @@ class Range
# (1..5).overlaps?(4..6) # => true
# (1..5).overlaps?(7..9) # => false
def overlaps?(other)
- include?(other.first) || other.include?(first)
+ cover?(other.first) || other.cover?(first)
end
end
diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb
index 8a91f6d69c..cf1ec448c2 100644
--- a/activesupport/test/core_ext/range_ext_test.rb
+++ b/activesupport/test/core_ext/range_ext_test.rb
@@ -71,4 +71,16 @@ class RangeTest < ActiveSupport::TestCase
range = (1..3)
assert range.method(:include?) != range.method(:cover?)
end
+
+ def test_overlaps_on_time
+ time_range_1 = Time.utc(2005, 12, 10, 15, 30)..Time.utc(2005, 12, 10, 17, 30)
+ time_range_2 = Time.utc(2005, 12, 10, 17, 00)..Time.utc(2005, 12, 10, 18, 00)
+ assert time_range_1.overlaps?(time_range_2)
+ end
+
+ def test_no_overlaps_on_time
+ time_range_1 = Time.utc(2005, 12, 10, 15, 30)..Time.utc(2005, 12, 10, 17, 30)
+ time_range_2 = Time.utc(2005, 12, 10, 17, 31)..Time.utc(2005, 12, 10, 18, 00)
+ assert !time_range_1.overlaps?(time_range_2)
+ end
end