Class TimeSpan

  • All Implemented Interfaces:
    Serializable, Comparable<TimeSpan>

    public final class TimeSpan
    extends Object
    implements Comparable<TimeSpan>, Serializable
    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:
    Serialized Form
    • Field Detail

      • EMPTY_FAR_PAST

        public static final TimeSpan EMPTY_FAR_PAST
      • start

        public final Instant start
      • duration

        public final Duration duration
    • Method Detail

      • collapse

        public Stream<TimeSpan> collapse​(TimeSpan other)
        Collapse to one or two spans. If the given TimeSpan overlaps with this, they are merged together to a new TimeSpan instance which covers the effective duration of the two spans. If the given TimeSpan does 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.
      • includes

        public boolean includes​(Instant instant)
        Check if an Instant is part of this time span. Includes start instant and excludes end instant of this time span.
        Returns:
        true if the given instant is part of this time span, false otherwise.
      • covers

        public boolean covers​(TimeSpan other)
        Check if the given TimeSpan is completly covered by this.
        Returns:
        true if the given TimeSpan is covered by this, false otherwise.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object