コード例 #1
0
 /**
  * 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 3 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 = Month::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 4, 15, 25, 10, Duration::withHours(-4)), Duration::withDays(10));
     $timespanB = Month::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 10, 12, 0, 0, Duration::withHours(-4)), Duration::withDays(1));
     $timespanC = Month::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 20), DateAndTime::withYearMonthDay(2005, 5, 29));
     $timespanD = Month::startingEnding(DateAndTime::withYearMonthDay(2005, 6, 1), DateAndTime::withYearMonthDay(2005, 6, 6));
     // intersection()
     $this->assertTrue($timespanA->isEqualTo($timespanA->intersection($timespanB)));
     $this->assertTrue($timespanA->isEqualTo($timespanA->intersection($timespanC)));
     $this->assertEqual($timespanA->intersection($timespanD), NULL);
     // union()
     $temp = Timespan::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 1), DateAndTime::withYearMonthDay(2005, 6, 1));
     $this->assertTrue($temp->isEqualTo($timespanA->union($timespanB)));
     $temp = Timespan::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 1), DateAndTime::withYearMonthDay(2005, 6, 1));
     $this->assertTrue($temp->isEqualTo($timespanA->union($timespanC)));
     $temp = Timespan::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 1), DateAndTime::withYearMonthDay(2005, 7, 1));
     $this->assertTrue($temp->isEqualTo($timespanA->union($timespanD)));
 }