예제 #1
0
 protected function invalidFields()
 {
     $list = array_diff(ChronoField::values(), $this->validFields());
     $list[] = JulianFields::JULIAN_DAY();
     $list[] = JulianFields::MODIFIED_JULIAN_DAY();
     $list[] = JulianFields::RATA_DIE();
     return $list;
 }
예제 #2
0
 public function test_valueOf()
 {
     $this->markTestIncomplete('ChronoField::values');
     foreach (ChronoField::values() as $field) {
         $this->assertEquals(ChronoField::valueOf($field->name()), $field);
     }
 }
 protected function invalidFields()
 {
     return array_diff(CF::values(), $this->validFields());
 }
 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);
 }