@Override public DurationField getField(Chronology chronology) { return new ScaledDurationField(chronology.months(), QUARTER_OF_YEAR_DURATION_FIELD_TYPE, 3); } }
public DurationField getField(Chronology chronology) { return new ScaledDurationField(chronology.months(), Quarters, 3); } };
public DurationField getField(Chronology chronology) { return new ScaledDurationField(chronology.months(), HalfYears, 6); } };
/** * Returns a copy of this datetime plus the specified number of months. * <p> * The calculation will do its best to only change the month field * retaining the same day of month. * However, in certain circumstances, it may be necessary to alter * smaller fields. For example, 2007-03-31 plus one month cannot result * in 2007-04-31, so the day of month is adjusted to 2007-04-30. * <p> * The following three lines are identical in effect: * <pre> * DateTime added = dt.plusMonths(6); * DateTime added = dt.plus(Period.months(6)); * DateTime added = dt.withFieldAdded(DurationFieldType.months(), 6); * </pre> * <p> * This datetime instance is immutable and unaffected by this method call. * * @param months the amount of months to add, may be negative * @return the new datetime plus the increased months * @since 1.1 */ public DateTime plusMonths(int months) { if (months == 0) { return this; } long instant = getChronology().months().add(getMillis(), months); return withMillis(instant); }
/** * Returns a copy of this datetime minus the specified number of months. * <p> * The calculation will do its best to only change the month field * retaining the same day of month. * However, in certain circumstances, it may be necessary to alter * smaller fields. For example, 2007-05-31 minus one month cannot result * in 2007-04-31, so the day of month is adjusted to 2007-04-30. * <p> * The following three lines are identical in effect: * <pre> * DateTime subtracted = dt.minusMonths(6); * DateTime subtracted = dt.minus(Period.months(6)); * DateTime subtracted = dt.withFieldAdded(DurationFieldType.months(), -6); * </pre> * <p> * This datetime instance is immutable and unaffected by this method call. * * @param months the amount of months to subtract, may be negative * @return the new datetime minus the increased months * @since 1.1 */ public DateTime minusMonths(int months) { if (months == 0) { return this; } long instant = getChronology().months().subtract(getMillis(), months); return withMillis(instant); }
/** * Add a number of months to the date. * * @param months the months to add * @throws IllegalArgumentException if the value is invalid */ public void addMonths(final int months) { if (months != 0) { setMillis(getChronology().months().add(getMillis(), months)); } }
/** * Add a number of months to the date. * * @param months the months to add * @throws IllegalArgumentException if the value is invalid */ public void addMonths(final int months) { if (months != 0) { setMillis(getChronology().months().add(getMillis(), months)); } }
/** * Returns a copy of this date plus the specified number of months. * <p> * This datetime instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * DateMidnight added = dt.plusMonths(6); * DateMidnight added = dt.plus(Period.months(6)); * DateMidnight added = dt.withFieldAdded(DurationFieldType.months(), 6); * </pre> * * @param months the amount of months to add, may be negative * @return the new datetime plus the increased months * @since 1.1 */ public DateMidnight plusMonths(int months) { if (months == 0) { return this; } long instant = getChronology().months().add(getMillis(), months); return withMillis(instant); }
/** * Returns a copy of this datetime plus the specified number of months. * <p> * This LocalDateTime instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * LocalDateTime added = dt.plusMonths(6); * LocalDateTime added = dt.plus(Period.months(6)); * LocalDateTime added = dt.withFieldAdded(DurationFieldType.months(), 6); * </pre> * * @param months the amount of months to add, may be negative * @return the new LocalDateTime plus the increased months */ public LocalDateTime plusMonths(int months) { if (months == 0) { return this; } long instant = getChronology().months().add(getLocalMillis(), months); return withLocalMillis(instant); }
/** * Returns a copy of this datetime minus the specified number of months. * <p> * This LocalDateTime instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * LocalDateTime subtracted = dt.minusMonths(6); * LocalDateTime subtracted = dt.minus(Period.months(6)); * LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.months(), -6); * </pre> * * @param months the amount of months to subtract, may be negative * @return the new LocalDateTime minus the increased months */ public LocalDateTime minusMonths(int months) { if (months == 0) { return this; } long instant = getChronology().months().subtract(getLocalMillis(), months); return withLocalMillis(instant); }
/** * Returns a copy of this date minus the specified number of months. * <p> * This datetime instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * DateMidnight subtracted = dt.minusMonths(6); * DateMidnight subtracted = dt.minus(Period.months(6)); * DateMidnight subtracted = dt.withFieldAdded(DurationFieldType.months(), -6); * </pre> * * @param months the amount of months to subtract, may be negative * @return the new datetime minus the increased months * @since 1.1 */ public DateMidnight minusMonths(int months) { if (months == 0) { return this; } long instant = getChronology().months().subtract(getMillis(), months); return withMillis(instant); }
/** * Returns a copy of this datetime minus the specified number of months. * <p> * This LocalDateTime instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * LocalDateTime subtracted = dt.minusMonths(6); * LocalDateTime subtracted = dt.minus(Period.months(6)); * LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.months(), -6); * </pre> * * @param months the amount of months to subtract, may be negative * @return the new LocalDateTime minus the increased months */ public LocalDateTime minusMonths(int months) { if (months == 0) { return this; } long instant = getChronology().months().subtract(getLocalMillis(), months); return withLocalMillis(instant); }
/** * Returns a copy of this date minus the specified number of months. * <p> * This subtracts the specified number of months from the date. * The subtraction may change the year, but the day-of-month is normally unchanged. * If subtracting months makes the day-of-month invalid, it is adjusted to the last valid day in the month. * This LocalDate instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * LocalDate subtracted = dt.minusMonths(6); * LocalDate subtracted = dt.minus(Period.months(6)); * LocalDate subtracted = dt.withFieldAdded(DurationFieldType.months(), -6); * </pre> * * @param months the amount of months to subtract, may be negative * @return the new LocalDate minus the increased months */ public LocalDate minusMonths(int months) { if (months == 0) { return this; } long instant = getChronology().months().subtract(getLocalMillis(), months); return withLocalMillis(instant); }
/** * Returns a copy of this date plus the specified number of months. * <p> * This datetime instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * DateMidnight added = dt.plusMonths(6); * DateMidnight added = dt.plus(Period.months(6)); * DateMidnight added = dt.withFieldAdded(DurationFieldType.months(), 6); * </pre> * * @param months the amount of months to add, may be negative * @return the new datetime plus the increased months * @since 1.1 */ public DateMidnight plusMonths(int months) { if (months == 0) { return this; } long instant = getChronology().months().add(getMillis(), months); return withMillis(instant); }
/** * Returns a copy of this datetime plus the specified number of months. * <p> * This LocalDateTime instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * LocalDateTime added = dt.plusMonths(6); * LocalDateTime added = dt.plus(Period.months(6)); * LocalDateTime added = dt.withFieldAdded(DurationFieldType.months(), 6); * </pre> * * @param months the amount of months to add, may be negative * @return the new LocalDateTime plus the increased months */ public LocalDateTime plusMonths(int months) { if (months == 0) { return this; } long instant = getChronology().months().add(getLocalMillis(), months); return withLocalMillis(instant); }
/** * Returns a copy of this date plus the specified number of months. * <p> * This adds the specified number of months to the date. * The addition may change the year, but the day-of-month is normally unchanged. * If adding months makes the day-of-month invalid, it is adjusted to the last valid day in the month. * This LocalDate instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * LocalDate added = dt.plusMonths(6); * LocalDate added = dt.plus(Period.months(6)); * LocalDate added = dt.withFieldAdded(DurationFieldType.months(), 6); * </pre> * * @param months the amount of months to add, may be negative * @return the new LocalDate plus the increased months */ public LocalDate plusMonths(int months) { if (months == 0) { return this; } long instant = getChronology().months().add(getLocalMillis(), months); return withLocalMillis(instant); }
/** * Returns a copy of this date minus the specified number of months. * <p> * This datetime instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * DateMidnight subtracted = dt.minusMonths(6); * DateMidnight subtracted = dt.minus(Period.months(6)); * DateMidnight subtracted = dt.withFieldAdded(DurationFieldType.months(), -6); * </pre> * * @param months the amount of months to subtract, may be negative * @return the new datetime minus the increased months * @since 1.1 */ public DateMidnight minusMonths(int months) { if (months == 0) { return this; } long instant = getChronology().months().subtract(getMillis(), months); return withMillis(instant); }
/** * Returns a copy of this date plus the specified number of months. * <p> * This adds the specified number of months to the date. * The addition may change the year, but the day-of-month is normally unchanged. * If adding months makes the day-of-month invalid, it is adjusted to the last valid day in the month. * This LocalDate instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * LocalDate added = dt.plusMonths(6); * LocalDate added = dt.plus(Period.months(6)); * LocalDate added = dt.withFieldAdded(DurationFieldType.months(), 6); * </pre> * * @param months the amount of months to add, may be negative * @return the new LocalDate plus the increased months */ public LocalDate plusMonths(int months) { if (months == 0) { return this; } long instant = getChronology().months().add(getLocalMillis(), months); return withLocalMillis(instant); }
/** * Creates a <code>Months</code> representing the number of whole months * between the two specified partial datetimes. * <p> * The two partials must contain the same fields, for example you can specify * two <code>LocalDate</code> objects. * <p> * This method calculates by adding months to the start date until the result * is past the end date. As such, a period from the end of a "long" month to * the end of a "short" month is counted as a whole month. * * @param start the start partial date, must not be null * @param end the end partial date, must not be null * @return the period in months * @throws IllegalArgumentException if the partials are null or invalid */ public static Months monthsBetween(ReadablePartial start, ReadablePartial end) { if (start instanceof LocalDate && end instanceof LocalDate) { Chronology chrono = DateTimeUtils.getChronology(start.getChronology()); int months = chrono.months().getDifference( ((LocalDate) end).getLocalMillis(), ((LocalDate) start).getLocalMillis()); return Months.months(months); } int amount = BaseSingleFieldPeriod.between(start, end, ZERO); return Months.months(amount); }
return chronology.years(); case MONTHS: return chronology.months(); case WEEKS: return chronology.weeks();