public Temporal plus(final long amountToAdd, final TemporalUnit unit) { if (unit instanceof CalendarDateUnit) { return this.step((int) amountToAdd, (CalendarDateUnit) unit); } else if (unit instanceof ChronoUnit) { return this.toInstant().plus(amountToAdd, unit); } else { return unit.addTo(this, amountToAdd); } }
public Temporal plus(final long amountToAdd, final TemporalUnit unit) { if (unit instanceof CalendarDateUnit) { return this.step((int) amountToAdd, (CalendarDateUnit) unit); } else if (unit instanceof ChronoUnit) { return this.toInstant().plus(amountToAdd, unit); } else { return unit.addTo(this, amountToAdd); } }
/** * Returns a copy of this date-time with the specified period added. * <p> * This method returns a new date-time based on this date-time with the specified period added. * This can be used to add any period that is defined by a unit, for example to add years, months or days. * The unit is responsible for the details of the calculation, including the resolution * of any edge cases in the calculation. * The offset is not part of the calculation and will be unchanged in the result. * <p> * This instance is immutable and unaffected by this method call. * * @param amountToAdd the amount of the unit to add to the result, may be negative * @param unit the unit of the period to add, not null * @return an {@code OffsetDateTime} based on this date-time with the specified period added, not null * @throws DateTimeException if the unit cannot be added to this type */ @Override public OffsetDateTime plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { return with(dateTime.plus(amountToAdd, unit), offset); } return unit.addTo(this, amountToAdd); }
/** * Returns a copy of this time with the specified period added. * <p> * This method returns a new time based on this time with the specified period added. * This can be used to add any period that is defined by a unit, for example to add hours, minutes or seconds. * The unit is responsible for the details of the calculation, including the resolution * of any edge cases in the calculation. * The offset is not part of the calculation and will be unchanged in the result. * <p> * This instance is immutable and unaffected by this method call. * * @param amountToAdd the amount of the unit to add to the result, may be negative * @param unit the unit of the period to add, not null * @return an {@code OffsetTime} based on this time with the specified period added, not null * @throws DateTimeException if the unit cannot be added to this type */ @Override public OffsetTime plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { return with(time.plus(amountToAdd, unit), offset); } return unit.addTo(this, amountToAdd); }
@Override public ChronoZonedDateTime<D> plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { return with(dateTime.plus(amountToAdd, unit)); } return toLocalDate().getChronology().ensureChronoZonedDateTime(unit.addTo(this, amountToAdd)); /// TODO: Generics replacement Risk! }
return unit.addTo(this, amountToAdd);
/** * {@inheritDoc} * @throws DateTimeException {@inheritDoc} * @throws ArithmeticException {@inheritDoc} */ @Override public Instant plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { switch ((ChronoUnit) unit) { case NANOS: return plusNanos(amountToAdd); case MICROS: return plus(amountToAdd / 1000000, (amountToAdd % 1000000) * 1000); case MILLIS: return plusMillis(amountToAdd); case SECONDS: return plusSeconds(amountToAdd); case MINUTES: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_MINUTE)); case HOURS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_HOUR)); case HALF_DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY / 2)); case DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY)); } throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); } return unit.addTo(this, amountToAdd); }
return unit.addTo(this, amountToAdd);
/** * {@inheritDoc} * @throws DateTimeException {@inheritDoc} * @throws ArithmeticException {@inheritDoc} */ @Override public Year plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { switch ((ChronoUnit) unit) { 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); }
@Override public ChronoLocalDateTimeImpl<D> plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { ChronoUnit f = (ChronoUnit) unit; switch (f) { case NANOS: return plusNanos(amountToAdd); case MICROS: return plusDays(amountToAdd / MICROS_PER_DAY).plusNanos((amountToAdd % MICROS_PER_DAY) * 1000); case MILLIS: return plusDays(amountToAdd / MILLIS_PER_DAY).plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000); case SECONDS: return plusSeconds(amountToAdd); case MINUTES: return plusMinutes(amountToAdd); case HOURS: return plusHours(amountToAdd); case HALF_DAYS: return plusDays(amountToAdd / 256).plusHours((amountToAdd % 256) * 12); // no overflow (256 is multiple of 2) } return with(date.plus(amountToAdd, unit), time); } return date.getChronology().ensureChronoLocalDateTime(unit.addTo(this, amountToAdd)); }
return unit.addTo(this, amountToAdd);
@Override public AbstractDate plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { ChronoUnit f = (ChronoUnit) unit; switch (f) { case DAYS: return plusDays(amountToAdd); case WEEKS: return plusWeeks(amountToAdd); case MONTHS: return plusMonths(amountToAdd); case YEARS: return plusYears(amountToAdd); case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10)); case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100)); case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000)); case ERAS: return with(ERA, Math.addExact(getLong(ERA), amountToAdd)); default: break; } throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); } return unit.addTo(this, amountToAdd); }
return unit.addTo(this, amountToAdd);
@SuppressWarnings("unchecked") @Override public ChronoDateImpl<D> plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { ChronoUnit f = (ChronoUnit) unit; switch (f) { case DAYS: return plusDays(amountToAdd); case WEEKS: return plusDays(Jdk8Methods.safeMultiply(amountToAdd, 7)); 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: throw new DateTimeException("Unable to add era, standard calendar system only has one era"); // case FOREVER: return (period == 0 ? this : (period > 0 ? LocalDate.MAX_DATE : LocalDate.MIN_DATE)); } throw new DateTimeException(unit + " not valid for chronology " + getChronology().getId()); } return (ChronoDateImpl<D>) getChronology().ensureChronoLocalDate(unit.addTo(this, amountToAdd)); }
return unit.addTo(this, amountToAdd);