Class BasicMonthOfYearDateTimeField
- java.lang.Object
-
- org.joda.time.DateTimeField
-
- org.joda.time.field.BaseDateTimeField
-
- org.joda.time.field.ImpreciseDateTimeField
-
- org.joda.time.chrono.BasicMonthOfYearDateTimeField
-
- Direct Known Subclasses:
GJMonthOfYearDateTimeField
class BasicMonthOfYearDateTimeField extends ImpreciseDateTimeField
Provides time calculations for the month of the year component of time.- Since:
- 1.2, refactored from GJMonthOfYearDateTimeField
-
-
Field Summary
Fields Modifier and Type Field Description private BasicChronologyiChronologyprivate intiLeapMonthprivate intiMaxprivate static intMINprivate static longserialVersionUIDSerialization version
-
Constructor Summary
Constructors Constructor Description BasicMonthOfYearDateTimeField(BasicChronology chronology, int leapMonth)Restricted constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longadd(long instant, int months)Add the specified month to the specified time instant.longadd(long instant, long months)Adds a value (which may be negative) to the instant value, overflowing into larger fields if necessary.int[]add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd)Adds a value (which may be negative) to the partial instant, throwing an exception if the maximum size of the instant is reached.longaddWrapField(long instant, int months)Add to the Month component of the specified time instant wrapping around within that component if necessary.intget(long instant)Get the Month component of the specified time instant.longgetDifferenceAsLong(long minuendInstant, long subtrahendInstant)Computes the difference between two instants, as measured in the units of this field.intgetLeapAmount(long instant)Gets the amount by which this field is 'leap' for the specified instant.DurationFieldgetLeapDurationField()If this field were to leap, then it would be in units described by the returned duration.intgetMaximumValue()Get the maximum allowable value for this field.intgetMinimumValue()Get the minimum allowable value for this field.DurationFieldgetRangeDurationField()Returns the range duration of this field.booleanisLeap(long instant)Returns whether this field is 'leap' for the specified instant.booleanisLenient()Returns true if the set method is lenient.private java.lang.ObjectreadResolve()Serialization singletonlongremainder(long instant)Returns the fractional duration milliseconds of this field.longroundFloor(long instant)Round to the lowest whole unit of this field.longset(long instant, int month)Set the Month component of the specified time instant.-
Methods inherited from class org.joda.time.field.ImpreciseDateTimeField
getDifference, getDurationField, getDurationUnitMillis
-
Methods inherited from class org.joda.time.field.BaseDateTimeField
addWrapField, addWrapPartial, convertText, getAsShortText, getAsShortText, getAsShortText, getAsShortText, getAsShortText, getAsText, getAsText, getAsText, getAsText, getAsText, getMaximumShortTextLength, getMaximumTextLength, getMaximumValue, getMaximumValue, getMaximumValue, getMinimumValue, getMinimumValue, getMinimumValue, getName, getType, isSupported, roundCeiling, roundHalfCeiling, roundHalfEven, roundHalfFloor, set, set, set, set, toString
-
Methods inherited from class org.joda.time.DateTimeField
setExtended
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serialization version- See Also:
- Constant Field Values
-
MIN
private static final int MIN
- See Also:
- Constant Field Values
-
iChronology
private final BasicChronology iChronology
-
iMax
private final int iMax
-
iLeapMonth
private final int iLeapMonth
-
-
Constructor Detail
-
BasicMonthOfYearDateTimeField
BasicMonthOfYearDateTimeField(BasicChronology chronology, int leapMonth)
Restricted constructor.- Parameters:
leapMonth- the month of year that leaps
-
-
Method Detail
-
isLenient
public boolean isLenient()
Description copied from class:DateTimeFieldReturns true if the set method is lenient. If so, it accepts values that are out of bounds. For example, a lenient day of month field accepts 32 for January, converting it to February 1.- Specified by:
isLenientin classDateTimeField- Returns:
- true if this field is lenient
-
get
public int get(long instant)
Get the Month component of the specified time instant.- Specified by:
getin classImpreciseDateTimeField- Parameters:
instant- the time instant in millis to query.- Returns:
- the month extracted from the input.
- See Also:
DateTimeField.get(long),ReadableDateTime.getMonthOfYear()
-
add
public long add(long instant, int months)Add the specified month to the specified time instant. The amount added may be negative.If the new month has less total days than the specified day of the month, this value is coerced to the nearest sane value. e.g.
07-31 - (1 month) = 06-30
03-31 - (1 month) = 02-28 or 02-29 depending
- Specified by:
addin classImpreciseDateTimeField- Parameters:
instant- the time instant in millis to update.months- the months to add (can be negative).- Returns:
- the updated time instant.
- See Also:
DateTimeField.add(long, int),ReadWritableDateTime.addMonths(int)
-
add
public long add(long instant, long months)Description copied from class:BaseDateTimeFieldAdds a value (which may be negative) to the instant value, overflowing into larger fields if necessary.- Specified by:
addin classImpreciseDateTimeField- Parameters:
instant- the milliseconds from 1970-01-01T00:00:00Z to add tomonths- the long value to add, in the units of the field- Returns:
- the updated milliseconds
- See Also:
BaseDateTimeField.add(long,int)
-
add
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd)
Description copied from class:BaseDateTimeFieldAdds a value (which may be negative) to the partial instant, throwing an exception if the maximum size of the instant is reached.The value will be added to this field, overflowing into larger fields if necessary. 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.
Partial instants only contain some fields. This may result in a maximum possible value, such as TimeOfDay being limited to 23:59:59:999. If this limit is breached by the add an exception is thrown.
For example, in the ISO chronology:
2000-08-20 add six months is 2000-02-20
2000-08-20 add twenty months is 2000-04-20
2000-08-20 add minus nine months is 2000-11-20
2001-01-31 add one month is 2001-02-28
2001-01-31 add two months is 2001-03-31- Overrides:
addin classBaseDateTimeField- Parameters:
partial- the partial instantfieldIndex- the index of this field in the partialvalues- the values of the partial instant which should be updatedvalueToAdd- the value to add, in the units of the field- Returns:
- the passed in values
-
addWrapField
public long addWrapField(long instant, int months)Add to the Month component of the specified time instant wrapping around within that component if necessary.- Overrides:
addWrapFieldin classBaseDateTimeField- Parameters:
instant- the time instant in millis to update.months- the months to add (can be negative).- Returns:
- the updated time instant.
- See Also:
DateTimeField.addWrapField(long, int)
-
getDifferenceAsLong
public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant)Description copied from class:ImpreciseDateTimeFieldComputes 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.
- Overrides:
getDifferenceAsLongin classImpreciseDateTimeField- Parameters:
minuendInstant- the milliseconds from 1970-01-01T00:00:00Z to subtract fromsubtrahendInstant- the milliseconds from 1970-01-01T00:00:00Z to subtract off the minuend- Returns:
- the difference in the units of this field
-
set
public long set(long instant, int month)Set the Month component of the specified time instant.If the new month has less total days than the specified day of the month, this value is coerced to the nearest sane value. e.g.
07-31 to month 6 = 06-30
03-31 to month 2 = 02-28 or 02-29 depending
- Specified by:
setin classImpreciseDateTimeField- Parameters:
instant- the time instant in millis to update.month- the month (1,12) to update the time to.- Returns:
- the updated time instant.
- Throws:
java.lang.IllegalArgumentException- if month is invalid
-
getRangeDurationField
public DurationField getRangeDurationField()
Description copied from class:BaseDateTimeFieldReturns the range duration of this field. For example, if this field represents "hour of day", then the range duration is a day.- Specified by:
getRangeDurationFieldin classImpreciseDateTimeField- Returns:
- the range duration of this field, or null if field has no range
-
isLeap
public boolean isLeap(long instant)
Description copied from class:BaseDateTimeFieldReturns 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:
isLeapin 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:BaseDateTimeFieldGets 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:
getLeapAmountin 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:BaseDateTimeFieldIf 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:
getLeapDurationFieldin classBaseDateTimeField- Returns:
- the leap duration field if field can be leap, null if it can't
-
getMinimumValue
public int getMinimumValue()
Description copied from class:BaseDateTimeFieldGet the minimum allowable value for this field.- Specified by:
getMinimumValuein classBaseDateTimeField- Returns:
- the minimum valid value for this field, in the units of the field
-
getMaximumValue
public int getMaximumValue()
Description copied from class:BaseDateTimeFieldGet the maximum allowable value for this field.- Specified by:
getMaximumValuein classBaseDateTimeField- Returns:
- the maximum valid value for this field, in the units of the field
-
roundFloor
public long roundFloor(long instant)
Description copied from class:BaseDateTimeFieldRound 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.
- Specified by:
roundFloorin classImpreciseDateTimeField- 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:BaseDateTimeFieldReturns 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:
remainderin classBaseDateTimeField- Parameters:
instant- the milliseconds from 1970-01-01T00:00:00Z to get the remainder- Returns:
- remainder duration, in milliseconds
-
readResolve
private java.lang.Object readResolve()
Serialization singleton
-
-