Class BaseDuration
- java.lang.Object
-
- org.joda.time.base.AbstractDuration
-
- org.joda.time.base.BaseDuration
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<ReadableDuration>,ReadableDuration
- Direct Known Subclasses:
Duration
public abstract class BaseDuration extends AbstractDuration implements ReadableDuration, java.io.Serializable
BaseDuration is an abstract implementation of ReadableDuration that stores data in alongduration milliseconds field.This class should generally not be used directly by API users. The
ReadableDurationinterface should be used when different kinds of duration objects are to be referenced.BaseDuration subclasses may be mutable and not thread-safe.
- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseDuration(long duration)Creates a duration from the given millisecond duration.protectedBaseDuration(long startInstant, long endInstant)Creates a duration from the given interval endpoints.protectedBaseDuration(java.lang.Object duration)Creates a duration from the specified object using theConverterManager.protectedBaseDuration(ReadableInstant start, ReadableInstant end)Creates a duration from the given interval endpoints.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetMillis()Gets the length of this duration in milliseconds.protected voidsetMillis(long duration)Sets the length of this duration in milliseconds.IntervaltoIntervalFrom(ReadableInstant startInstant)Converts this duration to an Interval starting at the specified instant.IntervaltoIntervalTo(ReadableInstant endInstant)Converts this duration to an Interval ending at the specified instant.PeriodtoPeriod(Chronology chrono)Converts this duration to a Period instance using the standard period type and the specified chronology.PeriodtoPeriod(PeriodType type)Converts this duration to a Period instance using the specified period type and the ISO chronology.PeriodtoPeriod(PeriodType type, Chronology chrono)Converts this duration to a Period instance using the specified period type and chronology.PeriodtoPeriodFrom(ReadableInstant startInstant)Converts this duration to a Period instance by adding the duration to a start instant to obtain an interval using the standard period type.PeriodtoPeriodFrom(ReadableInstant startInstant, PeriodType type)Converts this duration to a Period instance by adding the duration to a start instant to obtain an interval.PeriodtoPeriodTo(ReadableInstant endInstant)Converts this duration to a Period instance by subtracting the duration from an end instant to obtain an interval using the standard period type.PeriodtoPeriodTo(ReadableInstant endInstant, PeriodType type)Converts this duration to a Period instance by subtracting the duration from an end instant to obtain an interval using the standard period type.-
Methods inherited from class org.joda.time.base.AbstractDuration
compareTo, equals, hashCode, isEqual, isLongerThan, isShorterThan, toDuration, toPeriod, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.joda.time.ReadableDuration
equals, hashCode, isEqual, isLongerThan, isShorterThan, toDuration, toPeriod, toString
-
-
-
-
Constructor Detail
-
BaseDuration
protected BaseDuration(long duration)
Creates a duration from the given millisecond duration.- Parameters:
duration- the duration, in milliseconds
-
BaseDuration
protected BaseDuration(long startInstant, long endInstant)Creates a duration from the given interval endpoints.- Parameters:
startInstant- interval start, in millisecondsendInstant- interval end, in milliseconds- Throws:
java.lang.ArithmeticException- if the duration exceeds a 64-bit long
-
BaseDuration
protected BaseDuration(ReadableInstant start, ReadableInstant end)
Creates a duration from the given interval endpoints.- Parameters:
start- interval start, null means nowend- interval end, null means now- Throws:
java.lang.ArithmeticException- if the duration exceeds a 64-bit long
-
BaseDuration
protected BaseDuration(java.lang.Object duration)
Creates a duration from the specified object using theConverterManager.- Parameters:
duration- duration to convert- Throws:
java.lang.IllegalArgumentException- if duration is invalid
-
-
Method Detail
-
getMillis
public long getMillis()
Gets the length of this duration in milliseconds.- Specified by:
getMillisin interfaceReadableDuration- Returns:
- the length of the duration in milliseconds.
-
setMillis
protected void setMillis(long duration)
Sets the length of this duration in milliseconds.- Parameters:
duration- the new length of the duration
-
toPeriod
public Period toPeriod(PeriodType type)
Converts this duration to a Period instance using the specified period type and the ISO chronology.Only precise fields in the period type will be used. At most these are hours, minutes, seconds and millis - the period type may restrict the selection further.
For more control over the conversion process, you must pair the duration with an instant, see
toPeriodFrom(ReadableInstant, PeriodType).- Parameters:
type- the period type to use, null means standard- Returns:
- a Period created using the millisecond duration from this instance
-
toPeriod
public Period toPeriod(Chronology chrono)
Converts this duration to a Period instance using the standard period type and the specified chronology.Only precise fields in the period type will be used. Exactly which fields are precise depends on the chronology. Only the time fields are precise for ISO chronology with a time zone. However, ISO UTC also has precise days and weeks.
For more control over the conversion process, you must pair the duration with an instant, see
toPeriodFrom(ReadableInstant)andtoPeriodTo(ReadableInstant)- Parameters:
chrono- the chronology to use, null means ISO default- Returns:
- a Period created using the millisecond duration from this instance
-
toPeriod
public Period toPeriod(PeriodType type, Chronology chrono)
Converts this duration to a Period instance using the specified period type and chronology.Only precise fields in the period type will be used. Exactly which fields are precise depends on the chronology. Only the time fields are precise for ISO chronology with a time zone. However, ISO UTC also has precise days and weeks.
For more control over the conversion process, you must pair the duration with an instant, see
toPeriodFrom(ReadableInstant, PeriodType)andtoPeriodTo(ReadableInstant, PeriodType)- Parameters:
type- the period type to use, null means standardchrono- the chronology to use, null means ISO default- Returns:
- a Period created using the millisecond duration from this instance
-
toPeriodFrom
public Period toPeriodFrom(ReadableInstant startInstant)
Converts this duration to a Period instance by adding the duration to a start instant to obtain an interval using the standard period type.This conversion will determine the fields of a period accurately. The results are based on the instant millis, the chronology of the instant, the standard period type and the length of this duration.
- Parameters:
startInstant- the instant to calculate the period from, null means now- Returns:
- a Period created using the millisecond duration from this instance
-
toPeriodFrom
public Period toPeriodFrom(ReadableInstant startInstant, PeriodType type)
Converts this duration to a Period instance by adding the duration to a start instant to obtain an interval.This conversion will determine the fields of a period accurately. The results are based on the instant millis, the chronology of the instant, the period type and the length of this duration.
- Parameters:
startInstant- the instant to calculate the period from, null means nowtype- the period type determining how to split the duration into fields, null means All type- Returns:
- a Period created using the millisecond duration from this instance
-
toPeriodTo
public Period toPeriodTo(ReadableInstant endInstant)
Converts this duration to a Period instance by subtracting the duration from an end instant to obtain an interval using the standard period type.This conversion will determine the fields of a period accurately. The results are based on the instant millis, the chronology of the instant, the standard period type and the length of this duration.
- Parameters:
endInstant- the instant to calculate the period to, null means now- Returns:
- a Period created using the millisecond duration from this instance
-
toPeriodTo
public Period toPeriodTo(ReadableInstant endInstant, PeriodType type)
Converts this duration to a Period instance by subtracting the duration from an end instant to obtain an interval using the standard period type.This conversion will determine the fields of a period accurately. The results are based on the instant millis, the chronology of the instant, the period type and the length of this duration.
- Parameters:
endInstant- the instant to calculate the period to, null means nowtype- the period type determining how to split the duration into fields, null means All type- Returns:
- a Period created using the millisecond duration from this instance
-
toIntervalFrom
public Interval toIntervalFrom(ReadableInstant startInstant)
Converts this duration to an Interval starting at the specified instant.- Parameters:
startInstant- the instant to start the interval at, null means now- Returns:
- an Interval starting at the specified instant
-
toIntervalTo
public Interval toIntervalTo(ReadableInstant endInstant)
Converts this duration to an Interval ending at the specified instant.- Parameters:
endInstant- the instant to end the interval at, null means now- Returns:
- an Interval ending at the specified instant
-
-