Пример #1
0
 public function resolve(FieldValues $fieldValues, TemporalAccessor $partialTemporal, ResolverStyle $resolverStyle)
 {
     $value = $fieldValues->get($this);
     $newValue = Math::toIntExact($value);
     // broad limit makes overflow checking lighter
     // first convert localized day-of-week to ISO day-of-week
     // doing this first handles case where both ISO and localized were parsed and might mismatch
     // day-of-week is always strict as two different day-of-week values makes lenient complex
     if ($this->rangeUnit == ChronoUnit::WEEKS()) {
         // day-of-week
         $checkedValue = $this->range->checkValidIntValue($value, $this);
         // no leniency as too complex
         $startDow = $this->weekDef->getFirstDayOfWeek()->getValue();
         $isoDow = Math::floorMod($startDow - 1 + ($checkedValue - 1), 7) + 1;
         $fieldValues->remove($this);
         $fieldValues->put(CF::DAY_OF_WEEK(), $isoDow);
         return null;
     }
     // can only build date if ISO day-of-week is present
     if (!$fieldValues->has(CF::DAY_OF_WEEK())) {
         return null;
     }
     $isoDow = CF::DAY_OF_WEEK()->checkValidIntValue($fieldValues->get(CF::DAY_OF_WEEK()));
     $dow = $this->localizedDayOfWeekNumerical($isoDow);
     // build date
     $chrono = AbstractChronology::from($partialTemporal);
     if ($fieldValues->has(CF::YEAR())) {
         $year = CF::YEAR()->checkValidIntValue($fieldValues->get(CF::YEAR()));
         // validate
         if ($this->rangeUnit == ChronoUnit::MONTHS() && $fieldValues->has(CF::MONTH_OF_YEAR())) {
             // week-of-month
             $month = $fieldValues->get(CF::MONTH_OF_YEAR());
             // not validated yet
             return $this->resolveWoM($fieldValues, $chrono, $year, $month, $newValue, $dow, $resolverStyle);
         }
         if ($this->rangeUnit == ChronoUnit::YEARS()) {
             // week-of-year
             return $this->resolveWoY($fieldValues, $chrono, $year, $newValue, $dow, $resolverStyle);
         }
     } else {
         if (($this->rangeUnit == IsoFields::WEEK_BASED_YEARS() || $this->rangeUnit == ChronoUnit::FOREVER()) && $fieldValues->has($this->weekDef->weekBasedYear) && $fieldValues->has($this->weekDef->weekOfWeekBasedYear)) {
             // week-of-week-based-year and year-of-week-based-year
             return $this->resolveWBY($fieldValues, $chrono, $dow, $resolverStyle);
         }
     }
     return null;
 }