public class TimeWindow extends Object implements Serializable, Comparable<TimeWindow>
Modifier and Type | Field and Description |
---|---|
static Comparator<TimeWindow> |
START
The Comparator for START.
|
Constructor and Description |
---|
TimeWindow(Instant hoursBegin,
Instant hoursEnd,
ZoneId zoneId)
Instantiates a new time window.
|
TimeWindow(long hoursBeginMillis,
long hoursEndMillis,
ZoneId zoneId)
Instantiates a new time window.
|
TimeWindow(ZonedDateTime hoursBegin,
ZonedDateTime hoursEnd)
Instantiates a new time window.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(TimeWindow o) |
static String |
getAsString(TimeWindow hours,
ZoneId zoneId)
Gets the beginning hours and the end hours in the format
dd.MM.yyyy HH:mm:ss and the
zoneId. |
Instant |
getBegin()
Gets the begin as instant.
|
Duration |
getDuration()
Gets the duration between
getBegin() and getEnd() . |
Instant |
getEnd()
Gets the end as instant.
|
long |
getHoursBeginInMillis()
Gets the begin in millis, the default value is 0L.
|
long |
getHoursEndInMillis()
Gets the end in millis, the default value is 0L.
|
com.google.common.collect.Range<Instant> |
getRange()
Gets the range that contains all values between
getBegin() and getEnd() . |
long |
getStart2EndDurationMillis()
Gets the time in millis between
getHoursEndInMillis() and getHoursBeginInMillis() . |
ZonedDateTime |
getZonedBegin() |
ZonedDateTime |
getZonedEnd() |
ZoneId |
getZoneId()
Gets the
ZoneId , |
static boolean |
hasOverlap(TimeWindow w1,
TimeWindow w2)
Checks for overlap.
|
boolean |
hasSameStartAndEnd(TimeWindow o)
Checks if
getHoursBeginInMillis() and getHoursEndInMillis()
are the same as the one of the input. |
boolean |
isFitting(Duration duration) |
void |
setHoursBeginInMillis(long hoursBeginInMillis)
Sets the begin in millis.
|
void |
setHoursEndInMillis(long hoursEndInMillis)
Sets the end in millis.
|
String |
toString() |
static List<TimeWindow> |
validateOverlapAndSort(List<TimeWindow> windows)
Validate overlap and sort by start.
|
public static final Comparator<TimeWindow> START
public TimeWindow(ZonedDateTime hoursBegin, ZonedDateTime hoursEnd)
hoursBegin
- the hours beginhoursEnd
- the hours endpublic TimeWindow(Instant hoursBegin, Instant hoursEnd, ZoneId zoneId)
hoursBegin
- the hours beginhoursEnd
- the hours endzoneId
- the zone idpublic TimeWindow(long hoursBeginMillis, long hoursEndMillis, ZoneId zoneId)
hoursBeginMillis
- the hours begin millishoursEndMillis
- the hours end milliszoneId
- the zone idpublic long getHoursBeginInMillis()
public long getHoursEndInMillis()
public void setHoursBeginInMillis(long hoursBeginInMillis)
hoursBeginInMillis
- the new hours begin in millispublic void setHoursEndInMillis(long hoursEndInMillis)
hoursEndInMillis
- the new hours end in millispublic Instant getBegin()
public Instant getEnd()
public ZonedDateTime getZonedEnd()
public ZonedDateTime getZonedBegin()
public ZoneId getZoneId()
ZoneId
,
If through deserialization the zoneId is null, the system default is returned.
public int compareTo(TimeWindow o)
compareTo
in interface Comparable<TimeWindow>
public long getStart2EndDurationMillis()
getHoursEndInMillis()
and getHoursBeginInMillis()
.public com.google.common.collect.Range<Instant> getRange()
getBegin()
and getEnd()
.range<instant>
between the two instantspublic Duration getDuration()
getBegin()
and getEnd()
.Duration
between the two instantspublic boolean hasSameStartAndEnd(TimeWindow o)
getHoursBeginInMillis()
and getHoursEndInMillis()
are the same as the one of the input.o
- the TimeWindow input to check with the set parameterspublic static String getAsString(TimeWindow hours, ZoneId zoneId)
dd.MM.yyyy HH:mm:ss
and the
zoneId.hours
- the time windowzoneId
- the zoneIdpublic boolean isFitting(Duration duration)
public static List<TimeWindow> validateOverlapAndSort(List<TimeWindow> windows)
InvalidElementCreationException
exception
in case input windows are overlapping.windows
- the windowspublic static boolean hasOverlap(TimeWindow w1, TimeWindow w2)
w1
- the w 1w2
- the w 2Copyright © 2017–2023 DNA Evolutions GmbH. All rights reserved.