/** * Returns a copy of this date-time with the specified amount added. * <p> * This returns an {@code OffsetDateTime}, based on this one, with the specified amount added. * The amount is typically {@link Period} or {@link Duration} but may be * any other type implementing the {@link TemporalAmount} interface. * <p> * The calculation is delegated to the amount object by calling * {@link TemporalAmount#addTo(Temporal)}. The amount implementation is free * to implement the addition in any way it wishes, however it typically * calls back to {@link #plus(long, TemporalUnit)}. Consult the documentation * of the amount implementation to determine if it can be successfully added. * <p> * This instance is immutable and unaffected by this method call. * * @param TemporalAmount $amountToAdd the amount to add, not null * @return OffsetDateTime an {@code OffsetDateTime} based on this date-time with the addition made, not null * @throws DateTimeException if the addition cannot be made * @throws ArithmeticException if numeric overflow occurs */ public function plusAmount(TemporalAmount $amountToAdd) { return $amountToAdd->addTo($this); }
/** * Returns a copy of this date-time with the specified amount added. * <p> * This returns a {@code LocalDateTime}, based on this one, with the specified amount added. * The amount is typically {@link Period} or {@link Duration} but may be * any other type implementing the {@link TemporalAmount} interface. * <p> * The calculation is delegated to the amount object by calling * {@link TemporalAmount#addTo(Temporal)}. The amount implementation is free * to implement the addition in any way it wishes, however it typically * calls back to {@link #plus(long, TemporalUnit)}. Consult the documentation * of the amount implementation to determine if it can be successfully added. * <p> * This instance is immutable and unaffected by this method call. * * @param TemporalAmount $amountToAdd the amount to add, not null * @return LocalDateTime a {@code LocalDateTime} based on this date-time with the addition made, not null * @throws DateTimeException if the addition cannot be made * @throws ArithmeticException if numeric overflow occurs */ public function plusAmount(TemporalAmount $amountToAdd) { if ($amountToAdd instanceof Period) { $periodToAdd = $amountToAdd; return $this->_with($this->date->plusAmount($periodToAdd), $this->time); } return $amountToAdd->addTo($this); }
/** * Returns a copy of this date with the specified amount added. * <p> * This returns a {@code LocalDate}, based on this one, with the specified amount added. * The amount is typically {@link Period} but may be any other type implementing * the {@link TemporalAmount} interface. * <p> * The calculation is delegated to the amount object by calling * {@link TemporalAmount#addTo(Temporal)}. The amount implementation is free * to implement the addition in any way it wishes, however it typically * calls back to {@link #plus(long, TemporalUnit)}. Consult the documentation * of the amount implementation to determine if it can be successfully added. * <p> * This instance is immutable and unaffected by this method call. * * @param TemporalAmount $amountToAdd the amount to add, not null * @return LocalDate a {@code LocalDate} based on this date with the addition made, not null * @throws DateTimeException if the addition cannot be made * @throws ArithmeticException if numeric overflow occurs */ public function plusAmount(TemporalAmount $amountToAdd) { if ($amountToAdd instanceof Period) { $periodToAdd = $amountToAdd; return $this->plusMonths($periodToAdd->toTotalMonths())->plusDays($periodToAdd->getDays()); } return $amountToAdd->addTo($this); }
/** * Returns a copy of this date-time with the specified amount added. * <p> * This returns a {@code ZonedDateTime}, based on this one, with the specified amount added. * The amount is typically {@link Period} or {@link Duration} but may be * any other type implementing the {@link TemporalAmount} interface. * <p> * The calculation is delegated to the amount object by calling * {@link TemporalAmount#addTo(Temporal)}. The amount implementation is free * to implement the addition in any way it wishes, however it typically * calls back to {@link #plus(long, TemporalUnit)}. Consult the documentation * of the amount implementation to determine if it can be successfully added. * <p> * This instance is immutable and unaffected by this method call. * * @param TemporalAmount $amountToAdd the amount to add, not null * @return ZonedDateTime a {@code ZonedDateTime} based on this date-time with the addition made, not null * @throws DateTimeException if the addition cannot be made * @throws ArithmeticException if numeric overflow occurs */ public function plusAmount(TemporalAmount $amountToAdd) { if ($amountToAdd instanceof Period) { $periodToAdd = $amountToAdd; return $this->resolveLocal($this->dateTime->plusAmount($periodToAdd)); } return $amountToAdd->addTo($this); }