public static final class

DateMidnight.Property

extends AbstractReadableInstantFieldProperty
java.lang.Object
   ↳ org.joda.time.field.AbstractReadableInstantFieldProperty
     ↳ org.joda.time.DateMidnight.Property

Class Overview

DateMidnight.Property binds a DateMidnight to a DateTimeField allowing powerful datetime functionality to be easily accessed.

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.

Summary

Public Methods
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(String text, Locale locale)
Sets this field in a copy of the DateMidnight to a parsed text value.
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 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.
Protected Methods
Chronology getChronology()
Gets the chronology of the datetime that this property is linked to.
long getMillis()
Gets the milliseconds of the datetime that this property is linked to.
[Expand]
Inherited Methods
From class org.joda.time.field.AbstractReadableInstantFieldProperty
From class java.lang.Object

Public Methods

public DateMidnight addToCopy (int value)

Adds to this field in a copy of this DateMidnight.

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.

Parameters
value the value to add to the field in the copy
Returns
  • a copy of the DateMidnight with the field value changed
Throws
IllegalArgumentException if the value isn't valid

public DateMidnight addToCopy (long value)

Adds to this field in a copy of this DateMidnight.

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.

Parameters
value the value to add to the field in the copy
Returns
  • a copy of the DateMidnight with the field value changed
Throws
IllegalArgumentException if the value isn't valid

public DateMidnight addWrapFieldToCopy (int value)

Adds to this field, possibly wrapped, in a copy of this DateMidnight. A wrapped operation only changes this field. Thus 31st January addWrapField one day goes to the 1st January.

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.

Parameters
value the value to add to the field in the copy
Returns
  • a copy of the DateMidnight with the field value changed
Throws
IllegalArgumentException if the value isn't valid

public DateMidnight getDateMidnight ()

Gets the datetime being used.

Returns
  • the datetime

public DateTimeField getField ()

Gets the field being used.

Returns
  • the field

public DateMidnight roundCeilingCopy ()

Rounds to the highest whole unit of this field on a copy of this DateMidnight.

Returns
  • a copy of the DateMidnight with the field value changed

public DateMidnight roundFloorCopy ()

Rounds to the lowest whole unit of this field on a copy of this DateMidnight.

Returns
  • a copy of the DateMidnight with the field value changed

public DateMidnight roundHalfCeilingCopy ()

Rounds to the nearest whole unit of this field on a copy of this DateMidnight, favoring the ceiling if halfway.

Returns
  • a copy of the DateMidnight with the field value changed

public DateMidnight roundHalfEvenCopy ()

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.

Returns
  • a copy of the DateMidnight with the field value changed

public DateMidnight roundHalfFloorCopy ()

Rounds to the nearest whole unit of this field on a copy of this DateMidnight, favoring the floor if halfway.

Returns
  • a copy of the DateMidnight with the field value changed

public DateMidnight setCopy (String text, Locale locale)

Sets this field in a copy of the DateMidnight to a parsed text 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.

Parameters
text the text value to set
locale optional locale to use for selecting a text symbol
Returns
  • a copy of the DateMidnight with the field value changed
Throws
IllegalArgumentException if the text value isn't valid

public DateMidnight setCopy (int value)

Sets this field in a copy of the DateMidnight.

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.

Parameters
value the value to set the field in the copy to
Returns
  • a copy of the DateMidnight with the field value changed
Throws
IllegalArgumentException if the value isn't valid

public DateMidnight setCopy (String text)

Sets this field in a copy of the DateMidnight to a parsed text 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.

Parameters
text the text value to set
Returns
  • a copy of the DateMidnight with the field value changed
Throws
IllegalArgumentException if the text value isn't valid

public DateMidnight withMaximumValue ()

Returns a new DateMidnight with this field set to the maximum value for this field.

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.

Returns
  • a copy of the DateMidnight with this field set to its maximum

public DateMidnight withMinimumValue ()

Returns a new DateMidnight with this field set to the minimum value for this field.

The DateMidnight attached to this property is unchanged by this call.

Returns
  • a copy of the DateMidnight with this field set to its minimum

Protected Methods

protected Chronology getChronology ()

Gets the chronology of the datetime that this property is linked to.

Returns
  • the chronology

protected long getMillis ()

Gets the milliseconds of the datetime that this property is linked to.

Returns
  • the milliseconds