Exemple #1
0
 /**
  * Class constructor.
  *
  * @param \Brick\DateTime\ReadableInstant $startInclusive The start instant, inclusive.
  * @param \Brick\DateTime\ReadableInstant $endExclusive   The end instant, exclusive.
  *
  * @throws \Brick\DateTime\DateTimeException
  */
 public function __construct(ReadableInstant $startInclusive, ReadableInstant $endExclusive)
 {
     if ($endExclusive->isBefore($startInclusive)) {
         throw new DateTimeException('The end instant must not be before the start instant.');
     }
     $this->start = $startInclusive;
     $this->end = $endExclusive;
 }
Exemple #2
0
 /**
  * Compares this instant with another.
  *
  * @param ReadableInstant $that
  *
  * @return integer [-1,0,1] If this instant is before, on, or after the given instant.
  */
 public function compareTo(ReadableInstant $that)
 {
     $seconds = $this->getEpochSecond() - $that->getEpochSecond();
     if ($seconds !== 0) {
         return $seconds > 0 ? 1 : -1;
     }
     $nanos = $this->getNano() - $that->getNano();
     if ($nanos !== 0) {
         return $nanos > 0 ? 1 : -1;
     }
     return 0;
 }