Package no.digipost.time
Class TimeSpan
java.lang.Object
no.digipost.time.TimeSpan
- All Implemented Interfaces:
Serializable,Comparable<TimeSpan>
A time span is the composition of two instants on the time line,
denoting the start (inclusively) and end (exclusively) of an amount of time
on the actual time-line. For simplicity, it is not valid to construct
time spans which are negative, that goes "against time", where the
start instant is after the end instant.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA "started" time span, which works as a simple builder for a completeTimeSpan, using the concluding methodsTimeSpan.Started.until(Instant)orTimeSpan.Started.lasting(Duration) -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionCollapse to one or two spans.intbooleanCheck if the given TimeSpan is completly covered by this.booleanstatic TimeSpan.StartedStart constructing a newTimeSpanstarting at the givenInstant.inthashCode()booleanCheck if anInstantis part of this time span.intersection(TimeSpan other) Give the intersection (the overlapping part) of this and the givenTimeSpan, orOptional.empty()if they do not overlap.toString()
-
Field Details
-
EMPTY_FAR_PAST
-
start
-
end
-
duration
-
-
Method Details
-
from
Start constructing a newTimeSpanstarting at the givenInstant. Use the returnedTimeSpan.Started.until(Instant)orTimeSpan.Started.lasting(Duration)to set the end.- Parameters:
start- The start instant of the newTimeSpan.- Returns:
TimeSpan.Started
-
collapse
Collapse to one or two spans. If the givenTimeSpanoverlaps with this, they are merged together to a newTimeSpaninstance which covers the effective duration of the two spans. If the givenTimeSpandoes not overlap with this, the two spans are returned in chronological order, the earlier one placed first.- Parameters:
other- The other TimeSpan to collapse this with.- Returns:
- The list containing the collapsed TimeSpan, or this and the other if the two spans do not overlap each other.
-
intersection
Give the intersection (the overlapping part) of this and the givenTimeSpan, orOptional.empty()if they do not overlap. -
includes
Check if anInstantis part of this time span. Includes start instant and excludes end instant of this time span.- Returns:
trueif the giveninstantis part of this time span,falseotherwise.
-
covers
Check if the given TimeSpan is completly covered by this.- Returns:
trueif the givenTimeSpanis covered by this,falseotherwise.
-
compareTo
- Specified by:
compareToin interfaceComparable<TimeSpan>
-
equals
-
hashCode
public int hashCode() -
toString
-