/** * Returns a copy of this year-month with the specified period in months subtracted. * <p> * This instance is immutable and unaffected by this method call. * * @param monthsToSubtract the months to subtract, may be negative * @return a {@code YearMonth} based on this year-month with the months subtracted, not null * @throws DateTimeException if the result exceeds the supported range */ public YearMonth minusMonths(long monthsToSubtract) { return (monthsToSubtract == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-monthsToSubtract)); }
/** * Returns a copy of this year-month with the specified period in months subtracted. * <p> * This instance is immutable and unaffected by this method call. * * @param monthsToSubtract the months to subtract, may be negative * @return a {@code YearMonth} based on this year-month with the months subtracted, not null * @throws DateTimeException if the result exceeds the supported range */ public YearMonth minusMonths(long monthsToSubtract) { return (monthsToSubtract == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-monthsToSubtract)); }
/** * {@inheritDoc} * @throws DateTimeException {@inheritDoc} * @throws ArithmeticException {@inheritDoc} */ @Override public YearMonth plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { switch ((ChronoUnit) unit) { case MONTHS: return plusMonths(amountToAdd); case YEARS: return plusYears(amountToAdd); case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10)); case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100)); case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000)); case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd)); } throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); } return unit.addTo(this, amountToAdd); }
/** * {@inheritDoc} * @throws DateTimeException {@inheritDoc} * @throws ArithmeticException {@inheritDoc} */ @Override public YearMonth plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { switch ((ChronoUnit) unit) { case MONTHS: return plusMonths(amountToAdd); case YEARS: return plusYears(amountToAdd); case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10)); case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100)); case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000)); case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd)); } throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); } return unit.addTo(this, amountToAdd); }
switch (f) { case MONTH_OF_YEAR: return withMonth((int) newValue); case PROLEPTIC_MONTH: return plusMonths(newValue - getLong(PROLEPTIC_MONTH)); case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue)); case YEAR: return withYear((int) newValue);
switch (f) { case MONTH_OF_YEAR: return withMonth((int) newValue); case PROLEPTIC_MONTH: return plusMonths(newValue - getLong(PROLEPTIC_MONTH)); case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue)); case YEAR: return withYear((int) newValue);