/** * 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 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 // // A |- - - - - - - - - -| // B |-| // C |- - - - - - - - -| // D |- - - -| $timespanA = Week::startingDuration(DateAndTime::withYearMonthDay(2005, 5, 4), Duration::withDays(10)); $timespanB = Week::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 10, 12, 0, 0, Duration::withHours(-4)), Duration::withDays(1)); $timespanC = Week::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 8), DateAndTime::withYearMonthDay(2005, 5, 17)); $timespanD = Week::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 17), DateAndTime::withYearMonthDay(2005, 5, 21)); // intersection() $this->assertEqual($timespanA->intersection($timespanB), NULL); $this->assertEqual($timespanA->intersection($timespanC), NULL); $this->assertEqual($timespanA->intersection($timespanD), NULL); // union() $temp = Timespan::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 1), DateAndTime::withYearMonthDay(2005, 5, 15)); $this->assertTrue($temp->isEqualTo($timespanA->union($timespanB))); $temp = Timespan::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 1), DateAndTime::withYearMonthDay(2005, 5, 15)); $this->assertTrue($temp->isEqualTo($timespanA->union($timespanC))); $temp = Timespan::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 1), DateAndTime::withYearMonthDay(2005, 5, 22)); $this->assertTrue($temp->isEqualTo($timespanA->union($timespanD))); }