Record Class Interval

java.lang.Object
java.lang.Record
io.codemine.java.postgresql.codecs.Interval
Record Components:
months - month component (may be decomposed into years and months for display)
days - day component
micros - time component in microseconds

public record Interval(int months, int days, long micros) extends Record
PostgreSQL interval type. A time span with separate month, day, and microsecond components.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Interval(int months, int days, long micros)
    Creates an instance of a Interval record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the value of the days record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    long
    Returns the value of the micros record component.
    int
    Returns the value of the months record component.
    static Interval
    of(Duration duration)
    Creates an Interval from a Duration.
    Converts this Interval to a Duration.
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Interval

      public Interval(int months, int days, long micros)
      Creates an instance of a Interval record class.
      Parameters:
      months - the value for the months record component
      days - the value for the days record component
      micros - the value for the micros record component
  • Method Details

    • of

      public static Interval of(Duration duration)
      Creates an Interval from a Duration. The duration is converted to an interval by decomposing it into days and microseconds, and then further decomposing the days into months (assuming 30 days per month). Note that this conversion is lossy and may not accurately represent the original duration, especially for durations that span multiple months or years, due to the fixed assumption of 30 days per month.

      It also loses the nanosecond precision because the interval type only supports microseconds.

    • toDuration

      public Duration toDuration()
      Converts this Interval to a Duration. The conversion is done by calculating the total number of seconds represented by the interval (including the time, day, and month components) and then creating a Duration from that total. Note that this conversion is lossy and may not accurately represent the original interval, especially for intervals that include month or day components, due to the fixed assumption of 30 days per month and the loss of nanosecond precision.
    • 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. All components in this record class 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.
    • months

      public int months()
      Returns the value of the months record component.
      Returns:
      the value of the months record component
    • days

      public int days()
      Returns the value of the days record component.
      Returns:
      the value of the days record component
    • micros

      public long micros()
      Returns the value of the micros record component.
      Returns:
      the value of the micros record component