Module: DateRange
- Included in:
- Month, Quarter, SimpleRange, Week
- Defined in:
- lib/funtimes/date_range.rb
Instance Method Summary collapse
- #&(other) ⇒ Object
- #days ⇒ Object
- #encompasses(other) ⇒ Object
- #intersects(other) ⇒ Object
- #months ⇒ Object
- #number_of_days_in(other) ⇒ Object
- #quarters ⇒ Object
- #same_range_as(other) ⇒ Object
- #weeks ⇒ Object
- #|(other) ⇒ Object
Instance Method Details
#&(other) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/funtimes/date_range.rb', line 28 def & (other) return [] unless intersects other return other if encompasses(other) return self if other.encompasses(self) return SimpleRange.new(other.start_date, _end) if overlaps_left_side(other) SimpleRange.new(_start, other.end_date) end |
#days ⇒ Object
2 3 4 |
# File 'lib/funtimes/date_range.rb', line 2 def days (_start)..(_end) end |
#encompasses(other) ⇒ Object
20 21 22 |
# File 'lib/funtimes/date_range.rb', line 20 def encompasses(other) _start <= other.start_date && _end >= other.end_date end |
#intersects(other) ⇒ Object
24 25 26 |
# File 'lib/funtimes/date_range.rb', line 24 def intersects(other) other.encompasses(self) || encompasses(other) || overlaps(other) end |
#months ⇒ Object
6 7 8 9 |
# File 'lib/funtimes/date_range.rb', line 6 def months return [] unless _start && _end (Month.from(_start)..Month.from(_end)) end |
#number_of_days_in(other) ⇒ Object
47 48 49 50 51 |
# File 'lib/funtimes/date_range.rb', line 47 def number_of_days_in(other) intersection = (self & other) return 0 if intersection == [] intersection.days.to_a.length end |
#quarters ⇒ Object
11 12 13 14 |
# File 'lib/funtimes/date_range.rb', line 11 def quarters return [] unless _start && _end (Quarter.from(_start)..Quarter.from(_end)) end |
#same_range_as(other) ⇒ Object
43 44 45 |
# File 'lib/funtimes/date_range.rb', line 43 def same_range_as(other) other.start_date == _start && other.end_date == _end end |
#weeks ⇒ Object
16 17 18 |
# File 'lib/funtimes/date_range.rb', line 16 def weeks (Week.new(_start)..Week.new(_end)) end |
#|(other) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/funtimes/date_range.rb', line 36 def | (other) return [] unless intersects other return self if encompasses(other) return other if other.encompasses(self) SimpleRange.new([_start,other.start_date].min, [_end,other.end_date].max) end |