FWIW, people working with temporal logics and event algebras define 13
possible relationships between two intervals (see Fig. 4 page 10 of
[1]), with a precise (if not always intuitive) vocabulary.
In Ruby, these would be (not tested):
class Range
self: |—|
other: |—|
def before?(other)
self.end < other.begin
end
self: |—|
other: |—|
def after?(other)
other.before? self
end
self: |—|
other: |—|
def meets?(other)
self.end == other.begin
end
self: |—|
other: |—|
def met_by?(other)
other.meets?(self)
end
self: |—|
other: |—|
def overlaps?(other)
(self.begin < other.begin) and other.include?(self.end)
end
self: |—|
other: |—|
def overlapped_by?(other)
other.overlaps?(self)
end
self: |-----|
other: |—|
def finished_by?(other)
(self.begin < other.begin) and (self.end == other.end)
end
self: |-----|
other: |—|
def started_by?(other)
(self.begin == other.begin) and (self.end > other.end)
end
self: |—|
other: |-----|
def starts?(other)
other.started_by?(self)
end
self: |—|
other: |-----|
def finishes?(other)
other.finished_by?(self)
end
self: |-------|
other: |—|
def contains?(other)
(self.begin < other.begin) and (self.end > other.end)
end
self: |—|
other: |—|
def equals?(other)
(self.begin == other.begin) and (self.end == other.end)
end
self: |—|
other: |-------|
def during?(other)
other.contains?(self)
end
end
[1] Allen, J.F. and Ferguson, G. Actions and Events in Interval
Temporal Logic, J. Logic and Computation 4, 5, 1994.
http://tinyurl.com/2twek7