|
Joda Time API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object
|
+--org.joda.time.DateTimeField
|
+--org.joda.time.chrono.NonZeroDateTimeField
Wraps another field such that zero values are replaced with one more than it's maximum. This is particularly useful for implementing an clockhourOfDay field, where the midnight value of 0 is replaced with 24.
| Constructor Summary | |
NonZeroDateTimeField(java.lang.String name,
DateTimeField field)
|
|
| Method Summary | |
long |
add(long millis,
int amount)
Adds a value (which may be negative) to the millis value, overflowing into larger fields if necessary. |
long |
add(long millis,
long amount)
Adds a value (which may be negative) to the millis value, overflowing into larger fields if necessary. |
long |
addWrapped(long millis,
int amount)
Adds a value (which may be negative) to the millis value, wrapping within this field. |
int |
get(long millis)
Get the value of this field from the milliseconds. |
long |
getDifference(long minuendMillis,
long subtrahendMillis)
Computes the difference between two instants, as measured in the units of this field. |
DateTimeField |
getField()
Returns the DateTimeField being wrapped. |
int |
getMaximumValue()
Get the maximum value for the field, which is one more than the wrapped field's maximum value. |
int |
getMaximumValue(long millis)
Get the maximum value for the field, which is one more than the wrapped field's maximum value. |
int |
getMinimumValue()
Always returns 1. |
int |
getMinimumValue(long millis)
Always returns 1. |
long |
getRangeMillis()
Returns the range of this field, in milliseconds. |
long |
getUnitMillis()
Returns the amount of milliseconds per unit value of this field. |
long |
remainder(long millis)
Retains only the fractional units of this field. |
long |
roundCeiling(long millis)
Round to the highest whole unit of this field. |
long |
roundFloor(long millis)
Round to the lowest whole unit of this field. |
long |
set(long millis,
int value)
Sets a value in the milliseconds supplied. |
| Methods inherited from class org.joda.time.DateTimeField |
addLong, getAsShortText, getAsShortText, getAsText, getAsText, getLeapAmount, getMaximumShortTextLength, getMaximumTextLength, getName, getWrappedValue, getWrappedValue, isLeap, roundHalfCeiling, roundHalfEven, roundHalfFloor, set, set, toString, verifyValueBounds |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public NonZeroDateTimeField(java.lang.String name,
DateTimeField field)
name - short, descriptive name, like "clockhourOfDay".
java.lang.IllegalArgumentException - if wrapped field's minimum value is not zero| Method Detail |
public int get(long millis)
DateTimeField
get in class DateTimeFieldmillis - the milliseconds from 1970-01-01T00:00:00Z to query
public long add(long millis,
int amount)
DateTimeFieldThe value will be added to this field. If the value is too large to be added solely to this field, larger fields will increase as required. Smaller fields should be unaffected, except where the result would be an invalid value for a smaller field. In this case the smaller field is adjusted to be in range.
For example, in the ISO chronology:
2000-08-20 add six months is 2001-02-20
2000-08-20 add twenty months is 2002-04-20
2000-08-20 add minus nine months is 1999-11-20
2001-01-31 add one month is 2001-02-28
2001-01-31 add two months is 2001-03-31
add in class DateTimeFieldmillis - the milliseconds from 1970-01-01T00:00:00Z to add toamount - the value to add, in the units of the field
public long add(long millis,
long amount)
DateTimeField
add in class DateTimeFieldmillis - the milliseconds from 1970-01-01T00:00:00Z to add toamount - the long value to add, in the units of the field
DateTimeField.add(long,int)
public long addWrapped(long millis,
int amount)
DateTimeFieldThe value will be added to this field. If the value is too large to be added solely to this field then it wraps. Larger fields are always unaffected. Smaller fields should be unaffected, except where the result would be an invalid value for a smaller field. In this case the smaller field is adjusted to be in range.
For example, in the ISO chronology:
2000-08-20 addWrapped six months is 2000-02-20
2000-08-20 addWrapped twenty months is 2000-04-20
2000-08-20 addWrapped minus nine months is 2000-11-20
2001-01-31 addWrapped one month is 2001-02-28
2001-01-31 addWrapped two months is 2001-03-31
addWrapped in class DateTimeFieldmillis - the milliseconds from 1970-01-01T00:00:00Z to add toamount - the value to add, in the units of the field
public long getDifference(long minuendMillis,
long subtrahendMillis)
DateTimeFieldlong millis = ... int v = ... long age = getDifference(add(millis, v), millis);The value 'age' is the same as the value 'v'.
The default implementation performs a guess-and-check algorithm using the getUnitMillis and add methods. Subclasses are encouraged to provide a more efficient implementation.
getDifference in class DateTimeFieldminuendMillis - the milliseconds from 1970-01-01T00:00:00Z to
subtract fromsubtrahendMillis - the milliseconds from 1970-01-01T00:00:00Z to
subtract off the minuend
public long set(long millis,
int value)
DateTimeFieldThe value of this field will be set. If the value is invalid, an exception if thrown. Other fields are always unaffected.
set in class DateTimeFieldmillis - the milliseconds from 1970-01-01T00:00:00Z to set invalue - the value to set, in the units of the field
public long getUnitMillis()
DateTimeFieldFor fields with a variable unit size, this method returns a suitable average value.
getUnitMillis in class DateTimeFieldpublic long getRangeMillis()
DateTimeFieldFor 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.
getRangeMillis in class DateTimeFieldpublic int getMinimumValue()
getMinimumValue in class DateTimeFieldpublic int getMinimumValue(long millis)
getMinimumValue in class DateTimeFieldmillis - the milliseconds from 1970-01-01T00:00:00Z to query
public int getMaximumValue()
getMaximumValue in class DateTimeFieldpublic int getMaximumValue(long millis)
getMaximumValue in class DateTimeFieldmillis - the milliseconds from 1970-01-01T00:00:00Z to query
public long roundFloor(long millis)
DateTimeFieldFor example, a datetime of 2002-11-02T23:34:56.789, rounded to the lowest whole hour is 2002-11-02T23:00:00.000.
roundFloor in class DateTimeFieldmillis - the milliseconds from 1970-01-01T00:00:00Z to round
public long roundCeiling(long millis)
DateTimeFieldFor example, a datetime of 2002-11-02T23:34:56.789, rounded to the highest whole hour is 2002-11-03T00:00:00.000.
The default implementation calls roundFloor, and if the millis is modified as a result, adds one field unit. Subclasses are encouraged to provide a more efficient implementation.
roundCeiling in class DateTimeFieldmillis - the milliseconds from 1970-01-01T00:00:00Z to round
public long remainder(long millis)
DateTimeFieldFor example, a datetime of 2002-11-02T23:34:56.789, the remainder by hour is 1970-01-01T00:34:56.789.
The default implementation computes
millis - roundFloor(millis). Subclasses are encouraged to
provide a more efficient implementation.
remainder in class DateTimeFieldmillis - the milliseconds from 1970-01-01T00:00:00Z to get the
remainder
public DateTimeField getField()
|
Joda Time API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||