/** * Returns a copy of this datetime plus the specified number of weeks. * <p> * The calculation operates as if it were adding the equivalent in days. * <p> * The following three lines are identical in effect: * <pre> * DateTime added = dt.plusWeeks(6); * DateTime added = dt.plus(Period.weeks(6)); * DateTime added = dt.withFieldAdded(DurationFieldType.weeks(), 6); * </pre> * <p> * This datetime instance is immutable and unaffected by this method call. * * @param weeks the amount of weeks to add, may be negative * @return the new datetime plus the increased weeks * @since 1.1 */ public DateTime plusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().add(getMillis(), weeks); return withMillis(instant); }
/** * Returns a copy of this datetime minus the specified number of weeks. * <p> * The calculation operates as if it were subtracting the equivalent in days. * <p> * The following three lines are identical in effect: * <pre> * DateTime subtracted = dt.minusWeeks(6); * DateTime subtracted = dt.minus(Period.weeks(6)); * DateTime subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6); * </pre> * <p> * This datetime instance is immutable and unaffected by this method call. * * @param weeks the amount of weeks to subtract, may be negative * @return the new datetime minus the increased weeks * @since 1.1 */ public DateTime minusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().subtract(getMillis(), weeks); return withMillis(instant); }
/** * Returns a copy of this datetime plus the specified number of weeks. * <p> * The calculation operates as if it were adding the equivalent in days. * <p> * The following three lines are identical in effect: * <pre> * DateTime added = dt.plusWeeks(6); * DateTime added = dt.plus(Period.weeks(6)); * DateTime added = dt.withFieldAdded(DurationFieldType.weeks(), 6); * </pre> * <p> * This datetime instance is immutable and unaffected by this method call. * * @param weeks the amount of weeks to add, may be negative * @return the new datetime plus the increased weeks * @since 1.1 */ public DateTime plusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().add(getMillis(), weeks); return withMillis(instant); }
/** * Returns a copy of this datetime minus the specified number of weeks. * <p> * The calculation operates as if it were subtracting the equivalent in days. * <p> * The following three lines are identical in effect: * <pre> * DateTime subtracted = dt.minusWeeks(6); * DateTime subtracted = dt.minus(Period.weeks(6)); * DateTime subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6); * </pre> * <p> * This datetime instance is immutable and unaffected by this method call. * * @param weeks the amount of weeks to subtract, may be negative * @return the new datetime minus the increased weeks * @since 1.1 */ public DateTime minusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().subtract(getMillis(), weeks); return withMillis(instant); }
/** * Add a number of weeks to the date. * * @param weeks the weeks to add * @throws IllegalArgumentException if the value is invalid */ public void addWeeks(final int weeks) { if (weeks != 0) { setMillis(getChronology().weeks().add(getMillis(), weeks)); } }
/** * Add a number of weeks to the date. * * @param weeks the weeks to add * @throws IllegalArgumentException if the value is invalid */ public void addWeeks(final int weeks) { if (weeks != 0) { setMillis(getChronology().weeks().add(getMillis(), weeks)); } }
/** * Returns a copy of this date plus the specified number of weeks. * <p> * This LocalDate instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * LocalDate added = dt.plusWeeks(6); * LocalDate added = dt.plus(Period.weeks(6)); * LocalDate added = dt.withFieldAdded(DurationFieldType.weeks(), 6); * </pre> * * @param weeks the amount of weeks to add, may be negative * @return the new LocalDate plus the increased weeks */ public LocalDate plusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().add(getLocalMillis(), weeks); return withLocalMillis(instant); }
/** * Returns a copy of this date minus the specified number of weeks. * <p> * This LocalDate instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * LocalDate subtracted = dt.minusWeeks(6); * LocalDate subtracted = dt.minus(Period.weeks(6)); * LocalDate subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6); * </pre> * * @param weeks the amount of weeks to subtract, may be negative * @return the new LocalDate minus the increased weeks */ public LocalDate minusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().subtract(getLocalMillis(), weeks); return withLocalMillis(instant); }
/** * Returns a copy of this datetime plus the specified number of weeks. * <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.plusWeeks(6); * LocalDateTime added = dt.plus(Period.weeks(6)); * LocalDateTime added = dt.withFieldAdded(DurationFieldType.weeks(), 6); * </pre> * * @param weeks the amount of weeks to add, may be negative * @return the new LocalDateTime plus the increased weeks */ public LocalDateTime plusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().add(getLocalMillis(), weeks); return withLocalMillis(instant); }
/** * Returns a copy of this datetime minus the specified number of weeks. * <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.minusWeeks(6); * LocalDateTime subtracted = dt.minus(Period.weeks(6)); * LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6); * </pre> * * @param weeks the amount of weeks to subtract, may be negative * @return the new LocalDateTime minus the increased weeks */ public LocalDateTime minusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().subtract(getLocalMillis(), weeks); return withLocalMillis(instant); }
/** * Returns a copy of this date plus the specified number of weeks. * <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.plusWeeks(6); * DateMidnight added = dt.plus(Period.weeks(6)); * DateMidnight added = dt.withFieldAdded(DurationFieldType.weeks(), 6); * </pre> * * @param weeks the amount of weeks to add, may be negative * @return the new datetime plus the increased weeks * @since 1.1 */ public DateMidnight plusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().add(getMillis(), weeks); return withMillis(instant); }
/** * Returns a copy of this date minus the specified number of weeks. * <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.minusWeeks(6); * DateMidnight subtracted = dt.minus(Period.weeks(6)); * DateMidnight subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6); * </pre> * * @param weeks the amount of weeks to subtract, may be negative * @return the new datetime minus the increased weeks * @since 1.1 */ public DateMidnight minusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().subtract(getMillis(), weeks); return withMillis(instant); }
/** * Returns a copy of this date plus the specified number of weeks. * <p> * This LocalDate instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * LocalDate added = dt.plusWeeks(6); * LocalDate added = dt.plus(Period.weeks(6)); * LocalDate added = dt.withFieldAdded(DurationFieldType.weeks(), 6); * </pre> * * @param weeks the amount of weeks to add, may be negative * @return the new LocalDate plus the increased weeks */ public LocalDate plusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().add(getLocalMillis(), weeks); return withLocalMillis(instant); }
/** * Returns a copy of this date minus the specified number of weeks. * <p> * This LocalDate instance is immutable and unaffected by this method call. * <p> * The following three lines are identical in effect: * <pre> * LocalDate subtracted = dt.minusWeeks(6); * LocalDate subtracted = dt.minus(Period.weeks(6)); * LocalDate subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6); * </pre> * * @param weeks the amount of weeks to subtract, may be negative * @return the new LocalDate minus the increased weeks */ public LocalDate minusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().subtract(getLocalMillis(), weeks); return withLocalMillis(instant); }
/** * Returns a copy of this datetime plus the specified number of weeks. * <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.plusWeeks(6); * LocalDateTime added = dt.plus(Period.weeks(6)); * LocalDateTime added = dt.withFieldAdded(DurationFieldType.weeks(), 6); * </pre> * * @param weeks the amount of weeks to add, may be negative * @return the new LocalDateTime plus the increased weeks */ public LocalDateTime plusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().add(getLocalMillis(), weeks); return withLocalMillis(instant); }
/** * Returns a copy of this datetime minus the specified number of weeks. * <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.minusWeeks(6); * LocalDateTime subtracted = dt.minus(Period.weeks(6)); * LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6); * </pre> * * @param weeks the amount of weeks to subtract, may be negative * @return the new LocalDateTime minus the increased weeks */ public LocalDateTime minusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().subtract(getLocalMillis(), weeks); return withLocalMillis(instant); }
/** * Returns a copy of this date plus the specified number of weeks. * <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.plusWeeks(6); * DateMidnight added = dt.plus(Period.weeks(6)); * DateMidnight added = dt.withFieldAdded(DurationFieldType.weeks(), 6); * </pre> * * @param weeks the amount of weeks to add, may be negative * @return the new datetime plus the increased weeks * @since 1.1 */ public DateMidnight plusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().add(getMillis(), weeks); return withMillis(instant); }
/** * Returns a copy of this date minus the specified number of weeks. * <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.minusWeeks(6); * DateMidnight subtracted = dt.minus(Period.weeks(6)); * DateMidnight subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6); * </pre> * * @param weeks the amount of weeks to subtract, may be negative * @return the new datetime minus the increased weeks * @since 1.1 */ public DateMidnight minusWeeks(int weeks) { if (weeks == 0) { return this; } long instant = getChronology().weeks().subtract(getMillis(), weeks); return withMillis(instant); }
/** * Creates a <code>Weeks</code> representing the number of whole weeks * 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 weeks * @throws IllegalArgumentException if the partials are null or invalid */ public static Weeks weeksBetween(ReadablePartial start, ReadablePartial end) { if (start instanceof LocalDate && end instanceof LocalDate) { Chronology chrono = DateTimeUtils.getChronology(start.getChronology()); int weeks = chrono.weeks().getDifference( ((LocalDate) end).getLocalMillis(), ((LocalDate) start).getLocalMillis()); return Weeks.weeks(weeks); } int amount = BaseSingleFieldPeriod.between(start, end, ZERO); return Weeks.weeks(amount); }
/** * Creates a <code>Weeks</code> representing the number of whole weeks * 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 weeks * @throws IllegalArgumentException if the partials are null or invalid */ public static Weeks weeksBetween(ReadablePartial start, ReadablePartial end) { if (start instanceof LocalDate && end instanceof LocalDate) { Chronology chrono = DateTimeUtils.getChronology(start.getChronology()); int weeks = chrono.weeks().getDifference( ((LocalDate) end).getLocalMillis(), ((LocalDate) start).getLocalMillis()); return Weeks.weeks(weeks); } int amount = BaseSingleFieldPeriod.between(start, end, ZERO); return Weeks.weeks(amount); }