private function compareTo0(LocalDateTime $other) { $cmp = $this->date->compareTo0($other->toLocalDate()); if ($cmp == 0) { $cmp = $this->time->compareTo($other->toLocalTime()); } return $cmp; }
/** * 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; }