Ejemplo n.º 1
0
 public function adjustInto(Temporal $temporal, $newValue)
 {
     if ($this->isSupportedBy($temporal) === false) {
         throw new UnsupportedTemporalTypeException("Unsupported field: WeekBasedYear");
     }
     $newWby = $this->range()->checkValidIntValue($newValue, IsoFields::WEEK_BASED_YEAR());
     // strict check
     $date = LocalDate::from($temporal);
     $dow = $date->get(ChronoField::DAY_OF_WEEK());
     $week = IsoFields::getWeek($date);
     if ($week == 53 && IsoFields::getWeekRangeInt($newWby) == 52) {
         $week = 52;
     }
     $resolved = LocalDate::of($newWby, 1, 4);
     // 4th is guaranteed to be in week one
     $days = $dow - $resolved->get(ChronoField::DAY_OF_WEEK()) + ($week - 1) * 7;
     $resolved = $resolved->plusDays($days);
     return $temporal->adjust($resolved);
 }