class DateRange
Constants
- VERSION
Attributes
end_date[R]
start_date[R]
Public Class Methods
new(start_date, end_date)
click to toggle source
# File lib/date_range.rb, line 8 def initialize(start_date, end_date) @start_date = start_date @end_date = end_date end
Public Instance Methods
include?(other)
click to toggle source
# File lib/date_range.rb, line 13 def include?(other) if other.is_a?(DateRange) include?(other.start_date) && include?(other.end_date) else start_date <= other && end_date >= other end end
overlap(other)
click to toggle source
# File lib/date_range.rb, line 26 def overlap(other) return unless overlaps?(other) dates = [start_date, end_date, other.start_date, other.end_date].sort[1, 2] DateRange.new(*dates) end
overlaps?(other)
click to toggle source
# File lib/date_range.rb, line 21 def overlaps?(other) return unless other.is_a?(DateRange) other.include?(start_date) || other.include?(end_date) || include?(other) end