Java Code Examples for java.time.temporal.Temporal#minus()
The following examples show how to use
java.time.temporal.Temporal#minus() .
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: ChronoPeriodImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public Temporal subtractFrom(Temporal temporal) { validateChrono(temporal); if (months == 0) { if (years != 0) { temporal = temporal.minus(years, YEARS); } } else { long monthRange = monthRange(); if (monthRange > 0) { temporal = temporal.minus(years * monthRange + months, MONTHS); } else { if (years != 0) { temporal = temporal.minus(years, YEARS); } temporal = temporal.minus(months, MONTHS); } } if (days != 0) { temporal = temporal.minus(days, DAYS); } return temporal; }
Example 2
Source File: ChronoPeriodImpl.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public Temporal subtractFrom(Temporal temporal) { validateChrono(temporal); if (months == 0) { if (years != 0) { temporal = temporal.minus(years, YEARS); } } else { long monthRange = monthRange(); if (monthRange > 0) { temporal = temporal.minus(years * monthRange + months, MONTHS); } else { if (years != 0) { temporal = temporal.minus(years, YEARS); } temporal = temporal.minus(months, MONTHS); } } if (days != 0) { temporal = temporal.minus(days, DAYS); } return temporal; }
Example 3
Source File: ChronoPeriodImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public Temporal subtractFrom(Temporal temporal) { validateChrono(temporal); if (months == 0) { if (years != 0) { temporal = temporal.minus(years, YEARS); } } else { long monthRange = monthRange(); if (monthRange > 0) { temporal = temporal.minus(years * monthRange + months, MONTHS); } else { if (years != 0) { temporal = temporal.minus(years, YEARS); } temporal = temporal.minus(months, MONTHS); } } if (days != 0) { temporal = temporal.minus(days, DAYS); } return temporal; }
Example 4
Source File: ChronoPeriodImpl.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Override public Temporal subtractFrom(Temporal temporal) { validateChrono(temporal); if (months == 0) { if (years != 0) { temporal = temporal.minus(years, YEARS); } } else { long monthRange = monthRange(); if (monthRange > 0) { temporal = temporal.minus(years * monthRange + months, MONTHS); } else { if (years != 0) { temporal = temporal.minus(years, YEARS); } temporal = temporal.minus(months, MONTHS); } } if (days != 0) { temporal = temporal.minus(days, DAYS); } return temporal; }
Example 5
Source File: ChronoPeriodImpl.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@Override public Temporal subtractFrom(Temporal temporal) { validateChrono(temporal); if (months == 0) { if (years != 0) { temporal = temporal.minus(years, YEARS); } } else { long monthRange = monthRange(); if (monthRange > 0) { temporal = temporal.minus(years * monthRange + months, MONTHS); } else { if (years != 0) { temporal = temporal.minus(years, YEARS); } temporal = temporal.minus(months, MONTHS); } } if (days != 0) { temporal = temporal.minus(days, DAYS); } return temporal; }
Example 6
Source File: TimePeriod.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override public Temporal subtractFrom(Temporal temporal) { for(Map.Entry<TemporalUnit, Long> entry : values.entrySet()) { temporal = temporal.minus(entry.getValue(), entry.getKey()); } return temporal; }
Example 7
Source File: MockSimplePeriod.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Override public Temporal subtractFrom(Temporal temporal) { return temporal.minus(amount, unit); }
Example 8
Source File: MockSimplePeriod.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@Override public Temporal subtractFrom(Temporal temporal) { return temporal.minus(amount, unit); }
Example 9
Source File: DelayedDailyPathComputer.java From garmadon with Apache License 2.0 | 4 votes |
@Override public String apply(Temporal localDateTime) { Temporal actualDayBucket = localDateTime.minus(graceDelay); return DateTimeFormatter.ofPattern("YYYY-MM-dd").format(actualDayBucket); }
Example 10
Source File: MockSimplePeriod.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Override public Temporal subtractFrom(Temporal temporal) { return temporal.minus(amount, unit); }
Example 11
Source File: MockSimplePeriod.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Override public Temporal subtractFrom(Temporal temporal) { return temporal.minus(amount, unit); }
Example 12
Source File: MockSimplePeriod.java From j2objc with Apache License 2.0 | 4 votes |
@Override public Temporal subtractFrom(Temporal temporal) { return temporal.minus(amount, unit); }
Example 13
Source File: Period.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * Subtracts this period from the specified temporal object. * <p> * This returns a temporal object of the same observable type as the input * with this period subtracted. * If the temporal has a chronology, it must be the ISO chronology. * <p> * In most cases, it is clearer to reverse the calling pattern by using * {@link Temporal#minus(TemporalAmount)}. * <pre> * // these two lines are equivalent, but the second approach is recommended * dateTime = thisPeriod.subtractFrom(dateTime); * dateTime = dateTime.minus(thisPeriod); * </pre> * <p> * The calculation operates as follows. * First, the chronology of the temporal is checked to ensure it is ISO chronology or null. * Second, if the months are zero, the years are subtracted if non-zero, otherwise * the combination of years and months is subtracted if non-zero. * Finally, any days are subtracted. * <p> * This approach ensures that a partial period can be subtracted from a partial date. * For example, a period of years and/or months can be subtracted from a {@code YearMonth}, * but a period including days cannot. * The approach also subtracts years and months together when necessary, which ensures * correct behaviour at the end of the month. * <p> * This instance is immutable and unaffected by this method call. * * @param temporal the temporal object to adjust, not null * @return an object of the same type with the adjustment made, not null * @throws DateTimeException if unable to subtract * @throws ArithmeticException if numeric overflow occurs */ @Override public Temporal subtractFrom(Temporal temporal) { validateChrono(temporal); if (months == 0) { if (years != 0) { temporal = temporal.minus(years, YEARS); } } else { long totalMonths = toTotalMonths(); if (totalMonths != 0) { temporal = temporal.minus(totalMonths, MONTHS); } } if (days != 0) { temporal = temporal.minus(days, DAYS); } return temporal; }
Example 14
Source File: MockSimplePeriod.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Override public Temporal subtractFrom(Temporal temporal) { return temporal.minus(amount, unit); }
Example 15
Source File: MockSimplePeriod.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Override public Temporal subtractFrom(Temporal temporal) { return temporal.minus(amount, unit); }
Example 16
Source File: MockSimplePeriod.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public Temporal subtractFrom(Temporal temporal) { return temporal.minus(amount, unit); }
Example 17
Source File: Duration.java From openjdk-jdk8u with GNU General Public License v2.0 | 3 votes |
/** * Subtracts this duration from the specified temporal object. * <p> * This returns a temporal object of the same observable type as the input * with this duration subtracted. * <p> * In most cases, it is clearer to reverse the calling pattern by using * {@link Temporal#minus(TemporalAmount)}. * <pre> * // these two lines are equivalent, but the second approach is recommended * dateTime = thisDuration.subtractFrom(dateTime); * dateTime = dateTime.minus(thisDuration); * </pre> * <p> * The calculation will subtract the seconds, then nanos. * Only non-zero amounts will be added. * <p> * This instance is immutable and unaffected by this method call. * * @param temporal the temporal object to adjust, not null * @return an object of the same type with the adjustment made, not null * @throws DateTimeException if unable to subtract * @throws ArithmeticException if numeric overflow occurs */ @Override public Temporal subtractFrom(Temporal temporal) { if (seconds != 0) { temporal = temporal.minus(seconds, SECONDS); } if (nanos != 0) { temporal = temporal.minus(nanos, NANOS); } return temporal; }
Example 18
Source File: Duration.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * Subtracts this duration from the specified temporal object. * <p> * This returns a temporal object of the same observable type as the input * with this duration subtracted. * <p> * In most cases, it is clearer to reverse the calling pattern by using * {@link Temporal#minus(TemporalAmount)}. * <pre> * // these two lines are equivalent, but the second approach is recommended * dateTime = thisDuration.subtractFrom(dateTime); * dateTime = dateTime.minus(thisDuration); * </pre> * <p> * The calculation will subtract the seconds, then nanos. * Only non-zero amounts will be added. * <p> * This instance is immutable and unaffected by this method call. * * @param temporal the temporal object to adjust, not null * @return an object of the same type with the adjustment made, not null * @throws DateTimeException if unable to subtract * @throws ArithmeticException if numeric overflow occurs */ @Override public Temporal subtractFrom(Temporal temporal) { if (seconds != 0) { temporal = temporal.minus(seconds, SECONDS); } if (nanos != 0) { temporal = temporal.minus(nanos, NANOS); } return temporal; }
Example 19
Source File: Duration.java From openjdk-8-source with GNU General Public License v2.0 | 3 votes |
/** * Subtracts this duration from the specified temporal object. * <p> * This returns a temporal object of the same observable type as the input * with this duration subtracted. * <p> * In most cases, it is clearer to reverse the calling pattern by using * {@link Temporal#minus(TemporalAmount)}. * <pre> * // these two lines are equivalent, but the second approach is recommended * dateTime = thisDuration.subtractFrom(dateTime); * dateTime = dateTime.minus(thisDuration); * </pre> * <p> * The calculation will subtract the seconds, then nanos. * Only non-zero amounts will be added. * <p> * This instance is immutable and unaffected by this method call. * * @param temporal the temporal object to adjust, not null * @return an object of the same type with the adjustment made, not null * @throws DateTimeException if unable to subtract * @throws ArithmeticException if numeric overflow occurs */ @Override public Temporal subtractFrom(Temporal temporal) { if (seconds != 0) { temporal = temporal.minus(seconds, SECONDS); } if (nanos != 0) { temporal = temporal.minus(nanos, NANOS); } return temporal; }
Example 20
Source File: Duration.java From j2objc with Apache License 2.0 | 3 votes |
/** * Subtracts this duration from the specified temporal object. * <p> * This returns a temporal object of the same observable type as the input * with this duration subtracted. * <p> * In most cases, it is clearer to reverse the calling pattern by using * {@link Temporal#minus(TemporalAmount)}. * <pre> * // these two lines are equivalent, but the second approach is recommended * dateTime = thisDuration.subtractFrom(dateTime); * dateTime = dateTime.minus(thisDuration); * </pre> * <p> * The calculation will subtract the seconds, then nanos. * Only non-zero amounts will be added. * <p> * This instance is immutable and unaffected by this method call. * * @param temporal the temporal object to adjust, not null * @return an object of the same type with the adjustment made, not null * @throws DateTimeException if unable to subtract * @throws ArithmeticException if numeric overflow occurs */ @Override public Temporal subtractFrom(Temporal temporal) { if (seconds != 0) { temporal = temporal.minus(seconds, SECONDS); } if (nanos != 0) { temporal = temporal.minus(nanos, NANOS); } return temporal; }