/**
  * @inheritdoc
  */
 public static function from(TemporalAccessor $temporal)
 {
     if ($temporal instanceof ChronoLocalDate) {
         return $temporal;
     }
     $chrono = $temporal->query(TemporalQueries::chronology());
     if ($chrono === null) {
         throw new DateTimeException("Unable to obtain ChronoLocalDate from TemporalAccessor: " . get_class($temporal));
     }
     return $chrono->date($temporal);
 }
 /**
  * @inheritdoc
  */
 public static function from(TemporalAccessor $temporal)
 {
     if ($temporal instanceof ChronoZonedDateTime) {
         return $temporal;
     }
     /** @var Chronology $chrono */
     $chrono = $temporal->query(TemporalQueries::chronology());
     if ($chrono === null) {
         throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " . get_class($temporal));
     }
     return $chrono->zonedDateTimeFrom($temporal);
 }
Пример #3
0
 /**
  * @dataProvider data_query
  */
 public function test_query(TemporalAccessor $temporal, TemporalQuery $query, $expected)
 {
     $this->assertEquals($temporal->query($query), $expected);
 }
Пример #4
0
 /**
  * Obtains an instance of {@code LocalTime} from a temporal object.
  * <p>
  * This obtains a local time 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 LocalTime}.
  * <p>
  * The conversion uses the {@link TemporalQueries#localTime()} query, which relies
  * on extracting the {@link ChronoField#NANO_OF_DAY NANO_OF_DAY} field.
  * <p>
  * This method matches the signature of the functional interface {@link TemporalQuery}
  * allowing it to be used as a query via method reference, {@code self::from}.
  *
  * @param TemporalAccessor $temporal the temporal object to convert, not null
  * @return LocalTime the local time, not null
  * @throws DateTimeException if unable to convert to a {@code LocalTime}
  */
 public static function from(TemporalAccessor $temporal)
 {
     $time = $temporal->query(TemporalQueries::localTime());
     if ($time === null) {
         throw new DateTimeException("Unable to obtain LocalTime from TemporalAccessor: " . $temporal . " of type " . get_class($temporal));
     }
     return $time;
 }
Пример #5
0
 /**
  * A lenient query for the {@code ZoneId}, falling back to the {@code ZoneOffset}.
  * @param TemporalAccessor $temporal
  * @return ZoneId|ZoneOffset|null
  */
 public static function _zone(TemporalAccessor $temporal)
 {
     $zone = $temporal->query(TemporalQueries::$ZONE_ID);
     return $zone !== null ? $zone : $temporal->query(TemporalQueries::$OFFSET);
 }
Пример #6
0
 public static function from(TemporalAccessor $temporal)
 {
     $obj = $temporal->query(TemporalQueries::chronology());
     return $obj !== null ? $obj : IsoChronology::INSTANCE();
 }
Пример #7
0
 /**
  * Obtains an instance of {@code ZoneId} from a temporal object.
  * <p>
  * This obtains a zone 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 ZoneId}.
  * <p>
  * A {@code TemporalAccessor} represents some form of date and time information.
  * This factory converts the arbitrary temporal object to an instance of {@code ZoneId}.
  * <p>
  * The conversion will try to obtain the zone in a way that favours region-based
  * zones over offset-based zones using {@link TemporalQueries#zone()}.
  * <p>
  * This method matches the signature of the functional interface {@link TemporalQuery}
  * allowing it to be used as a query via method reference, {@code ZoneId::from}.
  *
  * @param TemporalAccessor $temporal the temporal object to convert, not null
  * @return ZoneId the zone ID, not null
  * @throws DateTimeException if unable to convert to a {@code ZoneId}
  */
 public static function from(TemporalAccessor $temporal)
 {
     $obj = $temporal->query(TemporalQueries::zone());
     if ($obj == null) {
         throw new DateTimeException("Unable to obtain ZoneId from TemporalAccessor: " . $temporal . " of type " . get_class($temporal));
     }
     return $obj;
 }
 /**
  * Gets a value using a query.
  *
  * @param TemporalQuery $query the query to use, not null
  * @return mixed the result, null if not found and optional is true
  * @throws DateTimeException if the type is not available and the section is not optional
  */
 public function getValue(TemporalQuery $query)
 {
     $result = $this->temporal->query($query);
     if ($result == null && $this->optional == 0) {
         throw new DateTimeException("Unable to extract value: " . get_class($this->temporal));
     }
     return $result;
 }
 /**
  * @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()));
 }
Пример #10
0
 /**
  * Validates that the temporal has the correct chronology.
  */
 private function validateChrono(TemporalAccessor $temporal)
 {
     $temporalChrono = $temporal->query(TemporalQueries::chronology());
     if ($temporalChrono != null && IsoChronology::INSTANCE()->equals($temporalChrono) == false) {
         throw new DateTimeException("Chronology mismatch, expected: ISO, actual: " . $temporalChrono->getId());
     }
 }