Class TimeWindow

java.lang.Object
com.dna.jopt.member.unit.hours.TimeWindow
All Implemented Interfaces:
Serializable, Comparable<TimeWindow>

public class TimeWindow extends Object implements Serializable, Comparable<TimeWindow>
The Class TimeWindow.
Since:
Dec 16, 2019
Version:
Dec 16, 2019
Author:
Jens Richter
See Also:
  • Field Details

  • Constructor Details

    • TimeWindow

      public TimeWindow(ZonedDateTime hoursBegin, ZonedDateTime hoursEnd)
      Instantiates a new time window.
      Parameters:
      hoursBegin - the hours begin
      hoursEnd - the hours end
    • TimeWindow

      public TimeWindow(Instant hoursBegin, Instant hoursEnd, ZoneId zoneId)
      Instantiates a new time window.
      Parameters:
      hoursBegin - the hours begin
      hoursEnd - the hours end
      zoneId - the zone id
    • TimeWindow

      public TimeWindow(long hoursBeginMillis, long hoursEndMillis, ZoneId zoneId)
      Instantiates a new time window.
      Parameters:
      hoursBeginMillis - the hours begin millis
      hoursEndMillis - the hours end millis
      zoneId - the zone id
  • Method Details

    • getHoursBeginInMillis

      public long getHoursBeginInMillis()
      Gets the begin in millis, the default value is 0L.
      Returns:
      the long hoursBeginInSecs
    • getHoursEndInMillis

      public long getHoursEndInMillis()
      Gets the end in millis, the default value is 0L.
      Returns:
      the long hoursBeginInSecs
    • setHoursBeginInMillis

      public void setHoursBeginInMillis(long hoursBeginInMillis)
      Sets the begin in millis.
      Parameters:
      hoursBeginInMillis - the new hours begin in millis
    • setHoursEndInMillis

      public void setHoursEndInMillis(long hoursEndInMillis)
      Sets the end in millis.
      Parameters:
      hoursEndInMillis - the new hours end in millis
    • getBegin

      public Instant getBegin()
      Gets the begin as instant.
      Returns:
      the begin
    • getEnd

      public Instant getEnd()
      Gets the end as instant.
      Returns:
      the begin
    • getCenter

      public Instant getCenter()
    • getZonedEnd

      public ZonedDateTime getZonedEnd()
    • getZonedBegin

      public ZonedDateTime getZonedBegin()
    • getZonedCenter

      public ZonedDateTime getZonedCenter()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getZoneId

      public ZoneId getZoneId()
      Gets the ZoneId,

      If through deserialization the zoneId is null, the system default is returned.

      Returns:
      the zoneId
    • compareTo

      public int compareTo(TimeWindow o)
      Specified by:
      compareTo in interface Comparable<TimeWindow>
    • getStart2EndDurationMillis

      public long getStart2EndDurationMillis()
      Gets the time in millis between getHoursEndInMillis() and getHoursBeginInMillis().
      Returns:
      the time between the two points in millis
    • getRange

      public com.google.common.collect.Range<Instant> getRange()
      Gets the range that contains all values between getBegin() and getEnd().
      Returns:
      the range<instant> between the two instants
    • getDuration

      public Duration getDuration()
      Gets the duration between getBegin() and getEnd().
      Returns:
      the Duration between the two instants
    • hasSameStartAndEnd

      public boolean hasSameStartAndEnd(TimeWindow o)
      Checks if getHoursBeginInMillis() and getHoursEndInMillis() are the same as the one of the input.
      Parameters:
      o - the TimeWindow input to check with the set parameters
      Returns:
      the boolean if the given timeWindow o is the same as the set parameters
    • getAsString

      public 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.
      Parameters:
      hours - the time window
      zoneId - the zoneId
      Returns:
      the beginning and the end of the hours in the format dd.MM.yyyy HH:mm:ss
    • isFitting

      public boolean isFitting(Duration duration)
    • validateOverlapAndSort

      public static List<TimeWindow> validateOverlapAndSort(List<TimeWindow> windows)
      Validate overlap and sort by start. Throws an InvalidElementCreationException exception in case input windows are overlapping.
      Parameters:
      windows - the windows
      Returns:
      the list
    • hasOverlap

      public static boolean hasOverlap(TimeWindow w1, TimeWindow w2)
      Checks for overlap.
      Parameters:
      w1 - the w 1
      w2 - the w 2
      Returns:
      true, if successful