private static Temporal assertValidMinus( Temporal temporal, long amountToAdd, TemporalUnit unit ) { try { return temporal.minus(amountToAdd, unit); } catch ( DateTimeException | ArithmeticException e ) { throw new TemporalArithmeticException( e.getMessage(), e ); } }
@Override @SuppressWarnings( "unchecked" ) public final V minus( TemporalAmount amount ) { return replacement( (T) temporal().minus( amount ) ); }
@Override @SuppressWarnings( "unchecked" ) public final V minus( long amountToSubtract, TemporalUnit unit ) { return replacement( (T) temporal().minus( amountToSubtract, unit ) ); }
@Override public Temporal subtractFrom(Temporal temporal) { return temporal.minus(this); } }
/** * Subtracts this amount from the specified temporal object. * <p> * This returns a temporal object of the same observable type as the input * with this amount subtracted. This simply subtracts the period and duration from the temporal. * <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 UnsupportedTemporalTypeException if the DAYS unit is not supported * @throws ArithmeticException if numeric overflow occurs */ @Override public Temporal subtractFrom(Temporal temporal) { return temporal.minus(period).minus(duration); }
@Override public Temporal subtractFrom( Temporal temporal ) { if ( months != 0 ) { temporal = temporal.minus( months, MONTHS ); } if ( days != 0 ) { temporal = temporal.minus( days, DAYS ); } if ( seconds != 0 ) { temporal = temporal.minus( seconds, SECONDS ); } if ( nanoseconds != 0 ) { temporal = temporal.minus( nanoseconds, NANOS ); } return temporal; }
private static Temporal assertValidMinus( Temporal temporal, long amountToAdd, TemporalUnit unit ) { try { return temporal.minus(amountToAdd, unit); } catch ( DateTimeException | ArithmeticException e ) { throw new TemporalArithmeticException( e.getMessage(), e ); } }
/** * {@inheritDoc} * * <p>This implementation converts the months and days components to a {@link Period}, and the * nanosecond component to a {@link Duration}, and subtracts those two amounts to the temporal * object. Therefore the chronology of the temporal must be either the ISO chronology or null. * * @see Period#subtractFrom(Temporal) * @see Duration#subtractFrom(Temporal) */ @Override public Temporal subtractFrom(Temporal temporal) { return temporal.minus(Period.of(0, months, days)).minus(Duration.ofNanos(nanoseconds)); }
public Temporal subtractFrom(final Temporal temporal) { return temporal.minus(this.toDurationInMillis(), CalendarDateUnit.MILLIS); }
public Temporal subtractFrom(final Temporal temporal) { return temporal.minus(this.toDurationInMillis(), CalendarDateUnit.MILLIS); }
@Override @SuppressWarnings( "unchecked" ) public final V minus( TemporalAmount amount ) { return replacement( (T) temporal().minus( amount ) ); }
@Override @SuppressWarnings( "unchecked" ) public final V minus( long amountToSubtract, TemporalUnit unit ) { return replacement( (T) temporal().minus( amountToSubtract, unit ) ); }
@Override public Temporal adjustInto(Temporal temporal) { int calDow = temporal.get(DAY_OF_WEEK); if (relative < 2 && calDow == dowValue) { return temporal; } if ((relative & 1) == 0) { int daysDiff = calDow - dowValue; return temporal.plus(daysDiff >= 0 ? 7 - daysDiff : -daysDiff, DAYS); } else { int daysDiff = dowValue - calDow; return temporal.minus(daysDiff >= 0 ? 7 - daysDiff : -daysDiff, DAYS); } } }
@Override public Temporal subtractFrom(Temporal temporal) { Jdk8Methods.requireNonNull(temporal, "temporal"); Chronology temporalChrono = temporal.query(TemporalQueries.chronology()); if (temporalChrono != null && chronology.equals(temporalChrono) == false) { throw new DateTimeException("Invalid chronology, required: " + chronology.getId() + ", but was: " + temporalChrono.getId()); } if (years != 0) { temporal = temporal.minus(years, YEARS); } if (months != 0) { temporal = temporal.minus(months, MONTHS); } if (days != 0) { temporal = temporal.minus(days, DAYS); } return temporal; }
public static TemporalAdjuster startOfPreviousEvenHour() { return temporal -> { int currentHour = temporal.get(ChronoField.HOUR_OF_DAY); return temporal.minus((currentHour % 2 == 0) ? 0 : 1, ChronoUnit.HOURS) .with(ChronoField.MINUTE_OF_HOUR, 0) .with(ChronoField.SECOND_OF_MINUTE, 0) .with(ChronoField.NANO_OF_SECOND, 0); }; }
private Temporal computeDateForMonthlyFrequencyFrom(final Temporal source, DayOfWeekOccurrence dayOfWeek) { Temporal current = source; if (dayOfWeek.nth() > 1) { current = current.with(ChronoField.ALIGNED_WEEK_OF_MONTH, dayOfWeek.nth()); } else if (dayOfWeek.nth() < 0) { current = current.with(ChronoField.DAY_OF_MONTH, 1) .plus(1, ChronoUnit.MONTHS) .minus(1, ChronoUnit.DAYS) .plus(dayOfWeek.nth(), ChronoUnit.WEEKS) .with(dayOfWeek.dayOfWeek()); } return current; }