Пример #1
0
 public function getFrom(TemporalAccessor $temporal)
 {
     return $temporal->getLong($this);
 }
Пример #2
0
 /**
  * Obtains an instance of {@code Instant} from a temporal object.
  * <p>
  * This obtains an instant based on the specified temporal.
  * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
  * which this factory converts to an instance of {@code Instant}.
  * <p>
  * The conversion extracts the {@link ChronoField#INSTANT_SECONDS INSTANT_SECONDS}
  * and {@link ChronoField#NANO_OF_SECOND NANO_OF_SECOND} fields.
  * <p>
  * This method matches the signature of the functional interface {@link TemporalQuery}
  * allowing it to be used as a query via method reference, {@code Instant::from}.
  *
  * @param TemporalAccessor $temporal the temporal object to convert, not null
  * @return Instant the instant, not null
  * @throws DateTimeException if unable to convert to an Instant {@code Instant}
  */
 public static function from(TemporalAccessor $temporal)
 {
     if ($temporal instanceof Instant) {
         return $temporal;
     }
     try {
         $instantSecs = $temporal->getLong(ChronoField::INSTANT_SECONDS());
         $nanoOfSecond = $temporal->get(ChronoField::NANO_OF_SECOND());
         return Instant::ofEpochSecond($instantSecs, $nanoOfSecond);
     } catch (DateTimeException $ex) {
         throw new DateTimeException("Unable to obtain Instant from TemporalAccessor: " . $temporal . " of type " . get_class($temporal), $ex);
     }
 }
Пример #3
0
 /**
  * A query for {@code LocalTime} returning null if not found.
  * @param TemporalAccessor $temporal
  * @return null|LocalTime
  */
 public static function _localTime(TemporalAccessor $temporal)
 {
     if ($temporal->isSupported(ChronoField::NANO_OF_DAY())) {
         return LocalTime::ofNanoOfDay($temporal->getLong(ChronoField::NANO_OF_DAY()));
     }
     return null;
 }
 private function assertParsed(TemporalAccessor $parsed, TemporalField $field, $value)
 {
     if ($value === null) {
         $this->assertEquals(false, $parsed->isSupported($field));
     } else {
         $this->assertEquals(true, $parsed->isSupported($field));
         $this->assertEquals($value, $parsed->getLong($field));
     }
 }
 /**
  * Gets the value of the specified field.
  * <p>
  * This will return the value for the specified field.
  *
  * @param TemporalField $field the field to find, not null
  * @return int the value, null if not found and optional is true
  * @throws DateTimeException if the field is not available and the section is not optional
  */
 public function getValueField(TemporalField $field)
 {
     try {
         return $this->temporal->getLong($field);
     } catch (DateTimeException $ex) {
         if ($this->optional > 0) {
             return null;
         }
         throw $ex;
     }
 }
Пример #6
0
 private function crossCheck1(TemporalAccessor $target)
 {
     foreach ($this->fieldValues as $field => $entry) {
         /** @var CF $field */
         if ($target->isSupported($field)) {
             try {
                 $val1 = $target->getLong($field);
             } catch (\RuntimeException $ex) {
                 continue;
             }
             $val2 = $entry;
             if ($val1 !== $val2) {
                 throw new DateTimeException("Conflict found: Field " . $field . " " . $val1 . " differs from " . $field . " " . $val2 . " derived from " . $target);
             }
             $this->fieldValues->remove($field);
         }
     }
 }
 /**
  * @param TemporalAccessor $parsed
  * @param Expected $expected
  */
 private function assertParseMatch($parsed, $expected)
 {
     foreach ($expected->fieldValues as $field => $val) {
         $this->assertEquals($parsed->isSupported($field), true);
         $parsed->getLong($field);
     }
     $this->assertEquals($expected->chrono, $parsed->query(TemporalQueries::chronology()));
     $this->assertEquals($expected->zone, $parsed->query(TemporalQueries::zoneId()));
 }
Пример #8
0
 public function getFrom(TemporalAccessor $temporal)
 {
     return $temporal->getLong(CF::EPOCH_DAY()) + $this->offset;
 }