java.lang.Object | |||
↳ | org.joda.time.DateTimeField | ||
↳ | org.joda.time.field.BaseDateTimeField | ||
↳ | org.joda.time.field.ImpreciseDateTimeField |
Abstract datetime field class that defines its own DurationField, which delegates back into this ImpreciseDateTimeField.
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.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a value (which may be negative) to the instant value,
overflowing into larger fields if necessary.
| |||||||||||
Adds a value (which may be negative) to the instant value,
overflowing into larger fields if necessary.
| |||||||||||
Get the value of this field from the milliseconds.
| |||||||||||
Computes the difference between two instants, as measured in the units
of this field.
| |||||||||||
Computes the difference between two instants, as measured in the units
of this field.
| |||||||||||
Returns the duration per unit value of this field.
| |||||||||||
Returns the range duration of this field.
| |||||||||||
Round to the lowest whole unit of this field.
| |||||||||||
Sets a value in the milliseconds supplied.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.joda.time.field.BaseDateTimeField
| |||||||||||
From class
org.joda.time.DateTimeField
| |||||||||||
From class
java.lang.Object
|
Constructor.
type | the field type |
---|---|
unitMillis | the average duration unit milliseconds |
Adds a value (which may be negative) to the instant value, overflowing into larger fields if necessary.
instant | the milliseconds from 1970-01-01T00:00:00Z to add to |
---|---|
value | the long value to add, in the units of the field |
Adds a value (which may be negative) to the instant value, overflowing into larger fields if necessary.
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
instant | the milliseconds from 1970-01-01T00:00:00Z to add to |
---|---|
value | the value to add, in the units of the field |
Get the value of this field from the milliseconds.
instant | the milliseconds from 1970-01-01T00:00:00Z to query |
---|
Computes the difference between two instants, as measured in the units of this field. Any fractional units are dropped from the result. Calling getDifference reverses the effect of calling add. In the following code:
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.
minuendInstant | the milliseconds from 1970-01-01T00:00:00Z to subtract from |
---|---|
subtrahendInstant | the milliseconds from 1970-01-01T00:00:00Z to subtract off the minuend |
Computes the difference between two instants, as measured in the units of this field. Any fractional units are dropped from the result. Calling getDifference reverses the effect of calling add. In the following code:
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.
minuendInstant | the milliseconds from 1970-01-01T00:00:00Z to subtract from |
---|---|
subtrahendInstant | the milliseconds from 1970-01-01T00:00:00Z to subtract off the minuend |
Returns the duration per unit value of this field. For example, if this field represents "hour of day", then the unit duration is an hour.
Returns the range duration of this field. For example, if this field represents "hour of day", then the range duration is a day.
Round to the lowest whole unit of this field. After rounding, the value of this field and all fields of a higher magnitude are retained. The fractional millis that cannot be expressed in whole increments of this field are set to minimum.
For example, a datetime of 2002-11-02T23:34:56.789, rounded to the lowest whole hour is 2002-11-02T23:00:00.000.
instant | the milliseconds from 1970-01-01T00:00:00Z to round |
---|
Sets a value in the milliseconds supplied.
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.
instant | the milliseconds from 1970-01-01T00:00:00Z to set in |
---|---|
value | the value to set, in the units of the field |