public function adjustInto(Temporal $temporal, $newValue) { if ($this->range()->isValidValue($newValue) == false) { throw new DateTimeException("Invalid value: " . $this->name . " " . $newValue); } return $temporal->with(CF::EPOCH_DAY(), Math::subtractExact($newValue, $this->offset)); }
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"); } }
/** * Adjusts the specified temporal object to have the same offset, date * and time as this object. * <p> * This returns a temporal object of the same observable type as the input * with the offset, date and time changed to be the same as this. * <p> * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)} * three times, passing {@link ChronoField#EPOCH_DAY}, * {@link ChronoField#NANO_OF_DAY} and {@link ChronoField#OFFSET_SECONDS} as the fields. * <p> * In most cases, it is clearer to reverse the calling pattern by using * {@link Temporal#with(TemporalAdjuster)}: * <pre> * // these two lines are equivalent, but the second approach is recommended * temporal = thisOffsetDateTime.adjustInto(temporal); * temporal = temporal.with(thisOffsetDateTime); * </pre> * <p> * This instance is immutable and unaffected by this method call. * * @param Temporal $temporal the target object to be adjusted, not null * @return Temporal the adjusted object, not null * @throws DateTimeException if unable to make the adjustment * @throws ArithmeticException if numeric overflow occurs */ public function adjustInto(Temporal $temporal) { // OffsetDateTime is treated as three separate fields, not an instant // this produces the most consistent set of results overall // the offset is set after the date and time, as it is typically a small // tweak to the result, with ZonedDateTime frequently ignoring the offset return $temporal->with(ChronoField::EPOCH_DAY(), $this->toLocalDate()->toEpochDay())->with(ChronoField::NANO_OF_DAY(), $this->toLocalTime()->toNanoOfDay())->with(ChronoField::OFFSET_SECONDS(), $this->getOffset()->getTotalSeconds()); }
public function adjustInto(Temporal $temporal, $newValue) { return $temporal->with($this, $newValue); }
/** * Adjusts the specified temporal object to have the same time as this object. * <p> * This returns a temporal object of the same observable type as the input * with the time changed to be the same as this. * <p> * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)} * passing {@link ChronoField#NANO_OF_DAY} as the field. * <p> * In most cases, it is clearer to reverse the calling pattern by using * {@link Temporal#with(TemporalAdjuster)}: * <pre> * // these two lines are equivalent, but the second approach is recommended * temporal = thisLocalTime.adjustInto(temporal); * temporal = temporal.with(thisLocalTime); * </pre> * <p> * This instance is immutable and unaffected by this method call. * * @param Temporal $temporal the target object to be adjusted, not null * @return Temporal the adjusted object, not null * @throws DateTimeException if unable to make the adjustment * @throws ArithmeticException if numeric overflow occurs */ public function adjustInto(Temporal $temporal) { return $temporal->with(ChronoField::NANO_OF_DAY(), $this->toNanoOfDay()); }
/** * Adjusts the specified temporal object to have this instant. * <p> * This returns a temporal object of the same observable type as the input * with the instant changed to be the same as this. * <p> * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)} * twice, passing {@link ChronoField#INSTANT_SECONDS} and * {@link ChronoField#NANO_OF_SECOND} as the fields. * <p> * In most cases, it is clearer to reverse the calling pattern by using * {@link Temporal#with(TemporalAdjuster)}: * <pre> * // these two lines are equivalent, but the second approach is recommended * temporal = thisInstant.adjustInto(temporal); * temporal = temporal.with(thisInstant); * </pre> * <p> * This instance is immutable and unaffected by this method call. * * @param Temporal $temporal the target object to be adjusted, not null * @return Temporal the adjusted object, not null * @throws DateTimeException if unable to make the adjustment * @throws ArithmeticException if numeric overflow occurs */ public function adjustInto(Temporal $temporal) { return $temporal->with(ChronoField::INSTANT_SECONDS(), $this->seconds)->with(ChronoField::NANO_OF_SECOND(), $this->nanos); }
/** * @inheritdoc */ public function adjustInto(Temporal $temporal) { return $temporal->with(ChronoField::EPOCH_DAY(), $this->toEpochDay()); }
/** * Adjusts the specified temporal object to have the same offset as this object. * <p> * This returns a temporal object of the same observable type as the input * with the offset changed to be the same as this. * <p> * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)} * passing {@link ChronoField#OFFSET_SECONDS} as the field. * <p> * In most cases, it is clearer to reverse the calling pattern by using * {@link Temporal#with(TemporalAdjuster)}: * <pre> * // these two lines are equivalent, but the second approach is recommended * temporal = thisOffset.adjustInto(temporal); * temporal = temporal.with(thisOffset); * </pre> * <p> * This instance is immutable and unaffected by this method call. * * @param Temporal $temporal the target object to be adjusted, not null * @return Temporal the adjusted object, not null * @throws DateTimeException if unable to make the adjustment * @throws ArithmeticException if numeric overflow occurs */ public function adjustInto(Temporal $temporal) { return $temporal->with(ChronoField::OFFSET_SECONDS(), $this->totalSeconds); }
/** * Adjusts the specified temporal object to have this day-of-week. * <p> * This returns a temporal object of the same observable type as the input * with the day-of-week changed to be the same as this. * <p> * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)} * passing {@link ChronoField#DAY_OF_WEEK} as the field. * Note that this adjusts forwards or backwards within a Monday to Sunday week. * See {@link java.time.temporal.WeekFields#dayOfWeek()} for localized week start days. * See {@code TemporalAdjuster} for other adjusters with more control, * such as {@code next(MONDAY)}. * <p> * In most cases, it is clearer to reverse the calling pattern by using * {@link Temporal#with(TemporalAdjuster)}: * <pre> * // these two lines are equivalent, but the second approach is recommended * temporal = thisDayOfWeek.adjustInto(temporal); * temporal = temporal.with(thisDayOfWeek); * </pre> * <p> * For example, given a date that is a Wednesday, the following are output: * <pre> * dateOnWed.with(MONDAY); // two days earlier * dateOnWed.with(TUESDAY); // one day earlier * dateOnWed.with(WEDNESDAY); // same date * dateOnWed.with(THURSDAY); // one day later * dateOnWed.with(FRIDAY); // two days later * dateOnWed.with(SATURDAY); // three days later * dateOnWed.with(SUNDAY); // four days later * </pre> * <p> * This instance is immutable and unaffected by this method call. * * @param Temporal $temporal the target object to be adjusted, not null * @return Temporal the adjusted object, not null * @throws DateTimeException if unable to make the adjustment * @throws ArithmeticException if numeric overflow occurs */ public function adjustInto(Temporal $temporal) { return $temporal->with(ChronoField::DAY_OF_WEEK(), $this->getValue()); }
/** * @inheritdoc */ public function adjustInto(Temporal $temporal) { return $temporal->with(ChronoField::EPOCH_DAY(), $this->toLocalDate()->toEpochDay())->with(ChronoField::NANO_OF_DAY(), $this->toLocalTime()->toNanoOfDay()); }
/** * Adjusts the specified temporal object to have the same offset and time * as this object. * <p> * This returns a temporal object of the same observable type as the input * with the offset and time changed to be the same as this. * <p> * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)} * twice, passing {@link ChronoField#NANO_OF_DAY} and * {@link ChronoField#OFFSET_SECONDS} as the fields. * <p> * In most cases, it is clearer to reverse the calling pattern by using * {@link Temporal#with(TemporalAdjuster)}: * <pre> * // these two lines are equivalent, but the second approach is recommended * temporal = thisOffsetTime.adjustInto(temporal); * temporal = temporal.with(thisOffsetTime); * </pre> * <p> * This instance is immutable and unaffected by this method call. * * @param Temporal $temporal the target object to be adjusted, not null * @return Temporal the adjusted object, not null * @throws DateTimeException if unable to make the adjustment * @throws ArithmeticException if numeric overflow occurs */ public function adjustInto(Temporal $temporal) { return $temporal->with(ChronoField::NANO_OF_DAY(), $this->time->toNanoOfDay())->with(ChronoField::OFFSET_SECONDS(), $this->offset->getTotalSeconds()); }