public static final class DateMidnight.Property extends AbstractReadableInstantFieldProperty
The simplest use of this class is as an alternative get method, here used to get the year '1972' (as an int) and the month 'December' (as a String).
DateMidnight dt = new DateMidnight(1972, 12, 3); int year = dt.year().get(); String monthStr = dt.monthOfYear().getAsText();
Methods are also provided that allow date modification. These return new instances of DateMidnight - they do not modify the original. The example below yields two independent immutable date objects 20 years apart.
DateMidnight dt = new DateMidnight(1972, 12, 3); DateMidnight dt20 = dt.year().addToCopy(20);Serious modification of dates (ie. more than just changing one or two fields) should use the
MutableDateTime
class.
DateMidnight.Property itself is thread-safe and immutable.
Modifier and Type | Method and Description |
---|---|
DateMidnight |
addToCopy(int value)
Adds to this field in a copy of this DateMidnight.
|
DateMidnight |
addToCopy(long value)
Adds to this field in a copy of this DateMidnight.
|
DateMidnight |
addWrapFieldToCopy(int value)
Adds to this field, possibly wrapped, in a copy of this DateMidnight.
|
DateMidnight |
getDateMidnight()
Gets the datetime being used.
|
DateTimeField |
getField()
Gets the field being used.
|
DateMidnight |
roundCeilingCopy()
Rounds to the highest whole unit of this field on a copy of this DateMidnight.
|
DateMidnight |
roundFloorCopy()
Rounds to the lowest whole unit of this field on a copy of this DateMidnight.
|
DateMidnight |
roundHalfCeilingCopy()
Rounds to the nearest whole unit of this field on a copy of this DateMidnight,
favoring the ceiling if halfway.
|
DateMidnight |
roundHalfEvenCopy()
Rounds to the nearest whole unit of this field on a copy of this DateMidnight.
|
DateMidnight |
roundHalfFloorCopy()
Rounds to the nearest whole unit of this field on a copy of this DateMidnight,
favoring the floor if halfway.
|
DateMidnight |
setCopy(int value)
Sets this field in a copy of the DateMidnight.
|
DateMidnight |
setCopy(java.lang.String text)
Sets this field in a copy of the DateMidnight to a parsed text value.
|
DateMidnight |
setCopy(java.lang.String text,
java.util.Locale locale)
Sets this field in a copy of the DateMidnight to a parsed text value.
|
DateMidnight |
withMaximumValue()
Returns a new DateMidnight with this field set to the maximum value
for this field.
|
DateMidnight |
withMinimumValue()
Returns a new DateMidnight with this field set to the minimum value
for this field.
|
compareTo, compareTo, equals, get, getAsShortText, getAsShortText, getAsString, getAsText, getAsText, getDifference, getDifferenceAsLong, getDurationField, getFieldType, getLeapAmount, getLeapDurationField, getMaximumShortTextLength, getMaximumTextLength, getMaximumValue, getMaximumValueOverall, getMinimumValue, getMinimumValueOverall, getName, getRangeDurationField, hashCode, isLeap, remainder, toInterval, toString
public DateTimeField getField()
getField
in class AbstractReadableInstantFieldProperty
public DateMidnight getDateMidnight()
public DateMidnight addToCopy(int value)
The DateMidnight attached to this property is unchanged by this call. This operation is faster than converting a DateMidnight to a MutableDateTime and back again when setting one field. When setting multiple fields, it is generally quicker to make the conversion to MutableDateTime.
value
- the value to add to the field in the copyjava.lang.IllegalArgumentException
- if the value isn't validpublic DateMidnight addToCopy(long value)
The DateMidnight attached to this property is unchanged by this call. This operation is faster than converting a DateMidnight to a MutableDateTime and back again when setting one field. When setting multiple fields, it is generally quicker to make the conversion to MutableDateTime.
value
- the value to add to the field in the copyjava.lang.IllegalArgumentException
- if the value isn't validpublic DateMidnight addWrapFieldToCopy(int value)
The DateMidnight attached to this property is unchanged by this call. This operation is faster than converting a DateMidnight to a MutableDateTime and back again when setting one field. When setting multiple fields, it is generally quicker to make the conversion to MutableDateTime.
value
- the value to add to the field in the copyjava.lang.IllegalArgumentException
- if the value isn't validpublic DateMidnight setCopy(int value)
The DateMidnight attached to this property is unchanged by this call. This operation is faster than converting a DateMidnight to a MutableDateTime and back again when setting one field. When setting multiple fields, it is generally quicker to make the conversion to MutableDateTime.
value
- the value to set the field in the copy tojava.lang.IllegalArgumentException
- if the value isn't validpublic DateMidnight setCopy(java.lang.String text, java.util.Locale locale)
The DateMidnight attached to this property is unchanged by this call. This operation is faster than converting a DateMidnight to a MutableDateTime and back again when setting one field. When setting multiple fields, it is generally quicker to make the conversion to MutableDateTime.
text
- the text value to setlocale
- optional locale to use for selecting a text symboljava.lang.IllegalArgumentException
- if the text value isn't validpublic DateMidnight setCopy(java.lang.String text)
The DateMidnight attached to this property is unchanged by this call. This operation is faster than converting a DateMidnight to a MutableDateTime and back again when setting one field. When setting multiple fields, it is generally quicker to make the conversion to MutableDateTime.
text
- the text value to setjava.lang.IllegalArgumentException
- if the text value isn't validpublic DateMidnight withMaximumValue()
This operation is useful for obtaining a DateTime on the last day of the month, as month lengths vary.
DateMidnight lastDayOfMonth = dt.dayOfMonth().withMaximumValue();
The DateMidnight attached to this property is unchanged by this call.
public DateMidnight withMinimumValue()
The DateMidnight attached to this property is unchanged by this call.
public DateMidnight roundFloorCopy()
public DateMidnight roundCeilingCopy()
public DateMidnight roundHalfFloorCopy()
public DateMidnight roundHalfCeilingCopy()
public DateMidnight roundHalfEvenCopy()
Copyright © 2010 - 2020 Adobe. All Rights Reserved