public DurationField getField(Chronology chronology) { return new ScaledDurationField(chronology.years(), Centuries, 100); } };
public DurationField getField(Chronology chronology) { return new ScaledDurationField(chronology.years(), Decades, 10); } };
/** * Returns a copy of this datetime minus the specified number of years. * <p> * The calculation will do its best to only change the year field * retaining the same month of year. * However, in certain circumstances, it may be necessary to alter * smaller fields. For example, 2008-02-29 minus one year cannot result * in 2007-02-29, so the day of month is adjusted to 2007-02-28. * <p> * The following three lines are identical in effect: * <pre> * DateTime subtracted = dt.minusYears(6); * DateTime subtracted = dt.minus(Period.years(6)); * DateTime subtracted = dt.withFieldAdded(DurationFieldType.years(), -6); * </pre> * <p> * This datetime instance is immutable and unaffected by this method call. * * @param years the amount of years to subtract, may be negative * @return the new datetime minus the increased years * @since 1.1 */ public DateTime minusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().subtract(getMillis(), years); return withMillis(instant); }
/** * Returns a copy of this datetime plus the specified number of years. * <p> * The calculation will do its best to only change the year field * retaining the same month of year. * However, in certain circumstances, it may be necessary to alter * smaller fields. For example, 2008-02-29 plus one year cannot result * in 2009-02-29, so the day of month is adjusted to 2009-02-28. * <p> * The following three lines are identical in effect: * <pre> * DateTime added = dt.plusYears(6); * DateTime added = dt.plus(Period.years(6)); * DateTime added = dt.withFieldAdded(DurationFieldType.years(), 6); * </pre> * <p> * This datetime instance is immutable and unaffected by this method call. * * @param years the amount of years to add, may be negative * @return the new datetime plus the increased years * @since 1.1 */ public DateTime plusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().add(getMillis(), years); return withMillis(instant); }
/** * Add a number of years to the date. * * @param years the years to add * @throws IllegalArgumentException if the value is invalid */ public void addYears(final int years) { if (years != 0) { setMillis(getChronology().years().add(getMillis(), years)); } }
/** * Add a number of years to the date. * * @param years the years to add * @throws IllegalArgumentException if the value is invalid */ public void addYears(final int years) { if (years != 0) { setMillis(getChronology().years().add(getMillis(), years)); } }
/** * Returns a copy of this datetime plus the specified number of years. * <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.plusYears(6); * LocalDateTime added = dt.plus(Period.years(6)); * LocalDateTime added = dt.withFieldAdded(DurationFieldType.years(), 6); * </pre> * * @param years the amount of years to add, may be negative * @return the new LocalDateTime plus the increased years */ public LocalDateTime plusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().add(getLocalMillis(), years); return withLocalMillis(instant); }
/** * Returns a copy of this datetime minus the specified number of years. * <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.minusYears(6); * LocalDateTime subtracted = dt.minus(Period.years(6)); * LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.years(), -6); * </pre> * * @param years the amount of years to subtract, may be negative * @return the new LocalDateTime minus the increased years */ public LocalDateTime minusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().subtract(getLocalMillis(), years); return withLocalMillis(instant); }
/** * Returns a copy of this date minus the specified number of years. * <p> * This datetime instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * DateTime subtracted = dt.minusYears(6); * DateTime subtracted = dt.minus(Period.years(6)); * DateTime subtracted = dt.withFieldAdded(DurationFieldType.years(), -6); * </pre> * * @param years the amount of years to subtract, may be negative * @return the new datetime minus the increased years * @since 1.1 */ public DateMidnight minusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().subtract(getMillis(), years); return withMillis(instant); }
/** * Returns a copy of this date plus the specified number of years. * <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.plusYears(6); * DateMidnight added = dt.plus(Period.years(6)); * DateMidnight added = dt.withFieldAdded(DurationFieldType.years(), 6); * </pre> * * @param years the amount of years to add, may be negative * @return the new datetime plus the increased years * @since 1.1 */ public DateMidnight plusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().add(getMillis(), years); return withMillis(instant); }
/** * Returns a copy of this date plus the specified number of years. * <p> * This adds the specified number of years to the date. * If adding years 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.plusYears(6); * LocalDate added = dt.plus(Period.years(6)); * LocalDate added = dt.withFieldAdded(DurationFieldType.years(), 6); * </pre> * * @param years the amount of years to add, may be negative * @return the new LocalDate plus the increased years */ public LocalDate plusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().add(getLocalMillis(), years); return withLocalMillis(instant); }
/** * Returns a copy of this datetime minus the specified number of years. * <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.minusYears(6); * LocalDateTime subtracted = dt.minus(Period.years(6)); * LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.years(), -6); * </pre> * * @param years the amount of years to subtract, may be negative * @return the new LocalDateTime minus the increased years */ public LocalDateTime minusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().subtract(getLocalMillis(), years); return withLocalMillis(instant); }
/** * Returns a copy of this date minus the specified number of years. * <p> * This subtracts the specified number of years from the date. * If subtracting years 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.minusYears(6); * LocalDate subtracted = dt.minus(Period.years(6)); * LocalDate subtracted = dt.withFieldAdded(DurationFieldType.years(), -6); * </pre> * * @param years the amount of years to subtract, may be negative * @return the new LocalDate minus the increased years */ public LocalDate minusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().subtract(getLocalMillis(), years); return withLocalMillis(instant); }
/** * Returns a copy of this datetime plus the specified number of years. * <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.plusYears(6); * LocalDateTime added = dt.plus(Period.years(6)); * LocalDateTime added = dt.withFieldAdded(DurationFieldType.years(), 6); * </pre> * * @param years the amount of years to add, may be negative * @return the new LocalDateTime plus the increased years */ public LocalDateTime plusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().add(getLocalMillis(), years); return withLocalMillis(instant); }
/** * Returns a copy of this date minus the specified number of years. * <p> * This datetime instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * DateTime subtracted = dt.minusYears(6); * DateTime subtracted = dt.minus(Period.years(6)); * DateTime subtracted = dt.withFieldAdded(DurationFieldType.years(), -6); * </pre> * * @param years the amount of years to subtract, may be negative * @return the new datetime minus the increased years * @since 1.1 */ public DateMidnight minusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().subtract(getMillis(), years); return withMillis(instant); }
/** * Returns a copy of this date plus the specified number of years. * <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.plusYears(6); * DateMidnight added = dt.plus(Period.years(6)); * DateMidnight added = dt.withFieldAdded(DurationFieldType.years(), 6); * </pre> * * @param years the amount of years to add, may be negative * @return the new datetime plus the increased years * @since 1.1 */ public DateMidnight plusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().add(getMillis(), years); return withMillis(instant); }
/** * Returns a copy of this date plus the specified number of years. * <p> * This adds the specified number of years to the date. * If adding years 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.plusYears(6); * LocalDate added = dt.plus(Period.years(6)); * LocalDate added = dt.withFieldAdded(DurationFieldType.years(), 6); * </pre> * * @param years the amount of years to add, may be negative * @return the new LocalDate plus the increased years */ public LocalDate plusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().add(getLocalMillis(), years); return withLocalMillis(instant); }
/** * Returns a copy of this date minus the specified number of years. * <p> * This subtracts the specified number of years from the date. * If subtracting years 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.minusYears(6); * LocalDate subtracted = dt.minus(Period.years(6)); * LocalDate subtracted = dt.withFieldAdded(DurationFieldType.years(), -6); * </pre> * * @param years the amount of years to subtract, may be negative * @return the new LocalDate minus the increased years */ public LocalDate minusYears(int years) { if (years == 0) { return this; } long instant = getChronology().years().subtract(getLocalMillis(), years); return withLocalMillis(instant); }
/** * Creates a <code>Years</code> representing the number of whole years * 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. * * @param start the start partial date, must not be null * @param end the end partial date, must not be null * @return the period in years * @throws IllegalArgumentException if the partials are null or invalid */ public static Years yearsBetween(ReadablePartial start, ReadablePartial end) { if (start instanceof LocalDate && end instanceof LocalDate) { Chronology chrono = DateTimeUtils.getChronology(start.getChronology()); int years = chrono.years().getDifference( ((LocalDate) end).getLocalMillis(), ((LocalDate) start).getLocalMillis()); return Years.years(years); } int amount = BaseSingleFieldPeriod.between(start, end, ZERO); return Years.years(amount); }
/** * Creates a <code>Years</code> representing the number of whole years * 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. * * @param start the start partial date, must not be null * @param end the end partial date, must not be null * @return the period in years * @throws IllegalArgumentException if the partials are null or invalid */ public static Years yearsBetween(ReadablePartial start, ReadablePartial end) { if (start instanceof LocalDate && end instanceof LocalDate) { Chronology chrono = DateTimeUtils.getChronology(start.getChronology()); int years = chrono.years().getDifference( ((LocalDate) end).getLocalMillis(), ((LocalDate) start).getLocalMillis()); return Years.years(years); } int amount = BaseSingleFieldPeriod.between(start, end, ZERO); return Years.years(amount); }