Refine search
/** * Converts this object to a <code>LocalDate</code> with the * same date and chronology. * * @return a LocalDate with the same date and chronology * @since 1.3 */ public LocalDate toLocalDate() { return new LocalDate(getMillis(), getChronology()); }
/** * Rounds to the highest whole unit of this field on a copy of this DateMidnight. * * @return a copy of the DateMidnight with the field value changed */ public DateMidnight roundCeilingCopy() { return iInstant.withMillis(iField.roundCeiling(iInstant.getMillis())); }
/** * Returns a copy of this date with the specified duration added. * <p> * If the addition is zero, then <code>this</code> is returned. * * @param durationToAdd the duration to add to this one * @param scalar the amount of times to add, such as -1 to subtract once * @return a copy of this datetime with the duration added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateMidnight withDurationAdded(long durationToAdd, int scalar) { if (durationToAdd == 0 || scalar == 0) { return this; } long instant = getChronology().add(getMillis(), durationToAdd, scalar); return withMillis(instant); }
/** * Returns a copy of this date with the partial set of fields replacing those * from this instance. * <p> * For example, if the partial is a <code>LocalDate</code> then the date fields * would be changed in the returned instance. * If the partial is null, then <code>this</code> is returned. * * @param partial the partial set of fields to apply to this datetime, null ignored * @return a copy of this datetime with a different set of fields * @throws IllegalArgumentException if any value is invalid */ public DateMidnight withFields(ReadablePartial partial) { if (partial == null) { return this; } return withMillis(getChronology().set(partial, getMillis())); }
/** * Rounds to the nearest whole unit of this field on a copy of this DateMidnight. * If halfway, the ceiling is favored over the floor only if it makes this field's value even. * * @return a copy of the DateMidnight with the field value changed */ public DateMidnight roundHalfEvenCopy() { return iInstant.withMillis(iField.roundHalfEven(iInstant.getMillis())); }
/** * Converts this object to a <code>LocalDate</code> with the * same date and chronology. * * @return a LocalDate with the same date and chronology * @since 1.3 */ public LocalDate toLocalDate() { return new LocalDate(getMillis(), getChronology()); }
/** * Returns a copy of this date with the specified duration added. * <p> * If the addition is zero, then <code>this</code> is returned. * * @param durationToAdd the duration to add to this one * @param scalar the amount of times to add, such as -1 to subtract once * @return a copy of this datetime with the duration added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateMidnight withDurationAdded(long durationToAdd, int scalar) { if (durationToAdd == 0 || scalar == 0) { return this; } long instant = getChronology().add(getMillis(), durationToAdd, scalar); return withMillis(instant); }
/** * Rounds to the nearest whole unit of this field on a copy of this DateMidnight, * favoring the ceiling if halfway. * * @return a copy of the DateMidnight with the field value changed */ public DateMidnight roundHalfCeilingCopy() { return iInstant.withMillis(iField.roundHalfCeiling(iInstant.getMillis())); }
/** * Converts this object to a <code>YearMonthDay</code> using the * same date and chronology. * * @return a YearMonthDay using the same millis and chronology * @deprecated Use LocalDate instead of YearMonthDay */ @Deprecated public YearMonthDay toYearMonthDay() { return new YearMonthDay(getMillis(), getChronology()); }
/** * Returns a copy of this date with the partial set of fields replacing those * from this instance. * <p> * For example, if the partial is a <code>LocalDate</code> then the date fields * would be changed in the returned instance. * If the partial is null, then <code>this</code> is returned. * * @param partial the partial set of fields to apply to this datetime, null ignored * @return a copy of this datetime with a different set of fields * @throws IllegalArgumentException if any value is invalid */ public DateMidnight withFields(ReadablePartial partial) { if (partial == null) { return this; } return withMillis(getChronology().set(partial, getMillis())); }
/** * Rounds to the lowest whole unit of this field on a copy of this DateMidnight. * * @return a copy of the DateMidnight with the field value changed */ public DateMidnight roundFloorCopy() { return iInstant.withMillis(iField.roundFloor(iInstant.getMillis())); }
/** * Converts this object to a <code>YearMonthDay</code> using the * same date and chronology. * * @return a YearMonthDay using the same millis and chronology * @deprecated Use LocalDate instead of YearMonthDay */ @Deprecated public YearMonthDay toYearMonthDay() { return new YearMonthDay(getMillis(), getChronology()); }
/** * Returns a copy of this date with the specified period added. * <p> * If the addition is zero, then <code>this</code> is returned. * <p> * This method is typically used to add multiple copies of complex * period instances. Adding one field is best achieved using methods * like {@link #withFieldAdded(DurationFieldType, int)} * or {@link #plusYears(int)}. * * @param period the period to add to this one, null means zero * @param scalar the amount of times to add, such as -1 to subtract once * @return a copy of this datetime with the period added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateMidnight withPeriodAdded(ReadablePeriod period, int scalar) { if (period == null || scalar == 0) { return this; } long instant = getChronology().add(period, getMillis(), scalar); return withMillis(instant); }
/** * Rounds to the nearest whole unit of this field on a copy of this DateMidnight, * favoring the floor if halfway. * * @return a copy of the DateMidnight with the field value changed */ public DateMidnight roundHalfFloorCopy() { return iInstant.withMillis(iField.roundHalfFloor(iInstant.getMillis())); }
/** * Returns a copy of this date with a different chronology, potentially * changing the day in unexpected ways. * <p> * This method creates a new DateMidnight using the midnight millisecond value * and the new chronology. If the same or similar chronology is specified, but * with a different time zone, the day may change. This occurs because the new * DateMidnight rounds down the millisecond value to get to midnight, and the * time zone change may result in a rounding down to a different day. * <p> * For example, changing time zone from London (+00:00) to Paris (+01:00) will * retain the same day, but changing from Paris to London will change the day. * (When its midnight in London its the same day in Paris, but when its midnight * in Paris its still the previous day in London) * <p> * To avoid these unusual effects, use {@link #withZoneRetainFields(DateTimeZone)} * to change time zones. * * @param newChronology the new chronology * @return a copy of this instant with a different chronology */ public DateMidnight withChronology(Chronology newChronology) { return (newChronology == getChronology() ? this : new DateMidnight(getMillis(), newChronology)); }
/** * Returns a copy of this date with the specified period added. * <p> * If the addition is zero, then <code>this</code> is returned. * <p> * This method is typically used to add multiple copies of complex * period instances. Adding one field is best achieved using methods * like {@link #withFieldAdded(DurationFieldType, int)} * or {@link #plusYears(int)}. * * @param period the period to add to this one, null means zero * @param scalar the amount of times to add, such as -1 to subtract once * @return a copy of this datetime with the period added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateMidnight withPeriodAdded(ReadablePeriod period, int scalar) { if (period == null || scalar == 0) { return this; } long instant = getChronology().add(period, getMillis(), scalar); return withMillis(instant); }
/** * Rounds to the lowest whole unit of this field on a copy of this DateMidnight. * * @return a copy of the DateMidnight with the field value changed */ public DateMidnight roundFloorCopy() { return iInstant.withMillis(iField.roundFloor(iInstant.getMillis())); }
/** * Returns a copy of this date with a different chronology, potentially * changing the day in unexpected ways. * <p> * This method creates a new DateMidnight using the midnight millisecond value * and the new chronology. If the same or similar chronology is specified, but * with a different time zone, the day may change. This occurs because the new * DateMidnight rounds down the millisecond value to get to midnight, and the * time zone change may result in a rounding down to a different day. * <p> * For example, changing time zone from London (+00:00) to Paris (+01:00) will * retain the same day, but changing from Paris to London will change the day. * (When its midnight in London its the same day in Paris, but when its midnight * in Paris its still the previous day in London) * <p> * To avoid these unusual effects, use {@link #withZoneRetainFields(DateTimeZone)} * to change time zones. * * @param newChronology the new chronology * @return a copy of this instant with a different chronology */ public DateMidnight withChronology(Chronology newChronology) { return (newChronology == getChronology() ? this : new DateMidnight(getMillis(), newChronology)); }
/** * Returns a copy of this date with the era field updated. * <p> * DateMidnight is immutable, so there are no set methods. * Instead, this method returns a new instance with the value of * era changed. * * @param era the era to set * @return a copy of this object with the field set * @throws IllegalArgumentException if the value is invalid * @since 1.3 */ public DateMidnight withEra(int era) { return withMillis(getChronology().era().set(getMillis(), era)); }
/** * Rounds to the highest whole unit of this field on a copy of this DateMidnight. * * @return a copy of the DateMidnight with the field value changed */ public DateMidnight roundCeilingCopy() { return iInstant.withMillis(iField.roundCeiling(iInstant.getMillis())); }