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 componentmicros- time component in microseconds
PostgreSQL
interval type. A time span with separate month, day, and microsecond
components.-
Constructor Summary
ConstructorsConstructorDescriptionInterval(int months, int days, long micros) Creates an instance of aIntervalrecord class. -
Method Summary
Modifier and TypeMethodDescriptionintdays()Returns the value of thedaysrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.longmicros()Returns the value of themicrosrecord component.intmonths()Returns the value of themonthsrecord component.static IntervalCreates anIntervalfrom aDuration.Converts thisIntervalto aDuration.toString()Returns a string representation of this record class.
-
Constructor Details
-
Method Details
-
of
Creates anIntervalfrom aDuration. 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
Converts thisIntervalto aDuration. 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
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. -
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. -
equals
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 '=='. -
months
public int months()Returns the value of themonthsrecord component.- Returns:
- the value of the
monthsrecord component
-
days
public int days()Returns the value of thedaysrecord component.- Returns:
- the value of the
daysrecord component
-
micros
public long micros()Returns the value of themicrosrecord component.- Returns:
- the value of the
microsrecord component
-