/** * Whether or not the date ranges overlap. Dates that start or end on boundaries are excluded * @param DateRange $dateRange * @return bool */ public function Overlaps(DateRange $dateRange) { return ($this->Contains($dateRange->GetBegin()) || $this->Contains($dateRange->GetEnd()) || $dateRange->Contains($this->GetBegin()) || $dateRange->Contains($this->GetEnd())) && (!$this->GetBegin()->Equals($dateRange->GetEnd()) && !$this->GetEnd()->Equals($dateRange->GetBegin())); }
public function testDateIsWithinRange() { $begin = Date::Create(2008, 9, 9, 10, 11, 12, 'UTC'); $end = Date::Create(2008, 10, 9, 10, 11, 12, 'UTC'); $range = new DateRange($begin, $end); $within = $begin->AddDays(10); $notWithin = $begin->AddDays(-10); $exactStart = $begin; $exactEnd = $end; $this->assertTrue($range->Contains($within)); $this->assertTrue($range->Contains($exactStart)); $this->assertTrue($range->Contains($exactEnd)); $this->assertFalse($range->Contains($notWithin)); }