Record Class TimeWindow
java.lang.Object
java.lang.Record
com.inductiveautomation.historian.common.model.TimeWindow
- Record Components:
size- the size of the windowunit- the chronological unit of the window
Represents a window of time with a size and unit. Provides conversion utilities between different
time units.
-
Constructor Summary
ConstructorsConstructorDescriptionTimeWindow(long size, ChronoUnit unit) Creates a new TimeWindow with validation. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static TimeWindowof(long size, ChronoUnit unit) static TimeWindowCreates a TimeWindow from a Duration.static TimeWindowofDays(long size) static TimeWindowofHours(long size) static TimeWindowofMillis(long size) Factory methods for common time windows.static TimeWindowofMinutes(long size) static TimeWindowofMonths(long size) static TimeWindowofSeconds(long size) static TimeWindowofWeeks(long size) static TimeWindowofYears(long size) longsize()Returns the value of thesizerecord component.longtoDays()Converts this window to a Duration if possible.longtoHours()longtoMillis()Converts this window to milliseconds for every unit inSUPPORTED_UNITS.longlongtoMonths()longtoString()Returns a string representation of this record class.longtoWeeks()longtoYears()unit()Returns the value of theunitrecord component.withUnit(ChronoUnit newUnit) Creates a new TimeWindow with a different unit.
-
Constructor Details
-
TimeWindow
Creates a new TimeWindow with validation.
-
-
Method Details
-
ofMillis
Factory methods for common time windows. -
ofSeconds
-
ofMinutes
-
ofHours
-
ofDays
-
ofWeeks
-
ofMonths
-
ofYears
-
of
-
of
Creates a TimeWindow from a Duration. -
toMillis
public long toMillis()Converts this window to milliseconds for every unit inSUPPORTED_UNITS.MILLISthroughDAYSconvert exactly.WEEKS,MONTHS, andYEARSuse the unit's average duration, so aMONTHSwindow is 30.436875 days rather than a calendar month; callers that need calendar-aligned boundaries must resolve them against a concrete date instead.- Returns:
- the window length in milliseconds.
-
toSeconds
public long toSeconds() -
toMinutes
public long toMinutes() -
toHours
public long toHours() -
toDays
public long toDays() -
toWeeks
public long toWeeks() -
toMonths
public long toMonths() -
toYears
public long toYears() -
toDuration
Converts this window to a Duration if possible.- Returns:
- the duration representation of this window
- Throws:
UnsupportedOperationException- if the unit is not time-based
-
withUnit
Creates a new TimeWindow with a different unit. -
toString
-
hashCode
-
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 thecomparemethod from their corresponding wrapper classes. -
size
-
unit
-