Beispiel #1
0
 /**
  * @param DateTime $startDate
  * @param DateTime $endDate
  * @return TimeSpan
  */
 public static function asInterval(DateTime $startDate, DateTime $endDate)
 {
     $newThis = new TimeSpan();
     $newThis->checkStartEndDateAndSetInterval($startDate, $endDate);
     $newThis->setStartDate($startDate);
     $newThis->setEndDate($endDate);
     return $newThis;
 }
Beispiel #2
0
 /**
  * @param TimeSpan $timeSpan
  */
 private function assertTimeSpan(TimeSpan $timeSpan)
 {
     $this->assertEquals(new DateTime("2012-01-01"), $timeSpan->getStartDate());
     $this->assertEquals(new DateTime("2012-07-01"), $timeSpan->getEndDate());
     $this->assertEquals(0, $timeSpan->getYearsComponent());
     $this->assertEquals(6, $timeSpan->getMonthsComponent());
     $this->assertEquals(0, $timeSpan->getDaysComponent());
     $timeSpan->setEndDate(new DateTime("2012-06-01"));
     $this->assertEquals(new DateTime("2012-01-01"), $timeSpan->getStartDate());
     $this->assertEquals(new DateTime("2012-06-01"), $timeSpan->getEndDate());
     $this->assertEquals(0, $timeSpan->getYearsComponent());
     $this->assertEquals(5, $timeSpan->getMonthsComponent());
     $this->assertEquals(0, $timeSpan->getDaysComponent());
     $timeSpan->setEndDate(new DateTime("2013-01-01"));
     $this->assertEquals(new DateTime("2012-01-01"), $timeSpan->getStartDate());
     $this->assertEquals(new DateTime("2013-01-01"), $timeSpan->getEndDate());
     $this->assertEquals(1, $timeSpan->getYearsComponent());
     $this->assertEquals(0, $timeSpan->getMonthsComponent());
     $this->assertEquals(0, $timeSpan->getDaysComponent());
     $timeSpan->clearStartEndDate();
     $this->assertNull($timeSpan->getStartDate());
     $this->assertNull($timeSpan->getEndDate());
     $this->assertEquals(1, $timeSpan->getYearsComponent());
     $this->assertEquals(0, $timeSpan->getMonthsComponent());
     $this->assertEquals(0, $timeSpan->getDaysComponent());
     $timeSpan->setEndDate(new DateTime("2013-01-01"));
     $this->assertEquals(new DateTime("2012-01-01"), $timeSpan->getStartDate());
     $this->assertEquals(new DateTime("2013-01-01"), $timeSpan->getEndDate());
     $this->assertEquals(1, $timeSpan->getYearsComponent());
     $this->assertEquals(0, $timeSpan->getMonthsComponent());
     $this->assertEquals(0, $timeSpan->getDaysComponent());
     $timeSpan->setStartDate(new DateTime("2012-01-01"));
     $this->assertEquals(new DateTime("2012-01-01"), $timeSpan->getStartDate());
     $this->assertEquals(new DateTime("2013-01-01"), $timeSpan->getEndDate());
     $this->assertEquals(1, $timeSpan->getYearsComponent());
     $this->assertEquals(0, $timeSpan->getMonthsComponent());
     $this->assertEquals(0, $timeSpan->getDaysComponent());
     $timeSpan->setStartDate(new DateTime("2012-01-02"));
     $this->assertEquals(new DateTime("2012-01-02"), $timeSpan->getStartDate());
     $this->assertEquals(new DateTime("2013-01-01"), $timeSpan->getEndDate());
     $this->assertEquals(1, $timeSpan->getYearsComponent());
     $this->assertEquals(0, $timeSpan->getMonthsComponent());
     $this->assertEquals(0, $timeSpan->getDaysComponent());
 }