Beispiel #1
0
 /**
  * Casts an DateTimeRange object into DateRange.
  *
  * @param   DateTimeRange  $range  A DateTimeRange object
  *
  * @return  DateRange
  *
  * @since   2.0.0
  */
 private static function cast(DateTimeRange $range)
 {
     $start = new Date($range->start());
     $end = new Date($range->end());
     return new DateRange($start, $end);
 }
Beispiel #2
0
 /**
  * Compares two objects.
  *
  * @param   DateTimeRange  $a  Base object.
  * @param   DateTimeRange  $b  Object to compare to.
  *
  * @return  integer
  *
  * @since   2.0.0
  * @throws  \InvalidArgumentException
  */
 private static function compare(DateTimeRange $a, DateTimeRange $b)
 {
     if (!$a->interval->equals($b->interval)) {
         throw new \InvalidArgumentException('Intervals of ranges are not equal.');
     }
     if ($a->equals($b)) {
         return 0;
     }
     if ($a->start()->isAfter($b->start())) {
         return 1;
     }
     if ($a->start()->isBefore($b->start()) || $a->end()->isBefore($b->end())) {
         return -1;
     }
     return 1;
 }