@Override public int indexOf(final CalendarDay day) { return (int) Period .between(min.getDate().withDayOfMonth(1), day.getDate().withDayOfMonth(1)) .toTotalMonths(); }
/** * Returns a copy of this period with the years and months normalized * using a 12 month year. * <p> * This normalizes the years and months units, leaving the days unit unchanged. * The months unit is adjusted to have an absolute value less than 11, * with the years unit being adjusted to compensate. For example, a period of * "1 Year and 15 months" will be normalized to "2 years and 3 months". * <p> * The sign of the years and months units will be the same after normalization. * For example, a period of "1 year and -25 months" will be normalized to * "-1 year and -1 month". * <p> * This normalization uses a 12 month year which is not valid for all calendar systems. * <p> * This instance is immutable and unaffected by this method call. * * @return a {@code Period} based on this period with excess months normalized to years, not null * @throws ArithmeticException if numeric overflow occurs */ public Period normalized() { long totalMonths = toTotalMonths(); long splitYears = totalMonths / 12; int splitMonths = (int) (totalMonths % 12); // no overflow if (splitYears == years && splitMonths == months) { return this; } return create(Jdk8Methods.safeToInt(splitYears), splitMonths, days); }
/** * Returns a copy of this period with the years and months normalized * using a 12 month year. * <p> * This normalizes the years and months units, leaving the days unit unchanged. * The months unit is adjusted to have an absolute value less than 11, * with the years unit being adjusted to compensate. For example, a period of * "1 Year and 15 months" will be normalized to "2 years and 3 months". * <p> * The sign of the years and months units will be the same after normalization. * For example, a period of "1 year and -25 months" will be normalized to * "-1 year and -1 month". * <p> * This normalization uses a 12 month year which is not valid for all calendar systems. * <p> * This instance is immutable and unaffected by this method call. * * @return a {@code Period} based on this period with excess months normalized to years, not null * @throws ArithmeticException if numeric overflow occurs */ public Period normalized() { long totalMonths = toTotalMonths(); long splitYears = totalMonths / 12; int splitMonths = (int) (totalMonths % 12); // no overflow if (splitYears == years && splitMonths == months) { return this; } return create(Jdk8Methods.safeToInt(splitYears), splitMonths, days); }
if (years != 0) { if (months != 0) { temporal = temporal.plus(toTotalMonths(), MONTHS); } else { temporal = temporal.plus(years, YEARS);
if (years != 0) { if (months != 0) { temporal = temporal.minus(toTotalMonths(), MONTHS); } else { temporal = temporal.minus(years, YEARS);
if (years != 0) { if (months != 0) { temporal = temporal.plus(toTotalMonths(), MONTHS); } else { temporal = temporal.plus(years, YEARS);
if (years != 0) { if (months != 0) { temporal = temporal.minus(toTotalMonths(), MONTHS); } else { temporal = temporal.minus(years, YEARS);