예제 #1
0
 /**
  * Returns a copy of this date-time with the specified amount subtracted.
  * <p>
  * This returns an {@code OffsetDateTime}, based on this one, with the specified amount subtracted.
  * 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#subtractFrom(Temporal)}. The amount implementation is free
  * to implement the subtraction in any way it wishes, however it typically
  * calls back to {@link #minus(long, TemporalUnit)}. Consult the documentation
  * of the amount implementation to determine if it can be successfully subtracted.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param TemporalAmount $amountToSubtract the amount to subtract, not null
  * @return OffsetDateTime an {@code OffsetDateTime} based on this date-time with the subtraction made, not null
  * @throws DateTimeException if the subtraction cannot be made
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function minusAmount(TemporalAmount $amountToSubtract)
 {
     return $amountToSubtract->subtractFrom($this);
 }
예제 #2
0
 /**
  * Returns a copy of this date-time with the specified amount subtracted.
  * <p>
  * This returns a {@code LocalDateTime}, based on this one, with the specified amount subtracted.
  * 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#subtractFrom(Temporal)}. The amount implementation is free
  * to implement the subtraction in any way it wishes, however it typically
  * calls back to {@link #minus(long, TemporalUnit)}. Consult the documentation
  * of the amount implementation to determine if it can be successfully subtracted.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param TemporalAmount $amountToSubtract the amount to subtract, not null
  * @return LocalDateTime a {@code LocalDateTime} based on this date-time with the subtraction made, not null
  * @throws DateTimeException if the subtraction cannot be made
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function minusAmount(TemporalAmount $amountToSubtract)
 {
     if ($amountToSubtract instanceof Period) {
         $periodToSubtract = $amountToSubtract;
         return $this->_with($this->date->minusAmount($periodToSubtract), $this->time);
     }
     return $amountToSubtract->subtractFrom($this);
 }
예제 #3
0
 /**
  * Returns a copy of this date with the specified amount subtracted.
  * <p>
  * This returns a {@code LocalDate}, based on this one, with the specified amount subtracted.
  * 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#subtractFrom(Temporal)}. The amount implementation is free
  * to implement the subtraction in any way it wishes, however it typically
  * calls back to {@link #minus(long, TemporalUnit)}. Consult the documentation
  * of the amount implementation to determine if it can be successfully subtracted.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param TemporalAmount $amountToSubtract the amount to subtract, not null
  * @return LocalDate a {@code LocalDate} based on this date with the subtraction made, not null
  * @throws DateTimeException if the subtraction cannot be made
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function minusAmount(TemporalAmount $amountToSubtract)
 {
     if ($amountToSubtract instanceof Period) {
         /** @var Period $periodToSubtract */
         $periodToSubtract = $amountToSubtract;
         return $this->minusMonths($periodToSubtract->toTotalMonths())->minusDays($periodToSubtract->getDays());
     }
     return $amountToSubtract->subtractFrom($this);
 }
예제 #4
0
 /**
  * Returns a copy of this date-time with the specified amount subtracted.
  * <p>
  * This returns a {@code ZonedDateTime}, based on this one, with the specified amount subtracted.
  * 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#subtractFrom(Temporal)}. The amount implementation is free
  * to implement the subtraction in any way it wishes, however it typically
  * calls back to {@link #minus(long, TemporalUnit)}. Consult the documentation
  * of the amount implementation to determine if it can be successfully subtracted.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param TemporalAmount $amountToSubtract the amount to subtract, not null
  * @return ZonedDateTime a {@code ZonedDateTime} based on this date-time with the subtraction made, not null
  * @throws DateTimeException if the subtraction cannot be made
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function minusAmount(TemporalAmount $amountToSubtract)
 {
     if ($amountToSubtract instanceof Period) {
         $periodToSubtract = $amountToSubtract;
         return $this->resolveLocal($this->dateTime->minusAmount($periodToSubtract));
     }
     return $amountToSubtract->subtractFrom($this);
 }