Java Code Examples for java.time.temporal.TemporalAmount#subtractFrom()
The following examples show how to use
java.time.temporal.TemporalAmount#subtractFrom() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalDate.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * 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 amountToSubtract the amount to subtract, not null * @return 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 */ @Override public LocalDate minus(TemporalAmount amountToSubtract) { if (amountToSubtract instanceof Period) { Period periodToSubtract = (Period) amountToSubtract; return minusMonths(periodToSubtract.toTotalMonths()).minusDays(periodToSubtract.getDays()); } Objects.requireNonNull(amountToSubtract, "amountToSubtract"); return (LocalDate) amountToSubtract.subtractFrom(this); }
Example 2
Source File: LocalDate.java From openjdk-jdk8u with GNU General Public License v2.0 | 3 votes |
/** * 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 amountToSubtract the amount to subtract, not null * @return 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 */ @Override public LocalDate minus(TemporalAmount amountToSubtract) { if (amountToSubtract instanceof Period) { Period periodToSubtract = (Period) amountToSubtract; return minusMonths(periodToSubtract.toTotalMonths()).minusDays(periodToSubtract.getDays()); } Objects.requireNonNull(amountToSubtract, "amountToSubtract"); return (LocalDate) amountToSubtract.subtractFrom(this); }
Example 3
Source File: LocalDate.java From openjdk-8-source with GNU General Public License v2.0 | 3 votes |
/** * 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 amountToSubtract the amount to subtract, not null * @return 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 */ @Override public LocalDate minus(TemporalAmount amountToSubtract) { if (amountToSubtract instanceof Period) { Period periodToSubtract = (Period) amountToSubtract; return minusMonths(periodToSubtract.toTotalMonths()).minusDays(periodToSubtract.getDays()); } Objects.requireNonNull(amountToSubtract, "amountToSubtract"); return (LocalDate) amountToSubtract.subtractFrom(this); }
Example 4
Source File: LocalDateTime.java From openjdk-jdk8u with GNU General Public License v2.0 | 3 votes |
/** * 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 amountToSubtract the amount to subtract, not null * @return 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 */ @Override public LocalDateTime minus(TemporalAmount amountToSubtract) { if (amountToSubtract instanceof Period) { Period periodToSubtract = (Period) amountToSubtract; return with(date.minus(periodToSubtract), time); } Objects.requireNonNull(amountToSubtract, "amountToSubtract"); return (LocalDateTime) amountToSubtract.subtractFrom(this); }
Example 5
Source File: LocalDateTime.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * 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 amountToSubtract the amount to subtract, not null * @return 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 */ @Override public LocalDateTime minus(TemporalAmount amountToSubtract) { if (amountToSubtract instanceof Period) { Period periodToSubtract = (Period) amountToSubtract; return with(date.minus(periodToSubtract), time); } Objects.requireNonNull(amountToSubtract, "amountToSubtract"); return (LocalDateTime) amountToSubtract.subtractFrom(this); }
Example 6
Source File: ZonedDateTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 3 votes |
/** * 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 amountToSubtract the amount to subtract, not null * @return 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 */ @Override public ZonedDateTime minus(TemporalAmount amountToSubtract) { if (amountToSubtract instanceof Period) { Period periodToSubtract = (Period) amountToSubtract; return resolveLocal(dateTime.minus(periodToSubtract)); } Objects.requireNonNull(amountToSubtract, "amountToSubtract"); return (ZonedDateTime) amountToSubtract.subtractFrom(this); }
Example 7
Source File: ZonedDateTime.java From TencentKona-8 with GNU General Public License v2.0 | 3 votes |
/** * 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 amountToSubtract the amount to subtract, not null * @return 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 */ @Override public ZonedDateTime minus(TemporalAmount amountToSubtract) { if (amountToSubtract instanceof Period) { Period periodToSubtract = (Period) amountToSubtract; return resolveLocal(dateTime.minus(periodToSubtract)); } Objects.requireNonNull(amountToSubtract, "amountToSubtract"); return (ZonedDateTime) amountToSubtract.subtractFrom(this); }
Example 8
Source File: LocalTime.java From hottub with GNU General Public License v2.0 | 2 votes |
/** * Returns a copy of this time with the specified amount subtracted. * <p> * This returns a {@code LocalTime}, based on this one, with the specified amount subtracted. * The amount is typically {@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 amountToSubtract the amount to subtract, not null * @return a {@code LocalTime} based on this time with the subtraction made, not null * @throws DateTimeException if the subtraction cannot be made * @throws ArithmeticException if numeric overflow occurs */ @Override public LocalTime minus(TemporalAmount amountToSubtract) { return (LocalTime) amountToSubtract.subtractFrom(this); }
Example 9
Source File: OffsetDateTime.java From Bytecoder with Apache License 2.0 | 2 votes |
/** * 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 amountToSubtract the amount to subtract, not null * @return 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 */ @Override public OffsetDateTime minus(TemporalAmount amountToSubtract) { return (OffsetDateTime) amountToSubtract.subtractFrom(this); }
Example 10
Source File: LocalTime.java From jdk8u-jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a copy of this time with the specified amount subtracted. * <p> * This returns a {@code LocalTime}, based on this one, with the specified amount subtracted. * The amount is typically {@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 amountToSubtract the amount to subtract, not null * @return a {@code LocalTime} based on this time with the subtraction made, not null * @throws DateTimeException if the subtraction cannot be made * @throws ArithmeticException if numeric overflow occurs */ @Override public LocalTime minus(TemporalAmount amountToSubtract) { return (LocalTime) amountToSubtract.subtractFrom(this); }
Example 11
Source File: LocalTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a copy of this time with the specified amount subtracted. * <p> * This returns a {@code LocalTime}, based on this one, with the specified amount subtracted. * The amount is typically {@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 amountToSubtract the amount to subtract, not null * @return a {@code LocalTime} based on this time with the subtraction made, not null * @throws DateTimeException if the subtraction cannot be made * @throws ArithmeticException if numeric overflow occurs */ @Override public LocalTime minus(TemporalAmount amountToSubtract) { return (LocalTime) amountToSubtract.subtractFrom(this); }
Example 12
Source File: OffsetTime.java From jdk8u-jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a copy of this time with the specified amount subtracted. * <p> * This returns an {@code OffsetTime}, based on this one, with the specified amount subtracted. * The amount is typically {@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 amountToSubtract the amount to subtract, not null * @return an {@code OffsetTime} based on this time with the subtraction made, not null * @throws DateTimeException if the subtraction cannot be made * @throws ArithmeticException if numeric overflow occurs */ @Override public OffsetTime minus(TemporalAmount amountToSubtract) { return (OffsetTime) amountToSubtract.subtractFrom(this); }
Example 13
Source File: Instant.java From hottub with GNU General Public License v2.0 | 2 votes |
/** * Returns a copy of this instant with the specified amount subtracted. * <p> * This returns an {@code Instant}, based on this one, with the specified amount subtracted. * The amount is typically {@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 amountToSubtract the amount to subtract, not null * @return an {@code Instant} based on this instant with the subtraction made, not null * @throws DateTimeException if the subtraction cannot be made * @throws ArithmeticException if numeric overflow occurs */ @Override public Instant minus(TemporalAmount amountToSubtract) { return (Instant) amountToSubtract.subtractFrom(this); }
Example 14
Source File: Year.java From Bytecoder with Apache License 2.0 | 2 votes |
/** * Returns a copy of this year with the specified amount subtracted. * <p> * This returns a {@code Year}, 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 amountToSubtract the amount to subtract, not null * @return a {@code Year} based on this year with the subtraction made, not null * @throws DateTimeException if the subtraction cannot be made * @throws ArithmeticException if numeric overflow occurs */ @Override public Year minus(TemporalAmount amountToSubtract) { return (Year) amountToSubtract.subtractFrom(this); }
Example 15
Source File: Year.java From openjdk-8-source with GNU General Public License v2.0 | 2 votes |
/** * Returns a copy of this year with the specified amount subtracted. * <p> * This returns a {@code Year}, 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 amountToSubtract the amount to subtract, not null * @return a {@code Year} based on this year with the subtraction made, not null * @throws DateTimeException if the subtraction cannot be made * @throws ArithmeticException if numeric overflow occurs */ @Override public Year minus(TemporalAmount amountToSubtract) { return (Year) amountToSubtract.subtractFrom(this); }
Example 16
Source File: OffsetDateTime.java From hottub with GNU General Public License v2.0 | 2 votes |
/** * 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 amountToSubtract the amount to subtract, not null * @return 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 */ @Override public OffsetDateTime minus(TemporalAmount amountToSubtract) { return (OffsetDateTime) amountToSubtract.subtractFrom(this); }
Example 17
Source File: Year.java From jdk8u60 with GNU General Public License v2.0 | 2 votes |
/** * Returns a copy of this year with the specified amount subtracted. * <p> * This returns a {@code Year}, 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 amountToSubtract the amount to subtract, not null * @return a {@code Year} based on this year with the subtraction made, not null * @throws DateTimeException if the subtraction cannot be made * @throws ArithmeticException if numeric overflow occurs */ @Override public Year minus(TemporalAmount amountToSubtract) { return (Year) amountToSubtract.subtractFrom(this); }
Example 18
Source File: OffsetTime.java From openjdk-jdk8u with GNU General Public License v2.0 | 2 votes |
/** * Returns a copy of this time with the specified amount subtracted. * <p> * This returns an {@code OffsetTime}, based on this one, with the specified amount subtracted. * The amount is typically {@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 amountToSubtract the amount to subtract, not null * @return an {@code OffsetTime} based on this time with the subtraction made, not null * @throws DateTimeException if the subtraction cannot be made * @throws ArithmeticException if numeric overflow occurs */ @Override public OffsetTime minus(TemporalAmount amountToSubtract) { return (OffsetTime) amountToSubtract.subtractFrom(this); }
Example 19
Source File: YearMonth.java From Bytecoder with Apache License 2.0 | 2 votes |
/** * Returns a copy of this year-month with the specified amount subtracted. * <p> * This returns a {@code YearMonth}, 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 amountToSubtract the amount to subtract, not null * @return a {@code YearMonth} based on this year-month with the subtraction made, not null * @throws DateTimeException if the subtraction cannot be made * @throws ArithmeticException if numeric overflow occurs */ @Override public YearMonth minus(TemporalAmount amountToSubtract) { return (YearMonth) amountToSubtract.subtractFrom(this); }
Example 20
Source File: Instant.java From openjdk-8 with GNU General Public License v2.0 | 2 votes |
/** * Returns a copy of this instant with the specified amount subtracted. * <p> * This returns an {@code Instant}, based on this one, with the specified amount subtracted. * The amount is typically {@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 amountToSubtract the amount to subtract, not null * @return an {@code Instant} based on this instant with the subtraction made, not null * @throws DateTimeException if the subtraction cannot be made * @throws ArithmeticException if numeric overflow occurs */ @Override public Instant minus(TemporalAmount amountToSubtract) { return (Instant) amountToSubtract.subtractFrom(this); }