/** * Test aritmatic operations * */ function test_intersect_union() { // intersection() // union() // 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 ... 0 0 0 0 // 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 ... 1 2 3 4 // // A |- - - - - - - - - -| // B |-| // C |- - - - - - - - -| // D ...|- - - -| $timespanA = Year::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 4, 15, 25, 10, Duration::withHours(-4)), Duration::withDays(10)); $timespanB = Year::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 10, 12, 0, 0, Duration::withHours(-4)), Duration::withDays(1)); $timespanC = Year::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 20), DateAndTime::withYearMonthDay(2005, 5, 29)); $timespanD = Year::startingEnding(DateAndTime::withYearMonthDay(2006, 6, 1), DateAndTime::withYearMonthDay(2005, 6, 6)); // intersection() $this->assertTrue($timespanB->isEqualTo($timespanA->intersection($timespanB))); $this->assertTrue($timespanC->isEqualTo($timespanA->intersection($timespanC))); $this->assertEqual($timespanA->intersection($timespanD), NULL); // union() $temp = Timespan::startingDuration(DateAndTime::withYearMonthDay(2005, 5, 4), Duration::withDays(371)); $union = $timespanA->union($timespanB); $this->assertTrue($temp->isEqualTo($union)); $unionDuration = $union->duration(); $this->assertEqual($unionDuration->days(), 371); $temp = Timespan::startingDuration(DateAndTime::withYearMonthDay(2005, 5, 4), Duration::withDays(381)); $this->assertTrue($temp->isEqualTo($timespanA->union($timespanC))); $temp = Timespan::startingDuration(DateAndTime::withYearMonthDay(2005, 5, 4), Duration::withDays(758)); $this->assertTrue($temp->isEqualTo($timespanA->union($timespanD))); }