Package com.darkcollective.relix.value
Record Class DurationValue
java.lang.Object
java.lang.Record
com.darkcollective.relix.value.DurationValue
- Record Components:
months- the calendar months; negative for a span backwardsvalue- the exact elapsed part; must not benull
- All Implemented Interfaces:
Value
A runtime duration value: a number of calendar months and an
exact elapsed span of seconds and nanoseconds, backed by
Duration (e.g.
PT30M for thirty minutes, P1M for a month, P1Y2MT12H for a
year, two months and twelve hours).
This is PostgreSQL's INTERVAL, with its days folded into the exact part:
a day here is always 24 hours. A month has no fixed length, so it stays a count of
months, and adding one to a date or a timestamp moves it to the same day of the next
month, or to that month's last day when it is shorter.
Two durations are the same value when they are as long, reading a month as
30 days, as PostgreSQL compares intervals: P1M equals P30D, and is
shorter than P31D. Both keep how they were written, which is what they
display. Equality, hashing and order all read the same length,
so =, δ and τ agree.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe days a month counts for when a duration is compared or measured, as in PostgreSQL. -
Constructor Summary
ConstructorsConstructorDescriptionDurationValue(long months, Duration value) Creates an instance of aDurationValuerecord class.DurationValue(Duration value) An exact duration, with no calendar months. -
Method Summary
Modifier and TypeMethodDescriptionReturns the canonical ISO-8601 duration string, e.g.booleanIndicates whether some other object is "equal to" this one.inthashCode()Returns a hash code value for this object.booleanisExact()Whether this duration is an exact span, with no calendar months.booleanisNull()Returnstrueif this value is null (absent).static StringThe ISO-8601 text formonthscalendar months and an exactvalue.length()How long this duration is, reading each month as 30L days: what it is compared, hashed and measured by.longmonths()Returns the value of themonthsrecord component.final StringtoString()Returns a string representation of this record class.type()Returns theScalarTypethat describes this value's kind.value()Returns the value of thevaluerecord component.
-
Field Details
-
DAYS_PER_MONTH
public static final long DAYS_PER_MONTHThe days a month counts for when a duration is compared or measured, as in PostgreSQL.- See Also:
-
-
Constructor Details
-
Method Details
-
isExact
public boolean isExact()Whether this duration is an exact span, with no calendar months.- Returns:
truewhenmonths()is zero
-
length
How long this duration is, reading each month as 30L days: what it is compared, hashed and measured by.- Returns:
- the length as an exact span
-
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
hashCode
public int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
isNull
public boolean isNull()Description copied from interface:ValueReturnstrueif this value is null (absent). -
type
Description copied from interface:Value -
asDisplayString
Returns the canonical ISO-8601 duration string, e.g."PT30M","P1M"or"P1Y2MT12H": the months as years and months, then the exact part asDuration.toString()writes it.- Specified by:
asDisplayStringin interfaceValue- Returns:
- ISO-8601 duration string
-
iso
The ISO-8601 text formonthscalendar months and an exactvalue.- Parameters:
months- the calendar monthsvalue- the exact part- Returns:
- the text, the exact part's own when there are no months
-
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. -
months
public long months()Returns the value of themonthsrecord component.- Returns:
- the value of the
monthsrecord component
-
value
Returns the value of thevaluerecord component.- Returns:
- the value of the
valuerecord component
-