Class OffsetDateTimeField
- java.lang.Object
-
- org.joda.time.DateTimeField
-
- org.joda.time.field.BaseDateTimeField
-
- org.joda.time.field.DecoratedDateTimeField
-
- org.joda.time.field.OffsetDateTimeField
-
public class OffsetDateTimeField extends DecoratedDateTimeField
Generic offset adjusting datetime field.OffsetDateTimeField is thread-safe and immutable.
- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description OffsetDateTimeField(DateTimeField field, int offset)
Constructor.OffsetDateTimeField(DateTimeField field, DateTimeFieldType type, int offset)
Constructor.OffsetDateTimeField(DateTimeField field, DateTimeFieldType type, int offset, int minValue, int maxValue)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
add(long instant, int amount)
Add the specified amount of offset units to the specified time instant.long
add(long instant, long amount)
Add the specified amount of offset units to the specified time instant.long
addWrapField(long instant, int amount)
Add to the offset component of the specified time instant, wrapping around within that component if necessary.int
get(long instant)
Get the amount of offset units from the specified time instant.int
getLeapAmount(long instant)
Gets the amount by which this field is 'leap' for the specified instant.DurationField
getLeapDurationField()
If this field were to leap, then it would be in units described by the returned duration.int
getMaximumValue()
Get the maximum value for the field.int
getMinimumValue()
Get the minimum value for the field.int
getOffset()
Returns the offset added to the field values.boolean
isLeap(long instant)
Returns whether this field is 'leap' for the specified instant.long
remainder(long instant)
Returns the fractional duration milliseconds of this field.long
roundCeiling(long instant)
Round to the highest whole unit of this field.long
roundFloor(long instant)
Round to the lowest whole unit of this field.long
roundHalfCeiling(long instant)
Round to the nearest whole unit of this field.long
roundHalfEven(long instant)
Round to the nearest whole unit of this field.long
roundHalfFloor(long instant)
Round to the nearest whole unit of this field.long
set(long instant, int value)
Set the specified amount of offset units to the specified time instant.-
Methods inherited from class org.joda.time.field.DecoratedDateTimeField
getDurationField, getRangeDurationField, getWrappedField, isLenient
-
Methods inherited from class org.joda.time.field.BaseDateTimeField
add, addWrapField, addWrapPartial, getAsShortText, getAsShortText, getAsShortText, getAsShortText, getAsShortText, getAsText, getAsText, getAsText, getAsText, getAsText, getDifference, getDifferenceAsLong, getMaximumShortTextLength, getMaximumTextLength, getMaximumValue, getMaximumValue, getMaximumValue, getMinimumValue, getMinimumValue, getMinimumValue, getName, getType, isSupported, set, set, set, set, toString
-
Methods inherited from class org.joda.time.DateTimeField
setExtended
-
-
-
-
Constructor Detail
-
OffsetDateTimeField
public OffsetDateTimeField(DateTimeField field, int offset)
Constructor.- Parameters:
field
- the field to wrap, like "year()".offset
- offset to add to field values- Throws:
java.lang.IllegalArgumentException
- if offset is zero
-
OffsetDateTimeField
public OffsetDateTimeField(DateTimeField field, DateTimeFieldType type, int offset)
Constructor.- Parameters:
field
- the field to wrap, like "year()".type
- the field type this field actually usesoffset
- offset to add to field values- Throws:
java.lang.IllegalArgumentException
- if offset is zero
-
OffsetDateTimeField
public OffsetDateTimeField(DateTimeField field, DateTimeFieldType type, int offset, int minValue, int maxValue)
Constructor.- Parameters:
field
- the field to wrap, like "year()".type
- the field type this field actually usesoffset
- offset to add to field valuesminValue
- minimum allowed valuemaxValue
- maximum allowed value- Throws:
java.lang.IllegalArgumentException
- if offset is zero
-
-
Method Detail
-
get
public int get(long instant)
Get the amount of offset units from the specified time instant.- Overrides:
get
in classDecoratedDateTimeField
- Parameters:
instant
- the time instant in millis to query.- Returns:
- the amount of units extracted from the input.
-
add
public long add(long instant, int amount)
Add the specified amount of offset units to the specified time instant. The amount added may be negative.- Overrides:
add
in classBaseDateTimeField
- Parameters:
instant
- the time instant in millis to update.amount
- the amount of units to add (can be negative).- Returns:
- the updated time instant.
-
add
public long add(long instant, long amount)
Add the specified amount of offset units to the specified time instant. The amount added may be negative.- Overrides:
add
in classBaseDateTimeField
- Parameters:
instant
- the time instant in millis to update.amount
- the amount of units to add (can be negative).- Returns:
- the updated time instant.
- See Also:
BaseDateTimeField.add(long,int)
-
addWrapField
public long addWrapField(long instant, int amount)
Add to the offset component of the specified time instant, wrapping around within that component if necessary.- Overrides:
addWrapField
in classBaseDateTimeField
- Parameters:
instant
- the time instant in millis to update.amount
- the amount of units to add (can be negative).- Returns:
- the updated time instant.
-
set
public long set(long instant, int value)
Set the specified amount of offset units to the specified time instant.- Overrides:
set
in classDecoratedDateTimeField
- Parameters:
instant
- the time instant in millis to update.value
- value of units to set.- Returns:
- the updated time instant.
- Throws:
java.lang.IllegalArgumentException
- if value is too large or too small.
-
isLeap
public boolean isLeap(long instant)
Description copied from class:BaseDateTimeField
Returns whether this field is 'leap' for the specified instant.For example, a leap year would return true, a non leap year would return false.
This implementation returns false.
- Overrides:
isLeap
in classBaseDateTimeField
- Parameters:
instant
- the instant to check for leap status- Returns:
- true if the field is 'leap'
-
getLeapAmount
public int getLeapAmount(long instant)
Description copied from class:BaseDateTimeField
Gets the amount by which this field is 'leap' for the specified instant.For example, a leap year would return one, a non leap year would return zero.
This implementation returns zero.
- Overrides:
getLeapAmount
in classBaseDateTimeField
- Parameters:
instant
- the instant to check for leap status- Returns:
- the amount, in units of the leap duration field, that the field is leap
-
getLeapDurationField
public DurationField getLeapDurationField()
Description copied from class:BaseDateTimeField
If this field were to leap, then it would be in units described by the returned duration. If this field doesn't ever leap, null is returned.This implementation returns null.
- Overrides:
getLeapDurationField
in classBaseDateTimeField
- Returns:
- the leap duration field if field can be leap, null if it can't
-
getMinimumValue
public int getMinimumValue()
Get the minimum value for the field.- Overrides:
getMinimumValue
in classDecoratedDateTimeField
- Returns:
- the minimum value
-
getMaximumValue
public int getMaximumValue()
Get the maximum value for the field.- Overrides:
getMaximumValue
in classDecoratedDateTimeField
- Returns:
- the maximum value
-
roundFloor
public long roundFloor(long instant)
Description copied from class:BaseDateTimeField
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.
- Overrides:
roundFloor
in classDecoratedDateTimeField
- Parameters:
instant
- the milliseconds from 1970-01-01T00:00:00Z to round- Returns:
- rounded milliseconds
-
roundCeiling
public long roundCeiling(long instant)
Description copied from class:BaseDateTimeField
Round to the highest whole unit of this field. The value of this field and all fields of a higher magnitude may be incremented in order to achieve this result. 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 highest whole hour is 2002-11-03T00:00:00.000.
The default implementation calls roundFloor, and if the instant is modified as a result, adds one field unit. Subclasses are encouraged to provide a more efficient implementation.
- Overrides:
roundCeiling
in classBaseDateTimeField
- Parameters:
instant
- the milliseconds from 1970-01-01T00:00:00Z to round- Returns:
- rounded milliseconds
-
roundHalfFloor
public long roundHalfFloor(long instant)
Description copied from class:BaseDateTimeField
Round to the nearest whole unit of this field. If the given millisecond value is closer to the floor or is exactly halfway, this function behaves like roundFloor. If the millisecond value is closer to the ceiling, this function behaves like roundCeiling.- Overrides:
roundHalfFloor
in classBaseDateTimeField
- Parameters:
instant
- the milliseconds from 1970-01-01T00:00:00Z to round- Returns:
- rounded milliseconds
-
roundHalfCeiling
public long roundHalfCeiling(long instant)
Description copied from class:BaseDateTimeField
Round to the nearest whole unit of this field. If the given millisecond value is closer to the floor, this function behaves like roundFloor. If the millisecond value is closer to the ceiling or is exactly halfway, this function behaves like roundCeiling.- Overrides:
roundHalfCeiling
in classBaseDateTimeField
- Parameters:
instant
- the milliseconds from 1970-01-01T00:00:00Z to round- Returns:
- rounded milliseconds
-
roundHalfEven
public long roundHalfEven(long instant)
Description copied from class:BaseDateTimeField
Round to the nearest whole unit of this field. If the given millisecond value is closer to the floor, this function behaves like roundFloor. If the millisecond value is closer to the ceiling, this function behaves like roundCeiling.If the millisecond value is exactly halfway between the floor and ceiling, the ceiling is chosen over the floor only if it makes this field's value even.
- Overrides:
roundHalfEven
in classBaseDateTimeField
- Parameters:
instant
- the milliseconds from 1970-01-01T00:00:00Z to round- Returns:
- rounded milliseconds
-
remainder
public long remainder(long instant)
Description copied from class:BaseDateTimeField
Returns the fractional duration milliseconds of this field. In other words, calling remainder returns the duration that roundFloor would subtract.For example, on a datetime of 2002-11-02T23:34:56.789, the remainder by hour is 34 minutes and 56.789 seconds.
The default implementation computes
instant - roundFloor(instant)
. Subclasses are encouraged to provide a more efficient implementation.- Overrides:
remainder
in classBaseDateTimeField
- Parameters:
instant
- the milliseconds from 1970-01-01T00:00:00Z to get the remainder- Returns:
- remainder duration, in milliseconds
-
getOffset
public int getOffset()
Returns the offset added to the field values.- Returns:
- the offset
-
-