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.
|
protected Chronology |
getChronology()
Gets the chronology of the datetime that this property is linked to.
|
DateMidnight |
getDateMidnight()
Gets the datetime being used.
|
DateTimeField |
getField()
Gets the field being used.
|
protected long |
getMillis()
Gets the milliseconds of the datetime that this property is linked to.
|
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(String text)
Sets this field in a copy of the DateMidnight to a parsed text value.
|
DateMidnight |
setCopy(String text,
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
protected long getMillis()
getMillis
in class AbstractReadableInstantFieldProperty
protected Chronology getChronology()
getChronology
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 copyIllegalArgumentException
- 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 copyIllegalArgumentException
- 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 copyIllegalArgumentException
- 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 toIllegalArgumentException
- if the value isn't validpublic DateMidnight setCopy(String text, 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 symbolIllegalArgumentException
- if the text value isn't validpublic DateMidnight setCopy(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 setIllegalArgumentException
- 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 © 2012 JBoss by Red Hat. All Rights Reserved.