Joda Time API

org.joda.time
Class DateTimeFieldProperty

java.lang.Object
  |
  +--org.joda.time.DateTimeFieldProperty
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
MutableDateTimeFieldProperty

public class DateTimeFieldProperty
extends java.lang.Object
implements java.io.Serializable

DateTimeFieldProperty binds a ReadableInstant to a DateTimeField.

DateTimeFieldProperty allows the date and time manipulation code to be field based yet still easy to use.

Since:
1.0
Author:
Stephen Colebourne, Brian S O'Neill
See Also:
ReadableInstant, DateTimeField, Serialized Form

Constructor Summary
DateTimeFieldProperty(ReadableInstant instant, DateTimeField field)
          Constructor.
 
Method Summary
 int compareTo(ReadableInstant instant)
          Compare this field to the same field on another instant.
 int get()
          Gets a value from the instant.
 java.lang.String getAsShortText()
          Gets a short text value from the instant.
 java.lang.String getAsShortText(java.util.Locale locale)
          Gets a short text value from the instant.
 java.lang.String getAsText()
          Gets a text value from the instant.
 java.lang.String getAsText(java.util.Locale locale)
          Gets a text value from the instant.
 long getDifference(ReadableInstant instant)
          Returns the difference between this field property instant and the one passed in, in the units of this field.
 DateTimeField getField()
          Gets the field being used.
 ReadableInstant getInstant()
          Gets the instant being used.
 int getLeapAmount()
          Gets the amount by which this field is leap.
 int getMaximumShortTextLength(java.util.Locale locale)
          Gets the maximum short text length for the field.
 int getMaximumTextLength(java.util.Locale locale)
          Gets the maximum text length for the field.
 int getMaximumValue()
          Gets the maximum value for the field.
 int getMaximumValueOverall()
          Gets the maximum value for the field ignoring the current time.
 int getMinimumValue()
          Gets the minimum value for the field.
 int getMinimumValueOverall()
          Gets the minimum value for the field ignoring the current time.
 java.lang.String getName()
          Gets the name of the field.
 long getRangeMillis()
          Returns the range of this field, in milliseconds.
 long getUnitMillis()
          Returns the amount of milliseconds per unit value of this field.
 boolean isLeap()
          Gets whether this field is leap.
 java.lang.String toString()
          Output a debugging string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DateTimeFieldProperty

public DateTimeFieldProperty(ReadableInstant instant,
                             DateTimeField field)
Constructor.

Parameters:
instant - the instant to set
field - the field to use
Method Detail

getField

public DateTimeField getField()
Gets the field being used.

Returns:
the field

getName

public java.lang.String getName()
Gets the name of the field.

Returns:
the field name

getInstant

public ReadableInstant getInstant()
Gets the instant being used.

Returns:
the instant

get

public int get()
Gets a value from the instant.

Returns:
the current value
See Also:
DateTimeField.get(long)

getAsText

public java.lang.String getAsText(java.util.Locale locale)
Gets a text value from the instant.

Parameters:
locale - optional locale to use for selecting a text symbol
Returns:
the current text value
See Also:
DateTimeField.getAsText(long, java.util.Locale)

getAsText

public final java.lang.String getAsText()
Gets a text value from the instant.

Returns:
the current text value
See Also:
DateTimeField.getAsText(long, java.util.Locale)

getAsShortText

public java.lang.String getAsShortText(java.util.Locale locale)
Gets a short text value from the instant.

Parameters:
locale - optional locale to use for selecting a text symbol
Returns:
the current text value
See Also:
DateTimeField.getAsShortText(long, java.util.Locale)

getAsShortText

public final java.lang.String getAsShortText()
Gets a short text value from the instant.

Returns:
the current text value
See Also:
DateTimeField.getAsShortText(long, java.util.Locale)

getDifference

public long getDifference(ReadableInstant instant)
Returns the difference between this field property instant and the one passed in, in the units of this field. The sign of the difference matches that of compareTo. In other words, this field property's instant is the minuend.

Parameters:
instant - the subtrahend
Returns:
the difference in the units of this field
See Also:
DateTimeField.getDifference(long, long)

isLeap

public boolean isLeap()
Gets whether this field is leap.

Returns:
true if a leap field
See Also:
DateTimeField.isLeap(long)

getLeapAmount

public int getLeapAmount()
Gets the amount by which this field is leap.

Returns:
the amount by which the field is leap
See Also:
DateTimeField.getLeapAmount(long)

getMinimumValueOverall

public int getMinimumValueOverall()
Gets the minimum value for the field ignoring the current time.

Returns:
the minimum value
See Also:
DateTimeField.getMinimumValue()

getMinimumValue

public int getMinimumValue()
Gets the minimum value for the field.

Returns:
the minimum value
See Also:
DateTimeField.getMinimumValue()

getMaximumValueOverall

public int getMaximumValueOverall()
Gets the maximum value for the field ignoring the current time.

Returns:
the maximum value
See Also:
DateTimeField.getMaximumValue()

getMaximumValue

public int getMaximumValue()
Gets the maximum value for the field.

Returns:
the maximum value
See Also:
DateTimeField.getMaximumValue()

getMaximumTextLength

public int getMaximumTextLength(java.util.Locale locale)
Gets the maximum text length for the field.

Parameters:
locale - optional locale to use for selecting a text symbol
Returns:
the maximum length
See Also:
DateTimeField.getMaximumTextLength(java.util.Locale)

getMaximumShortTextLength

public int getMaximumShortTextLength(java.util.Locale locale)
Gets the maximum short text length for the field.

Parameters:
locale - optional locale to use for selecting a text symbol
Returns:
the maximum length
See Also:
DateTimeField.getMaximumShortTextLength(java.util.Locale)

getUnitMillis

public long getUnitMillis()
Returns the amount of milliseconds per unit value of this field. For example, if this field represents "hour of day", then the unit is the amount of milliseconds per one hour.

For fields with a variable unit size, this method returns a suitable average value.

Returns:
the unit size of this field, in milliseconds

getRangeMillis

public long getRangeMillis()
Returns the range of this field, in milliseconds. For example, if this field represents "hour of day", then the range is the amount of milliseconds per one day.

For fields with a variable range, this method returns a suitable average value. If the range is too large to fit in a long, Long.MAX_VALUE is returned.

Returns:
the range of this field, in milliseconds

compareTo

public int compareTo(ReadableInstant instant)
Compare this field to the same field on another instant.

The get() method is used to obtain the value to compare for this instant and the ReadableInstant.get(DateTimeField) method is used for the specified instant.

Parameters:
instant - the instant to compare to
Returns:
-1 if this is less, +1 if more and 0 if equal
Throws:
java.lang.IllegalArgumentException - if the instant is null

toString

public java.lang.String toString()
Output a debugging string.

Overrides:
toString in class java.lang.Object
Returns:
debugging string

Joda Time API

Copyright © 2001-2003 Stephen Colebourne. All Rights Reserved.