Class MutableInterval
- All Implemented Interfaces:
Serializable
,Cloneable
,ReadableInterval
,ReadWritableInterval
A time interval represents a period of time between two instants. Intervals are inclusive of the start instant and exclusive of the end. The end instant is always greater than or equal to the start instant.
Intervals have a fixed millisecond duration.
This is the difference between the start and end instants.
The duration is represented separately by ReadableDuration
.
As a result, intervals are not comparable.
To compare the length of two intervals, you should compare their durations.
An interval can also be converted to a ReadablePeriod
.
This represents the difference between the start and end points in terms of fields
such as years and days.
If performing significant calculations on an interval, it may be faster to convert an Interval object to a MutableInterval one.
MutableInterval is mutable and not thread-safe, unless concurrent threads are not invoking mutator methods.
- Since:
- 1.0
- Author:
- Stephen Colebourne, Brian S O'Neill
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a zero length time interval from 1970-01-01 to 1970-01-01.MutableInterval
(long startInstant, long endInstant) Constructs an interval from a start and end instant with the ISO default chronology.MutableInterval
(long startInstant, long endInstant, Chronology chronology) Constructs an interval from a start and end instant with a chronology.MutableInterval
(Object interval) Constructs a time interval by converting or copying from another object.MutableInterval
(Object interval, Chronology chronology) Constructs a time interval by converting or copying from another object, overriding the chronology.MutableInterval
(ReadableDuration duration, ReadableInstant end) Constructs an interval from a millisecond duration and an end instant.MutableInterval
(ReadableInstant start, ReadableDuration duration) Constructs an interval from a start instant and a duration.MutableInterval
(ReadableInstant start, ReadableInstant end) Constructs an interval from a start and end instant.MutableInterval
(ReadableInstant start, ReadablePeriod period) Constructs an interval from a start instant and a time period.MutableInterval
(ReadablePeriod period, ReadableInstant end) Constructs an interval from a time period and an end instant. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Clone this object.copy()
Clone this object without having to cast the returned object.static MutableInterval
Parses aMutableInterval
from the specified string.void
setChronology
(Chronology chrono) Sets the chronology of this time interval.void
setDurationAfterStart
(long duration) Sets the duration of this time interval, preserving the start instant.void
setDurationAfterStart
(ReadableDuration duration) Sets the duration of this time interval, preserving the start instant.void
setDurationBeforeEnd
(long duration) Sets the duration of this time interval, preserving the end instant.void
setDurationBeforeEnd
(ReadableDuration duration) Sets the duration of this time interval, preserving the end instant.void
setEnd
(ReadableInstant end) Sets the end of this time interval as an Instant.void
setEndMillis
(long endInstant) Sets the end of this time interval.void
setInterval
(long startInstant, long endInstant) Sets this interval from two millisecond instants retaining the chronology.void
setInterval
(ReadableInstant start, ReadableInstant end) Sets this interval from two instants, replacing the chronology with that from the start instant.void
setInterval
(ReadableInterval interval) Sets this interval to be the same as another.void
setPeriodAfterStart
(ReadablePeriod period) Sets the period of this time interval, preserving the start instant and using the ISOChronology in the default zone for calculations.void
setPeriodBeforeEnd
(ReadablePeriod period) Sets the period of this time interval, preserving the end instant and using the ISOChronology in the default zone for calculations.void
setStart
(ReadableInstant start) Sets the start of this time interval as an Instant.void
setStartMillis
(long startInstant) Sets the start of this time interval.Methods inherited from class org.joda.time.base.BaseInterval
getChronology, getEndMillis, getStartMillis, setInterval
Methods inherited from class org.joda.time.base.AbstractInterval
checkInterval, contains, contains, contains, containsNow, equals, getEnd, getStart, hashCode, isAfter, isAfter, isAfter, isAfterNow, isBefore, isBefore, isBefore, isBeforeNow, isEqual, overlaps, toDuration, toDurationMillis, toInterval, toMutableInterval, toPeriod, toPeriod, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.joda.time.ReadableInterval
contains, contains, equals, getChronology, getEnd, getEndMillis, getStart, getStartMillis, hashCode, isAfter, isAfter, isBefore, isBefore, overlaps, toDuration, toDurationMillis, toInterval, toMutableInterval, toPeriod, toPeriod, toString
-
Constructor Details
-
MutableInterval
public MutableInterval()Constructs a zero length time interval from 1970-01-01 to 1970-01-01. -
MutableInterval
public MutableInterval(long startInstant, long endInstant) Constructs an interval from a start and end instant with the ISO default chronology.- Parameters:
startInstant
- start of this interval, as milliseconds from 1970-01-01T00:00:00Z.endInstant
- end of this interval, as milliseconds from 1970-01-01T00:00:00Z.- Throws:
IllegalArgumentException
- if the end is before the start
-
MutableInterval
Constructs an interval from a start and end instant with a chronology.- Parameters:
startInstant
- start of this interval, as milliseconds from 1970-01-01T00:00:00Z.endInstant
- end of this interval, as milliseconds from 1970-01-01T00:00:00Z.chronology
- the chronology to use, null is ISO default- Throws:
IllegalArgumentException
- if the end is before the start
-
MutableInterval
Constructs an interval from a start and end instant.The chronology used is that of the start instant.
- Parameters:
start
- start of this interval, null means nowend
- end of this interval, null means now- Throws:
IllegalArgumentException
- if the end is before the start
-
MutableInterval
Constructs an interval from a start instant and a duration.- Parameters:
start
- start of this interval, null means nowduration
- the duration of this interval, null means zero length- Throws:
IllegalArgumentException
- if the end is before the startArithmeticException
- if the end instant exceeds the capacity of a long
-
MutableInterval
Constructs an interval from a millisecond duration and an end instant.- Parameters:
duration
- the duration of this interval, null means zero lengthend
- end of this interval, null means now- Throws:
IllegalArgumentException
- if the end is before the startArithmeticException
- if the start instant exceeds the capacity of a long
-
MutableInterval
Constructs an interval from a start instant and a time period.When forming the interval, the chronology from the instant is used if present, otherwise the chronology of the period is used.
- Parameters:
start
- start of this interval, null means nowperiod
- the period of this interval, null means zero length- Throws:
IllegalArgumentException
- if the end is before the startArithmeticException
- if the end instant exceeds the capacity of a long
-
MutableInterval
Constructs an interval from a time period and an end instant.When forming the interval, the chronology from the instant is used if present, otherwise the chronology of the period is used.
- Parameters:
period
- the period of this interval, null means zero lengthend
- end of this interval, null means now- Throws:
IllegalArgumentException
- if the end is before the startArithmeticException
- if the start instant exceeds the capacity of a long
-
MutableInterval
Constructs a time interval by converting or copying from another object.The recognised object types are defined in
ConverterManager
and include ReadableInterval and String. The String formats are described byISODateTimeFormat.dateTimeParser()
andISOPeriodFormat.standard()
, and may be 'datetime/datetime', 'datetime/period' or 'period/datetime'.- Parameters:
interval
- the time interval to copy- Throws:
IllegalArgumentException
- if the interval is invalid
-
MutableInterval
Constructs a time interval by converting or copying from another object, overriding the chronology.The recognised object types are defined in
ConverterManager
and include ReadableInterval and String. The String formats are described byISODateTimeFormat.dateTimeParser()
andISOPeriodFormat.standard()
, and may be 'datetime/datetime', 'datetime/period' or 'period/datetime'.- Parameters:
interval
- the time interval to copychronology
- the chronology to use, null means ISO default- Throws:
IllegalArgumentException
- if the interval is invalid
-
-
Method Details
-
parse
Parses aMutableInterval
from the specified string.The String formats are described by
ISODateTimeFormat.dateTimeParser()
andISOPeriodFormat.standard()
, and may be 'datetime/datetime', 'datetime/period' or 'period/datetime'.- Parameters:
str
- the string to parse, not null- Since:
- 2.0
-
setInterval
public void setInterval(long startInstant, long endInstant) Sets this interval from two millisecond instants retaining the chronology.- Specified by:
setInterval
in interfaceReadWritableInterval
- Parameters:
startInstant
- the start of the time intervalendInstant
- the start of the time interval- Throws:
IllegalArgumentException
- if the end is before the start
-
setInterval
Sets this interval to be the same as another.- Specified by:
setInterval
in interfaceReadWritableInterval
- Parameters:
interval
- the interval to copy- Throws:
IllegalArgumentException
- if the interval is null
-
setInterval
Sets this interval from two instants, replacing the chronology with that from the start instant.- Specified by:
setInterval
in interfaceReadWritableInterval
- Parameters:
start
- the start of the time intervalend
- the start of the time interval- Throws:
IllegalArgumentException
- if the end is before the start
-
setChronology
Sets the chronology of this time interval.- Specified by:
setChronology
in interfaceReadWritableInterval
- Parameters:
chrono
- the chronology to use, null means ISO default
-
setStartMillis
public void setStartMillis(long startInstant) Sets the start of this time interval.- Specified by:
setStartMillis
in interfaceReadWritableInterval
- Parameters:
startInstant
- the start of the time interval, millisecond instant from 1970-01-01T00:00:00Z- Throws:
IllegalArgumentException
- if the end is before the start
-
setStart
Sets the start of this time interval as an Instant.- Specified by:
setStart
in interfaceReadWritableInterval
- Parameters:
start
- the start of the time interval, null means now- Throws:
IllegalArgumentException
- if the end is before the start
-
setEndMillis
public void setEndMillis(long endInstant) Sets the end of this time interval.- Specified by:
setEndMillis
in interfaceReadWritableInterval
- Parameters:
endInstant
- the end of the time interval, millisecond instant from 1970-01-01T00:00:00Z- Throws:
IllegalArgumentException
- if the end is before the start
-
setEnd
Sets the end of this time interval as an Instant.- Specified by:
setEnd
in interfaceReadWritableInterval
- Parameters:
end
- the end of the time interval, null means now- Throws:
IllegalArgumentException
- if the end is before the start
-
setDurationAfterStart
public void setDurationAfterStart(long duration) Sets the duration of this time interval, preserving the start instant.- Parameters:
duration
- new duration for interval- Throws:
IllegalArgumentException
- if the end is before the startArithmeticException
- if the end instant exceeds the capacity of a long
-
setDurationBeforeEnd
public void setDurationBeforeEnd(long duration) Sets the duration of this time interval, preserving the end instant.- Parameters:
duration
- new duration for interval- Throws:
IllegalArgumentException
- if the end is before the startArithmeticException
- if the start instant exceeds the capacity of a long
-
setDurationAfterStart
Sets the duration of this time interval, preserving the start instant.- Specified by:
setDurationAfterStart
in interfaceReadWritableInterval
- Parameters:
duration
- new duration for interval, null means zero length- Throws:
IllegalArgumentException
- if the end is before the startArithmeticException
- if the end instant exceeds the capacity of a long
-
setDurationBeforeEnd
Sets the duration of this time interval, preserving the end instant.- Specified by:
setDurationBeforeEnd
in interfaceReadWritableInterval
- Parameters:
duration
- new duration for interval, null means zero length- Throws:
IllegalArgumentException
- if the end is before the startArithmeticException
- if the start instant exceeds the capacity of a long
-
setPeriodAfterStart
Sets the period of this time interval, preserving the start instant and using the ISOChronology in the default zone for calculations.- Specified by:
setPeriodAfterStart
in interfaceReadWritableInterval
- Parameters:
period
- new period for interval, null means zero length- Throws:
IllegalArgumentException
- if the end is before the startArithmeticException
- if the end instant exceeds the capacity of a long
-
setPeriodBeforeEnd
Sets the period of this time interval, preserving the end instant and using the ISOChronology in the default zone for calculations.- Specified by:
setPeriodBeforeEnd
in interfaceReadWritableInterval
- Parameters:
period
- new period for interval, null means zero length- Throws:
IllegalArgumentException
- if the end is before the startArithmeticException
- if the start instant exceeds the capacity of a long
-
copy
Clone this object without having to cast the returned object.- Returns:
- a clone of the this object.
-
clone
Clone this object.
-