Class Interval

java.lang.Object
com.nt.udc.util.Interval

public class Interval extends Object
Implementation of an Interval which is not available in the java.time library
  • Field Details

  • Constructor Details

    • Interval

      public Interval(ZonedDateTime earliestStart, ZonedDateTime latestEnd)
      internal constructor for creating an interval from ZoneDateTimes.
      Parameters:
      earliestStart - the earliest start
      latestEnd - the latest end
  • Method Details

    • from

      public static final Interval from(ZonedDateTime earliestStart, ZonedDateTime latestEnd)
      creates an Interval from two supplied ZoneDateTimes. The dates should be supplied in Chronological order. If they are not....then they will be ordered from earliest to latest. Null supplied dates will be converted to timenow in UTC/GMT format.
      Parameters:
      earliestStart - the start time for the interval
      latestEnd - the end time for the interval
      Returns:
      the interval
    • fromUTC

      public static final Interval fromUTC(long earliestStart, long latestEnd)
      creates an Interval from to supplied longs representing epoch milliseconds. The resulting start and end ZonedDateTimes will be created in UTC format.
      Parameters:
      earliestStart - the easliest start time in epoch milliseconds
      latestEnd - he latest end time in epoch milliseconds. Pass in Long.MAX_VALUE to represent infinity
      Returns:
      the newly created Interval in UTC time zone.
    • toUTC

      public static final ZonedDateTime toUTC(ZonedDateTime zdt)
      Converts a ZonedDateTime to UTC time
      Parameters:
      zdt - the supplied ZoneDateTime that should be represented in UTC time
      Returns:
      a ZoneDateTime in UTC time
    • toUTC

      public static final ZonedDateTime toUTC(long millis)
      Creates a ZonedDateTime from a long that represents epoch time in milliseconds.
      Parameters:
      millis - epoch time in milliseconds
      Returns:
      a ZonedDateTime in UTC time zone
    • from

      public static final Interval from(Interval interval)
      create a new Inverval from an existing Interval
      Parameters:
      interval - the existing Interval from which a new instance will be created.
      Returns:
      a new instance of a copy constructed Interval
    • getEnd

      public ZonedDateTime getEnd()
      gets the end time for the Interval
      Returns:
      the end time for the Interval
    • getStart

      public ZonedDateTime getStart()
      gets the start time for the Interval
      Returns:
      the start time for the Interval
    • getEpochMilliEnd

      public long getEpochMilliEnd()
      gets the epoch millisecond time for the Interval end time. Will return Long.MAX_VALUE if the end time is infinity
      Returns:
      the epoch millisecond time for the Interval end time
    • getEpochMilliStart

      public long getEpochMilliStart()
      gets the epoch millisecond time for the Interval start time.
      Returns:
      the epoch millisecond time for the Interval start time
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • contains

      public boolean contains(ZonedDateTime timestamp)
      Contains logic is inclusive of start time, but exclusive of end time.
      Parameters:
      timestamp - null equals now time. This is implemented same as JodaTime lib for backward compatibility
      Returns:
      true if supplied date is contained in the Interval.
    • overlaps

      public boolean overlaps(Interval otherInterval)
      checks if the supplied Interval overlaps with this Interval
      Parameters:
      otherInterval - the supplied Interval to check against
      Returns:
      true if the supplied Interval overlaps with this Interval. The endpoint logic is exclusive.
    • toDuration

      public Duration toDuration()
    • contains

      public boolean contains(Interval otherInterval)
      checks if the supplied Interval is wholly contained within this interval.
      Parameters:
      otherInterval - the supplied Interval to check against
      Returns:
      true if the supplied Interval is completely contained within this Interval.
    • toString

      public String toString()
      Overrides:
      toString in class Object