Пример #1
0
 public function equals($obj)
 {
     if ($obj instanceof SystemClock) {
         return $this->zone->equals($obj->zone);
     }
     return false;
 }
Пример #2
0
 public function equals($obj)
 {
     if ($obj instanceof FixedClock) {
         return $this->instant->equals($obj->instant) && $this->zone->equals($obj->zone);
     }
     return false;
 }
Пример #3
0
 public function withZone(ZoneId $zone)
 {
     if ($zone->equals($this->baseClock->getZone())) {
         // intentional NPE
         return $this;
     }
     return new TickClock($this->baseClock->withZone($zone), $this->tickNanos);
 }
Пример #4
0
 public function withZone(ZoneId $zone)
 {
     if ($zone->equals($this->baseClock->getZone())) {
         // intentional NPE
         return $this;
     }
     return new OffsetClock($this->baseClock->withZone($zone), $this->offset);
 }
Пример #5
0
 private function resolveFields()
 {
     // resolve CF
     $this->resolveInstantFields();
     $this->resolveDateFields();
     $this->resolveTimeFields();
     // if any other fields, handle them
     // any lenient date resolution should return epoch-day
     if (!$this->fieldValues->isEmpty()) {
         $changedCount = 0;
         outer:
         while ($changedCount < 50) {
             foreach ($this->fieldValues as $targetField => $value) {
                 /** @var CF $targetField */
                 $resolvedObject = $targetField->resolve($this->fieldValues, $this, $this->resolverStyle);
                 if ($resolvedObject !== null) {
                     if ($resolvedObject instanceof ChronoZonedDateTime) {
                         $czdt = $resolvedObject;
                         if ($this->zone === null) {
                             $this->zone = $czdt->getZone();
                         } else {
                             if ($this->zone->equals($czdt->getZone()) == false) {
                                 throw new DateTimeException("ChronoZonedDateTime must use the effective parsed zone: " . $this->zone);
                             }
                         }
                         $resolvedObject = $czdt->toLocalDateTime();
                     }
                     if ($resolvedObject instanceof ChronoLocalDateTime) {
                         $cldt = $resolvedObject;
                         $this->updateCheckConflict($cldt->toLocalTime(), Period::ZERO());
                         $this->updateCheckConflict1($cldt->toLocalDate());
                         $changedCount++;
                         continue 2;
                         // have to restart to avoid concurrent modification
                     }
                     if ($resolvedObject instanceof ChronoLocalDate) {
                         $this->updateCheckConflict1($resolvedObject);
                         $changedCount++;
                         continue 2;
                         // have to restart to avoid concurrent modification
                     }
                     if ($resolvedObject instanceof LocalTime) {
                         $this->updateCheckConflict($resolvedObject, Period::ZERO());
                         $changedCount++;
                         continue 2;
                         // have to restart to avoid concurrent modification
                     }
                     throw new DateTimeException("Method resolve() can only return ChronoZonedDateTime, " . "ChronoLocalDateTime, ChronoLocalDate or LocalTime");
                 } else {
                     if ($this->fieldValues->has($targetField) === false) {
                         $changedCount++;
                         continue 2;
                         // have to restart to avoid concurrent modification
                     }
                 }
             }
             break;
         }
         if ($changedCount === 50) {
             // catch infinite loops
             throw new DateTimeException("One of the parsed fields has an incorrectly implemented resolve method");
         }
         // if something changed then have to redo CF resolve
         if ($changedCount > 0) {
             $this->resolveInstantFields();
             $this->resolveDateFields();
             $this->resolveTimeFields();
         }
     }
 }
 public function withZoneSameInstant(ZoneId $zone)
 {
     return $this->zone->equals($zone) ? $this : $this->create($this->dateTime->toInstant($this->offset), $zone);
 }
Пример #7
0
 /**
  * Checks if this date-time is equal to another date-time.
  * <p>
  * The comparison is based on the offset date-time and the zone.
  * Only objects of type {@code ZonedDateTime} are compared, other types return false.
  *
  * @param mixed $obj the object to check, null returns false
  * @return bool true if this is equal to the other date-time
  */
 public function equals($obj)
 {
     if ($this === $obj) {
         return true;
     }
     if ($obj instanceof ZonedDateTime) {
         $other = $obj;
         return $this->dateTime->equals($other->dateTime) && $this->offset->equals($other->offset) && $this->zone->equals($other->zone);
     }
     return false;
 }