/**
  * A query for {@code ZoneOffset} returning null if not found.
  * @param TemporalAccessor $temporal
  * @return null|ZoneOffset
  * @throws DateTimeException
  */
 public static function _offset(TemporalAccessor $temporal)
 {
     if ($temporal->isSupported(ChronoField::OFFSET_SECONDS())) {
         return ZoneOffset::ofTotalSeconds($temporal->get(ChronoField::OFFSET_SECONDS()));
     }
     return null;
 }
Example #2
0
 /**
  * Obtains an instance of {@code DayOfWeek} from a temporal object.
  * <p>
  * This obtains a day-of-week 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 DayOfWeek}.
  * <p>
  * The conversion extracts the {@link ChronoField#DAY_OF_WEEK DAY_OF_WEEK} 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 DayOfWeek::from}.
  *
  * @param TemporalAccessor $temporal the temporal object to convert, not null
  * @return DayOfWeek the day-of-week, not null
  * @throws DateTimeException if unable to convert to a {@code DayOfWeek}
  */
 public static function from(TemporalAccessor $temporal)
 {
     if ($temporal instanceof DayOfWeek) {
         return $temporal;
     }
     try {
         return self::of($temporal->get(ChronoField::DAY_OF_WEEK()));
     } catch (DateTimeException $ex) {
         throw new DateTimeException("Unable to obtain DayOfWeek from TemporalAccessor: " . $temporal . " of type " . get_class($temporal), $ex);
     }
 }
Example #3
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);
     }
 }
 private function localizedDayOfWeek(TemporalAccessor $temporal)
 {
     $sow = $this->weekDef->getFirstDayOfWeek()->getValue();
     $isoDow = $temporal->get(CF::DAY_OF_WEEK());
     return Math::floorMod($isoDow - $sow, 7) + 1;
 }