/** * Returns a copy of this period with the specified amount subtracted. * <p> * This input amount is converted to a {@code Period} using {@code from(TemporalAmount)}. * This operates separately on the years, months and days. * <p> * For example, "1 year, 6 months and 3 days" minus "2 years, 2 months and 2 days" * returns "-1 years, 4 months and 1 day". * <p> * This instance is immutable and unaffected by this method call. * * @param amountToSubtract the period to subtract, not null * @return a {@code Period} based on this period with the requested period subtracted, not null * @throws ArithmeticException if numeric overflow occurs */ public Period minus(TemporalAmount amountToSubtract) { Period amount = Period.from(amountToSubtract); return create( Jdk8Methods.safeSubtract(years, amount.years), Jdk8Methods.safeSubtract(months, amount.months), Jdk8Methods.safeSubtract(days, amount.days)); }
/** * Returns a copy of this period with the specified amount added. * <p> * This input amount is converted to a {@code Period} using {@code from(TemporalAmount)}. * This operates separately on the years, months and days. * <p> * For example, "1 year, 6 months and 3 days" plus "2 years, 2 months and 2 days" * returns "3 years, 8 months and 5 days". * <p> * This instance is immutable and unaffected by this method call. * * @param amountToAdd the period to add, not null * @return a {@code Period} based on this period with the requested period added, not null * @throws ArithmeticException if numeric overflow occurs */ public Period plus(TemporalAmount amountToAdd) { Period amount = Period.from(amountToAdd); return create( Jdk8Methods.safeAdd(years, amount.years), Jdk8Methods.safeAdd(months, amount.months), Jdk8Methods.safeAdd(days, amount.days)); }
/** * Returns a copy of this period with the specified amount added. * <p> * This input amount is converted to a {@code Period} using {@code from(TemporalAmount)}. * This operates separately on the years, months and days. * <p> * For example, "1 year, 6 months and 3 days" plus "2 years, 2 months and 2 days" * returns "3 years, 8 months and 5 days". * <p> * This instance is immutable and unaffected by this method call. * * @param amountToAdd the period to add, not null * @return a {@code Period} based on this period with the requested period added, not null * @throws ArithmeticException if numeric overflow occurs */ public Period plus(TemporalAmount amountToAdd) { Period amount = Period.from(amountToAdd); return create( Jdk8Methods.safeAdd(years, amount.years), Jdk8Methods.safeAdd(months, amount.months), Jdk8Methods.safeAdd(days, amount.days)); }
/** * Returns a copy of this period with the specified amount subtracted. * <p> * This input amount is converted to a {@code Period} using {@code from(TemporalAmount)}. * This operates separately on the years, months and days. * <p> * For example, "1 year, 6 months and 3 days" minus "2 years, 2 months and 2 days" * returns "-1 years, 4 months and 1 day". * <p> * This instance is immutable and unaffected by this method call. * * @param amountToSubtract the period to subtract, not null * @return a {@code Period} based on this period with the requested period subtracted, not null * @throws ArithmeticException if numeric overflow occurs */ public Period minus(TemporalAmount amountToSubtract) { Period amount = Period.from(amountToSubtract); return create( Jdk8Methods.safeSubtract(years, amount.years), Jdk8Methods.safeSubtract(months, amount.months), Jdk8Methods.safeSubtract(days, amount.days)); }