/**
  * @inheritdoc
  */
 public function isSupportedBy(Temporal $temporal)
 {
     if ($temporal instanceof LocalTime) {
         return $this->isTimeBased();
     }
     if ($temporal instanceof ChronoLocalDate) {
         return $this->isDateBased();
     }
     if ($temporal instanceof ChronoLocalDateTime || $temporal instanceof ChronoZonedDateTime) {
         return true;
     }
     try {
         $temporal->plus(1, $this);
         return true;
     } catch (UnsupportedTemporalTypeException $ex) {
         return false;
     } catch (\RuntimeException $ex) {
         try {
             $temporal->plus(-1, $this);
             return true;
         } catch (\RuntimeException $ex2) {
             return false;
         }
     }
 }
 public function adjustInto(Temporal $temporal, $newValue)
 {
     // calls getFrom() to check if supported
     $this->range()->checkValidValue($newValue, $this);
     // lenient range
     return $temporal->plus(Math::subtractExact($newValue, $this->getFrom($temporal)), ChronoUnit::WEEKS());
 }
Example #3
0
 public function addTo(Temporal $temporal, $amount)
 {
     switch ($this) {
         case IsoFields::WEEK_BASED_YEARS():
             return $temporal->with(IsoFields::WEEK_BASED_YEAR(), Math::addExact($temporal->get(IsoFields::WEEK_BASED_YEAR()), $amount));
         case IsoFields::QUARTER_YEARS():
             // no overflow (256 is multiple of 4)
             return $temporal->plus($amount / 256, ChronoUnit::YEARS())->plus($amount % 256 * 3, ChronoUnit::MONTHS());
         default:
             throw new IllegalStateException("Unreachable");
     }
 }
Example #4
0
 public function addTo(Temporal $temporal, $amount)
 {
     return $temporal->plus($amount, $this);
 }
 public function addTo(Temporal $temporal)
 {
     return $temporal->plus($this->amount, $this->unit);
 }