Record Class TimeRange

java.lang.Object
java.lang.Record
com.inductiveautomation.historian.common.model.TimeRange
Record Components:
startTime - the start of the time range
endTime - the end of the time range (defaults to now if null)
includeBounds - whether to include points exactly at the boundaries

public record TimeRange(Instant startTime, Instant endTime, boolean includeBounds) extends Record
Represents a time range with optional boundary inclusion.
  • Constructor Details

    • TimeRange

      public TimeRange(Instant startTime, Instant endTime, boolean includeBounds)
      Primary constructor with validation.
    • TimeRange

      public TimeRange(long startTimeMillis, long endTimeMillis, boolean includeBounds)
      Canonical constructor using epoch milliseconds.
      Parameters:
      startTimeMillis - the start time in epoch milliseconds
      endTimeMillis - the end time in epoch milliseconds, or 0 to use current time
      includeBounds - whether to include boundary points
  • Method Details

    • inclusive

      public static TimeRange inclusive(Instant startTime, Instant endTime)
      Creates a time range with inclusive bounds.
      Parameters:
      startTime - the start time
      endTime - the end time (null for current time)
      Returns:
      new time range with inclusive bounds
    • exclusive

      public static TimeRange exclusive(Instant startTime, Instant endTime)
      Creates a time range with exclusive bounds.
      Parameters:
      startTime - the start time
      endTime - the end time (null for current time)
      Returns:
      new time range with exclusive bounds
    • create

      @Nullable public static TimeRange create(Instant startTime, Instant endTime, boolean includeBounds)
      Creates an optional time range, returning null if both times are null.
      Parameters:
      startTime - the start time
      endTime - the end time
      includeBounds - whether to include boundary points
      Returns:
      new time range or null
    • contains

      public boolean contains(Instant timestamp)
      Checks if a timestamp falls within this time range.
      Parameters:
      timestamp - the timestamp to check
      Returns:
      true if the timestamp is within the range
    • nextRange

      public TimeRange nextRange()
      Creates a new time range that follows this one without gaps or overlaps.
      Returns:
      a new time range starting at this range's end time
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • startTime

      public Instant startTime()
      Returns the value of the startTime record component.
      Returns:
      the value of the startTime record component
    • endTime

      public Instant endTime()
      Returns the value of the endTime record component.
      Returns:
      the value of the endTime record component
    • includeBounds

      public boolean includeBounds()
      Returns the value of the includeBounds record component.
      Returns:
      the value of the includeBounds record component