Class LocalTime.Property
- java.lang.Object
-
- org.joda.time.field.AbstractReadableInstantFieldProperty
-
- org.joda.time.LocalTime.Property
-
- All Implemented Interfaces:
java.io.Serializable
- Enclosing class:
- LocalTime
public static final class LocalTime.Property extends AbstractReadableInstantFieldProperty
LocalTime.Property binds a LocalTime 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 minute '30'.
LocalTime dt = new LocalTime(12, 30); int year = dt.minuteOfHour().get();
Methods are also provided that allow time modification. These return new instances of LocalTime - they do not modify the original. The example below yields two independent immutable date objects 2 hours apart.
LocalTime dt1230 = new LocalTime(12, 30); LocalTime dt1430 = dt1230.hourOfDay().setCopy(14);
LocalTime.Property itself is thread-safe and immutable, as well as the LocalTime being operated on.
- Since:
- 1.3
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private DateTimeField
iField
The field this property is working againstprivate LocalTime
iInstant
The instant this property is working againstprivate static long
serialVersionUID
Serialization version
-
Constructor Summary
Constructors Constructor Description Property(LocalTime instant, DateTimeField field)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LocalTime
addCopy(int value)
Adds to this field in a copy of this LocalTime.LocalTime
addCopy(long value)
Adds to this field in a copy of this LocalTime.LocalTime
addNoWrapToCopy(int value)
Adds to this field in a copy of this LocalTime.LocalTime
addWrapFieldToCopy(int value)
Adds to this field, possibly wrapped, in a copy of this LocalTime.protected Chronology
getChronology()
Gets the chronology of the datetime that this property is linked to.DateTimeField
getField()
Gets the field being used.LocalTime
getLocalTime()
Gets the LocalTime object linked to this property.protected long
getMillis()
Gets the milliseconds of the time that this property is linked to.private void
readObject(java.io.ObjectInputStream oos)
Reads the property from a safe serialization format.LocalTime
roundCeilingCopy()
Rounds to the highest whole unit of this field on a copy of this LocalTime.LocalTime
roundFloorCopy()
Rounds to the lowest whole unit of this field on a copy of this LocalTime.LocalTime
roundHalfCeilingCopy()
Rounds to the nearest whole unit of this field on a copy of this LocalTime, favoring the ceiling if halfway.LocalTime
roundHalfEvenCopy()
Rounds to the nearest whole unit of this field on a copy of this LocalTime.LocalTime
roundHalfFloorCopy()
Rounds to the nearest whole unit of this field on a copy of this LocalTime, favoring the floor if halfway.LocalTime
setCopy(int value)
Sets this field in a copy of the LocalTime.LocalTime
setCopy(java.lang.String text)
Sets this field in a copy of the LocalTime to a parsed text value.LocalTime
setCopy(java.lang.String text, java.util.Locale locale)
Sets this field in a copy of the LocalTime to a parsed text value.LocalTime
withMaximumValue()
Returns a new LocalTime with this field set to the maximum value for this field.LocalTime
withMinimumValue()
Returns a new LocalTime with this field set to the minimum value for this field.private void
writeObject(java.io.ObjectOutputStream oos)
Writes the property in a safe serialization format.-
Methods inherited from class org.joda.time.field.AbstractReadableInstantFieldProperty
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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serialization version- See Also:
- Constant Field Values
-
iInstant
private transient LocalTime iInstant
The instant this property is working against
-
iField
private transient DateTimeField iField
The field this property is working against
-
-
Constructor Detail
-
Property
Property(LocalTime instant, DateTimeField field)
Constructor.- Parameters:
instant
- the instant to setfield
- the field to use
-
-
Method Detail
-
writeObject
private void writeObject(java.io.ObjectOutputStream oos) throws java.io.IOException
Writes the property in a safe serialization format.- Throws:
java.io.IOException
-
readObject
private void readObject(java.io.ObjectInputStream oos) throws java.io.IOException, java.lang.ClassNotFoundException
Reads the property from a safe serialization format.- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
getField
public DateTimeField getField()
Gets the field being used.- Specified by:
getField
in classAbstractReadableInstantFieldProperty
- Returns:
- the field
-
getMillis
protected long getMillis()
Gets the milliseconds of the time that this property is linked to.- Specified by:
getMillis
in classAbstractReadableInstantFieldProperty
- Returns:
- the milliseconds
-
getChronology
protected Chronology getChronology()
Gets the chronology of the datetime that this property is linked to.- Overrides:
getChronology
in classAbstractReadableInstantFieldProperty
- Returns:
- the chronology
- Since:
- 1.4
-
getLocalTime
public LocalTime getLocalTime()
Gets the LocalTime object linked to this property.- Returns:
- the linked LocalTime
-
addCopy
public LocalTime addCopy(int value)
Adds to this field in a copy of this LocalTime.The LocalTime attached to this property is unchanged by this call.
- Parameters:
value
- the value to add to the field in the copy- Returns:
- a copy of the LocalTime with the field value changed
-
addCopy
public LocalTime addCopy(long value)
Adds to this field in a copy of this LocalTime. If the addition exceeds the maximum value (eg. 23:59) it will wrap to the minimum value (eg. 00:00).The LocalTime attached to this property is unchanged by this call.
- Parameters:
value
- the value to add to the field in the copy- Returns:
- a copy of the LocalTime with the field value changed
-
addNoWrapToCopy
public LocalTime addNoWrapToCopy(int value)
Adds to this field in a copy of this LocalTime. If the addition exceeds the maximum value (eg. 23:59) then an exception will be thrown. Contrast this behaviour toaddCopy(int)
.The LocalTime attached to this property is unchanged by this call.
- Parameters:
value
- the value to add to the field in the copy- Returns:
- a copy of the LocalTime with the field value changed
- Throws:
java.lang.IllegalArgumentException
- if the result is invalid
-
addWrapFieldToCopy
public LocalTime addWrapFieldToCopy(int value)
Adds to this field, possibly wrapped, in a copy of this LocalTime. A field wrapped operation only changes this field. Thus 10:59 plusWrapField one minute goes to 10:00.The LocalTime attached to this property is unchanged by this call.
- Parameters:
value
- the value to add to the field in the copy- Returns:
- a copy of the LocalTime with the field value changed
- Throws:
java.lang.IllegalArgumentException
- if the value isn't valid
-
setCopy
public LocalTime setCopy(int value)
Sets this field in a copy of the LocalTime.The LocalTime attached to this property is unchanged by this call.
- Parameters:
value
- the value to set the field in the copy to- Returns:
- a copy of the LocalTime with the field value changed
- Throws:
java.lang.IllegalArgumentException
- if the value isn't valid
-
setCopy
public LocalTime setCopy(java.lang.String text, java.util.Locale locale)
Sets this field in a copy of the LocalTime to a parsed text value.The LocalTime attached to this property is unchanged by this call.
- Parameters:
text
- the text value to setlocale
- optional locale to use for selecting a text symbol- Returns:
- a copy of the LocalTime with the field value changed
- Throws:
java.lang.IllegalArgumentException
- if the text value isn't valid
-
setCopy
public LocalTime setCopy(java.lang.String text)
Sets this field in a copy of the LocalTime to a parsed text value.The LocalTime attached to this property is unchanged by this call.
- Parameters:
text
- the text value to set- Returns:
- a copy of the LocalTime with the field value changed
- Throws:
java.lang.IllegalArgumentException
- if the text value isn't valid
-
withMaximumValue
public LocalTime withMaximumValue()
Returns a new LocalTime with this field set to the maximum value for this field.The LocalTime attached to this property is unchanged by this call.
- Returns:
- a copy of the LocalTime with this field set to its maximum
-
withMinimumValue
public LocalTime withMinimumValue()
Returns a new LocalTime with this field set to the minimum value for this field.The LocalTime attached to this property is unchanged by this call.
- Returns:
- a copy of the LocalTime with this field set to its minimum
-
roundFloorCopy
public LocalTime roundFloorCopy()
Rounds to the lowest whole unit of this field on a copy of this LocalTime.For example, rounding floor on the hourOfDay field of a LocalTime where the time is 10:30 would result in new LocalTime with the time of 10:00.
- Returns:
- a copy of the LocalTime with the field value changed
-
roundCeilingCopy
public LocalTime roundCeilingCopy()
Rounds to the highest whole unit of this field on a copy of this LocalTime.For example, rounding floor on the hourOfDay field of a LocalTime where the time is 10:30 would result in new LocalTime with the time of 11:00.
- Returns:
- a copy of the LocalTime with the field value changed
-
roundHalfFloorCopy
public LocalTime roundHalfFloorCopy()
Rounds to the nearest whole unit of this field on a copy of this LocalTime, favoring the floor if halfway.- Returns:
- a copy of the LocalTime with the field value changed
-
roundHalfCeilingCopy
public LocalTime roundHalfCeilingCopy()
Rounds to the nearest whole unit of this field on a copy of this LocalTime, favoring the ceiling if halfway.- Returns:
- a copy of the LocalTime with the field value changed
-
roundHalfEvenCopy
public LocalTime roundHalfEvenCopy()
Rounds to the nearest whole unit of this field on a copy of this LocalTime. If halfway, the ceiling is favored over the floor only if it makes this field's value even.- Returns:
- a copy of the LocalTime with the field value changed
-
-