public abstract class ImpreciseDateTimeField extends BaseDateTimeField
This DateTimeField is useful for defining DateTimeFields that are composed
of imprecise durations. If both duration fields are precise, then a
PreciseDateTimeField
should be used instead.
When defining imprecise DateTimeFields where a matching DurationField is already available, just extend BaseDateTimeField directly so as not to create redundant DurationField instances.
ImpreciseDateTimeField is thread-safe and immutable, and its subclasses must be as well.
PreciseDateTimeField
Constructor and Description |
---|
ImpreciseDateTimeField(DateTimeFieldType type,
long unitMillis)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
abstract long |
add(long instant,
int value)
Adds a value (which may be negative) to the instant value,
overflowing into larger fields if necessary.
|
abstract long |
add(long instant,
long value)
Adds a value (which may be negative) to the instant value,
overflowing into larger fields if necessary.
|
abstract int |
get(long instant)
Get the value of this field from the milliseconds.
|
int |
getDifference(long minuendInstant,
long subtrahendInstant)
Computes the difference between two instants, as measured in the units
of this field.
|
long |
getDifferenceAsLong(long minuendInstant,
long subtrahendInstant)
Computes the difference between two instants, as measured in the units
of this field.
|
DurationField |
getDurationField()
Returns the duration per unit value of this field.
|
abstract DurationField |
getRangeDurationField()
Returns the range duration of this field.
|
abstract long |
roundFloor(long instant)
Round to the lowest whole unit of this field.
|
abstract long |
set(long instant,
int value)
Sets a value in the milliseconds supplied.
|
add, addWrapField, addWrapField, addWrapPartial, getAsShortText, getAsShortText, getAsShortText, getAsShortText, getAsShortText, getAsText, getAsText, getAsText, getAsText, getAsText, getLeapAmount, getLeapDurationField, getMaximumShortTextLength, getMaximumTextLength, getMaximumValue, getMaximumValue, getMaximumValue, getMaximumValue, getMinimumValue, getMinimumValue, getMinimumValue, getMinimumValue, getName, getType, isLeap, isSupported, remainder, roundCeiling, roundHalfCeiling, roundHalfEven, roundHalfFloor, set, set, set, set, toString
isLenient, setExtended
public ImpreciseDateTimeField(DateTimeFieldType type, long unitMillis)
type
- the field typeunitMillis
- the average duration unit millisecondspublic abstract int get(long instant)
BaseDateTimeField
get
in class BaseDateTimeField
instant
- the milliseconds from 1970-01-01T00:00:00Z to querypublic abstract long set(long instant, int value)
BaseDateTimeField
The value of this field will be set. If the value is invalid, an exception if thrown.
If setting this field would make other fields invalid, then those fields may be changed. For example if the current date is the 31st January, and the month is set to February, the day would be invalid. Instead, the day would be changed to the closest value - the 28th/29th February as appropriate.
set
in class BaseDateTimeField
instant
- the milliseconds from 1970-01-01T00:00:00Z to set invalue
- the value to set, in the units of the fieldpublic abstract long add(long instant, int value)
BaseDateTimeField
The 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 BaseDateTimeField
instant
- the milliseconds from 1970-01-01T00:00:00Z to add tovalue
- the value to add, in the units of the fieldpublic abstract long add(long instant, long value)
BaseDateTimeField
add
in class BaseDateTimeField
instant
- the milliseconds from 1970-01-01T00:00:00Z to add tovalue
- the long value to add, in the units of the fieldBaseDateTimeField.add(long,int)
public int getDifference(long minuendInstant, long subtrahendInstant)
long instant = ... int v = ... int age = getDifference(add(instant, v), instant);The value 'age' is the same as the value 'v'.
The default implementation call getDifferenceAsLong and converts the return value to an int.
getDifference
in class BaseDateTimeField
minuendInstant
- the milliseconds from 1970-01-01T00:00:00Z to
subtract fromsubtrahendInstant
- the milliseconds from 1970-01-01T00:00:00Z to
subtract off the minuendpublic long getDifferenceAsLong(long minuendInstant, long subtrahendInstant)
long instant = ... long v = ... long age = getDifferenceAsLong(add(instant, v), instant);The value 'age' is the same as the value 'v'.
The default implementation performs a guess-and-check algorithm using getDurationField().getUnitMillis() and the add() method. Subclasses are encouraged to provide a more efficient implementation.
getDifferenceAsLong
in class BaseDateTimeField
minuendInstant
- the milliseconds from 1970-01-01T00:00:00Z to
subtract fromsubtrahendInstant
- the milliseconds from 1970-01-01T00:00:00Z to
subtract off the minuendpublic final DurationField getDurationField()
BaseDateTimeField
getDurationField
in class BaseDateTimeField
public abstract DurationField getRangeDurationField()
BaseDateTimeField
getRangeDurationField
in class BaseDateTimeField
public abstract long roundFloor(long instant)
BaseDateTimeField
For 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 BaseDateTimeField
instant
- the milliseconds from 1970-01-01T00:00:00Z to roundCopyright © 2010 - 2020 Adobe. All Rights Reserved