Пример #1
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;
 }
Пример #2
0
 public function isSupportedBy(TemporalAccessor $temporal)
 {
     return $temporal->isSupported($this);
 }
 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));
     }
 }
Пример #4
0
 public function isSupportedBy(TemporalAccessor $temporal)
 {
     return $temporal->isSupported(ChronoField::EPOCH_DAY()) && IsoFields::isIso($temporal);
 }
 private static function adjust(TemporalAccessor $temporal, DateTimeFormatter $formatter)
 {
     // normal case first (early return is an optimization)
     $overrideChrono = $formatter->getChronology();
     $overrideZone = $formatter->getZone();
     if ($overrideChrono == null && $overrideZone == null) {
         return $temporal;
     }
     // ensure minimal change (early return is an optimization)
     $temporalChrono = $temporal->query(TemporalQueries::chronology());
     $temporalZone = $temporal->query(TemporalQueries::zoneId());
     if ($temporalChrono !== null && $temporalChrono->equals($overrideChrono)) {
         $overrideChrono = null;
     }
     if ($temporalZone !== null && $temporalZone->equals($overrideZone)) {
         $overrideZone = null;
     }
     if ($overrideChrono === null && $overrideZone === null) {
         return $temporal;
     }
     // make adjustment
     $effectiveChrono = $overrideChrono != null ? $overrideChrono : $temporalChrono;
     if ($overrideZone != null) {
         // if have zone and instant, calculation is simple, defaulting chrono if necessary
         if ($temporal->isSupported(ChronoField::INSTANT_SECONDS())) {
             $chrono = $effectiveChrono != null ? $effectiveChrono : IsoChronology::INSTANCE();
             return $chrono->zonedDateTime(Instant::from($temporal), $overrideZone);
         }
         // block changing zone on OffsetTime, and similar problem cases
         if ($overrideZone->normalized() instanceof ZoneOffset && $temporal->isSupported(ChronoField::OFFSET_SECONDS()) && $temporal->get(ChronoField::OFFSET_SECONDS()) != $overrideZone->getRules()->getOffset(Instant::EPOCH())->getTotalSeconds()) {
             throw new DateTimeException("Unable to apply override zone '" . $overrideZone . "' because the temporal object being formatted has a different offset but" . " does not represent an instant: " . $temporal);
         }
     }
     $effectiveZone = $overrideZone !== null ? $overrideZone : $temporalZone;
     $effectiveDate = null;
     if ($overrideChrono !== null) {
         if ($temporal->isSupported(ChronoField::EPOCH_DAY())) {
             $effectiveDate = $effectiveChrono->dateFrom($temporal);
         } else {
             // check for date fields other than epoch-day, ignoring case of converting null to ISO
             if (!($overrideChrono == IsoChronology::INSTANCE() && $temporalChrono === null)) {
                 foreach (ChronoField::values() as $f) {
                     if ($f->isDateBased() && $temporal->isSupported($f)) {
                         throw new DateTimeException("Unable to apply override chronology '" . $overrideChrono . "' because the temporal object being formatted contains date fields but" . " does not represent a whole date: " . $temporal);
                     }
                 }
             }
             $effectiveDate = null;
         }
     } else {
         $effectiveDate = null;
     }
     // combine available data
     // this is a non-standard temporal that is almost a pure delegate
     // this better handles map-like underlying temporal instances
     return new Test($effectiveDate, $temporal, $effectiveZone, $effectiveChrono);
 }
Пример #6
0
 public function isSupportedBy(TemporalAccessor $temporal)
 {
     return $temporal->isSupported(ChronoField::DAY_OF_YEAR()) && $temporal->isSupported(ChronoField::MONTH_OF_YEAR()) && $temporal->isSupported(ChronoField::YEAR()) && IsoFields::isIso($temporal);
 }
Пример #7
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);
         }
     }
 }
Пример #8
0
 public function isSupportedBy(TemporalAccessor $temporal)
 {
     return $temporal->isSupported(ChronoField::EPOCH_DAY()) && AbstractChronology::from($temporal)->equals(IsoChronology::INSTANCE());
 }
Пример #9
0
 /**
  * Map the field range to a week range of a week year.
  * @param TemporalAccessor $temporal the temporal
  * @return ValueRange the ValueRange with the range adjusted to weeks.
  */
 private function rangeWeekOfWeekBasedYear(TemporalAccessor $temporal)
 {
     if (!$temporal->isSupported(CF::DAY_OF_YEAR())) {
         return self::WEEK_OF_YEAR_RANGE();
     }
     $dow = $this->localizedDayOfWeek($temporal);
     $doy = $temporal->get(CF::DAY_OF_YEAR());
     $offset = $this->startOfWeekOffset($doy, $dow);
     $week = $this->computeWeek($offset, $doy);
     if ($week === 0) {
         // Day is in end of week of previous year
         // Recompute from the last day of the previous year
         $date = AbstractChronology::from($temporal)->dateFrom($temporal);
         $date = $date->minus($doy + 7, ChronoUnit::DAYS());
         // Back down into previous year
         return $this->rangeWeekOfWeekBasedYear($date);
     }
     // Check if day of year is in partial week associated with next year
     $dayRange = $temporal->range(CF::DAY_OF_YEAR());
     $yearLen = $dayRange->getMaximum();
     $newYearWeek = $this->computeWeek($offset, $yearLen + $this->weekDef->getMinimalDaysInFirstWeek());
     if ($week >= $newYearWeek) {
         // Overlaps with weeks of following year; recompute from a week in following year
         $date = AbstractChronology::from($temporal)->dateFrom($temporal);
         $date = $date->plus($yearLen - $doy + 1 + 7, ChronoUnit::DAYS());
         return $this->rangeWeekOfWeekBasedYear($date);
     }
     return ValueRange::of(1, $newYearWeek - 1);
 }
 /**
  * @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()));
 }
Пример #11
0
 public function isSupportedBy(TemporalAccessor $temporal)
 {
     return $temporal->isSupported(CF::EPOCH_DAY());
 }