示例#1
0
 /**
  * Compares this instant to the specified instant.
  * <p>
  * The comparison is based on the time-line position of the instants.
  * It is "consistent with equals", as defined by {@link Comparable}.
  *
  * @param Instant $otherInstant the other instant to compare to, not null
  * @return int the comparator value, negative if less, positive if greater
  * @throws NullPointerException if otherInstant is null
  */
 public function compareTo(Instant $otherInstant)
 {
     $cmp = Long::compare($this->seconds, $otherInstant->seconds);
     if ($cmp !== 0) {
         return $cmp;
     }
     return $this->nanos - $otherInstant->nanos;
 }
示例#2
0
 /**
  * Compares this {@code OffsetDateTime} to another date-time.
  * The comparison is based on the instant.
  *
  * @param $datetime1 OffsetDateTime the first date-time to compare, not null
  * @param $datetime2 OffsetDateTime the other date-time to compare to, not null
  * @return int the comparator value, negative if less, positive if greater
  */
 public static function compareInstant(OffsetDateTime $datetime1, OffsetDateTime $datetime2)
 {
     if ($datetime1->getOffset()->equals($datetime2->getOffset())) {
         return $datetime1->toLocalDateTime()->compareTo($datetime2->toLocalDateTime());
     }
     $cmp = Long::compare($datetime1->toEpochSecond(), $datetime2->toEpochSecond());
     if ($cmp === 0) {
         $cmp = $datetime1->toLocalTime()->getNano() - $datetime2->toLocalTime()->getNano();
     }
     return $cmp;
 }
示例#3
0
 /**
  * Compares this duration to the specified {@code Duration}.
  * <p>
  * The comparison is based on the total length of the durations.
  * It is "consistent with equals", as defined by {@link Comparable}.
  *
  * @param Duration $otherDuration the other duration to compare to, not null
  * @return int the comparator value, negative if less, positive if greater
  */
 public function compareTo(Duration $otherDuration)
 {
     $cmp = Long::compare($this->seconds, $otherDuration->seconds);
     if ($cmp !== 0) {
         return $cmp;
     }
     return $this->nanos - $otherDuration->nanos;
 }
 public function compareTo(MockSimplePeriod $otherPeriod)
 {
     if ($this->unit->equals($otherPeriod->getUnit()) == false) {
         throw new IllegalArgumentException("Units cannot be compared: " . $this->unit . " and " . $otherPeriod->getUnit());
     }
     return Long::compare($this->amount, $otherPeriod->amount);
 }
 /**
  * @inheritdoc
  */
 public function compareTo(ChronoLocalDate $other)
 {
     $cmp = Long::compare($this->toEpochDay(), $other->toEpochDay());
     if ($cmp === 0) {
         $cmp = $this->getChronology()->compareTo($other->getChronology());
     }
     return $cmp;
 }
 /**
  * @inheritdoc
  */
 public function compareTo(ChronoZonedDateTime $other)
 {
     $cmp = Long::compare($this->toEpochSecond(), $other->toEpochSecond());
     if ($cmp === 0) {
         $cmp = $this->toLocalTime()->getNano() - $other->toLocalTime()->getNano();
         if ($cmp === 0) {
             $cmp = $this->toLocalDateTime()->compareTo($other->toLocalDateTime());
             if ($cmp === 0) {
                 $cmp = $this->getZone()->getId() === $other->getZone()->getId();
                 if ($cmp) {
                     $cmp = $this->getChronology()->compareTo($other->getChronology());
                 }
             }
         }
     }
     return $cmp;
 }
示例#7
0
 /**
  * Compares this {@code OffsetTime} to another time.
  * <p>
  * The comparison is based first on the UTC equivalent instant, then on the local time.
  * It is "consistent with equals", as defined by {@link Comparable}.
  * <p>
  * For example, the following is the comparator order:
  * <ol>
  * <li>{@code 10:30+01:00}</li>
  * <li>{@code 11:00+01:00}</li>
  * <li>{@code 12:00+02:00}</li>
  * <li>{@code 11:30+01:00}</li>
  * <li>{@code 12:00+01:00}</li>
  * <li>{@code 12:30+01:00}</li>
  * </ol>
  * Values #2 and #3 represent the same instant on the time-line.
  * When two values represent the same instant, the local time is compared
  * to distinguish them. This step is needed to make the ordering
  * consistent with {@code equals()}.
  * <p>
  * To compare the underlying local time of two {@code TemporalAccessor} instances,
  * use {@link ChronoField#NANO_OF_DAY} as a comparator.
  *
  * @param OffsetTime $other the other time to compare to, not null
  * @return int the comparator value, negative if less, positive if greater
  * @throws NullPointerException if {@code other} is null
  */
 public function compareTo(OffsetTime $other)
 {
     if ($this->offset->equals($other->offset)) {
         return $this->time->compareTo($other->time);
     }
     $compare = Long::compare($this->toEpochNano(), $other->toEpochNano());
     if ($compare == 0) {
         $compare = $this->time->compareTo($other->time);
     }
     return $compare;
 }