/** * Returns a copy of this year with the specified number of years subtracted. * <p> * This instance is immutable and unaffected by this method call. * * @param yearsToSubtract the years to subtract, may be negative * @return a {@code Year} based on this year with the period subtracted, not null * @throws DateTimeException if the result exceeds the supported year range */ public Year minusYears(long yearsToSubtract) { return (yearsToSubtract == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-yearsToSubtract)); }
/** * Returns a {@link java.time.Year} that is {@code years} years after this year. * * @param self a Year * @param years the number of years to add * @return a Year * @since 2.5.0 */ public static Year plus(final Year self, long years) { return self.plusYears(years); }
/** * 年の加算を実行します * * @param date * 日付型 * @param years * 加算する年 * @return 年を加算した結果のカレンダー */ public static Year addYears(final Year date, final int years) { if (date == null) { return null; } return date.plusYears(years); }
/** * {@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); }
private String convertFromMarcDate(String date) { if (date.indexOf('|') >= 0) { // invalid date / no date return null; } try { // yy maps to 2000-2099 which is wrong, cataloging era is somewhere around 1970-2070 LocalDate localDatetime = LocalDate.parse(date, formatter); // adjust year. If in the future, subtract 100 to go back to 20th century cataloging. // one year tolerance, maybe "future cataloging" if (localDatetime.getYear() > Year.now().plusYears(1).getValue()) { localDatetime = localDatetime.minusYears(100); } return localDatetime.toString(); } catch (Exception e) { logger.log(Level.WARNING, "unable to convert date: " + date, e); return date; } } }