java.lang.Object
com.flowingcode.vaadin.addons.recurrentschedulefield.api.DateTimeRange
All Implemented Interfaces:
Serializable

public class DateTimeRange extends Object implements Serializable
Represents a range of dates, times and days, generating TimeInterval instances based on specified constraints.
Characteristics:
  • Date range: Intervals span from (inclusive) start to (exclusive) end dates.
  • Days: Only includes specified days of the week.
  • Time range: Each interval spans from (inclusive) start to (exclusive) end times.
Features:
  • Retrieve intervals within the range.
  • Check if a date or date-time falls within any interval.
  • Get past or future intervals relative to a given date.
  • Calculate interval duration or the period between start and end dates.
Author:
Flowing Code
See Also:
  • Constructor Details

    • DateTimeRange

      public DateTimeRange(LocalDate startDate, LocalDate endDate, Set<DayOfWeek> weekDays)
      Creates a new DateTimeRange with the specified start and end dates, and included days of the week.
      Parameters:
      startDate - the inclusive start date of the range
      endDate - the exclusive end date of the range
      weekDays - the set of included DayOfWeek values
      Throws:
      IllegalArgumentException - if startDate is not before endDate, or if weekDays is null or empty
    • DateTimeRange

      public DateTimeRange(LocalDate startDate, LocalDate endDate)
      Creates a new DateTimeRange with the specified start and end dates, including all days of the week.
      Parameters:
      startDate - the inclusive start date of the range
      endDate - the exclusive end date of the range
      Throws:
      IllegalArgumentException - if startDate is not before endDate
    • DateTimeRange

      public DateTimeRange(LocalDate startDate, LocalDate endDate, LocalTime startTime, LocalTime endTime, Set<DayOfWeek> weekDays)
      Creates a new DateTimeRange with the specified dates, time boundaries, and included days of the week.
      Parameters:
      startDate - the inclusive start date of the range
      endDate - the exclusive end date of the range
      startTime - the inclusive start time of each interval
      endTime - the exclusive end time of each interval
      weekDays - the set of included DayOfWeek values
      Throws:
      IllegalArgumentException - if startDate is not before endDate, if startTime is not before endTime, or if weekDays is null or empty
    • DateTimeRange

      public DateTimeRange(LocalDate startDate, LocalDate endDate, LocalTime startTime, LocalTime endTime)
      Creates a new DateTimeRange with the specified dates and time boundaries, including all days of the week.
      Parameters:
      startDate - the inclusive start date of the range
      endDate - the exclusive end date of the range
      startTime - the inclusive start time of each interval
      endTime - the exclusive end time of each interval
      Throws:
      IllegalArgumentException - if startDate is not before endDate, or if startTime is not before endTime
  • Method Details

    • setDayDuration

      public void setDayDuration(LocalTime startTime, LocalTime endTime)
      Sets time boundaries for the intervals.
      Parameters:
      startTime - the starting point
      endTime - the ending point (exclusive)
    • setWeekDays

      public void setWeekDays(Set<DayOfWeek> weekDays)
      Defines on which days of the week intervals are defined.
      Parameters:
      weekDays - a list of days
    • setAllWeekDays

      public void setAllWeekDays()
      Sets the interval creation to include all days of the week. This is equivalent to calling setWeekDays(Set) with all days.
    • getWeekDays

      public Set<DayOfWeek> getWeekDays()
      Returns the days of the week on which intervals are defined.
      Returns:
      an immutable set of DayOfWeek
    • getIntervals

      public List<TimeInterval> getIntervals()
      Gets the intervals that conform to the current date and time constraints. Each interval represents a time range within the defined start and end dates, and only includes the specified days of the week.
      Returns:
      a list of TimeInterval objects, sorted by their time range
    • includes

      public boolean includes(LocalDate date)
      Checks if the given LocalDate falls within any interval.
      Returns:
      true if the argument is within an interval, false otherwise
    • includes

      public boolean includes(LocalDateTime dateTime)
      Checks if the given LocalDateTime falls within any interval.
      Returns:
      true if the argument is within an interval, false otherwise
    • getNextInterval

      public TimeInterval getNextInterval(LocalDate from)
      Gets the next interval that ends after the given LocalDate.
      Returns:
      the next TimeInterval after the given date, or null if no such interval exists
    • getNextInterval

      public TimeInterval getNextInterval()
      Gets the next interval that ends after the current date and time.
      Returns:
      the next TimeInterval after the current date and time, or null if no such interval exists
    • getNextInterval

      public TimeInterval getNextInterval(LocalDateTime from)
      Gets the next interval that ends after the given LocalDateTime.
      Returns:
      the next TimeInterval after the given date, or null if no such interval exists
    • getIntervalsLeft

      public List<TimeInterval> getIntervalsLeft()
      Gets the intervals that end after the current date and time.
      Returns:
      a list of TimeInterval objects representing the remaining intervals
    • getIntervalsLeft

      public List<TimeInterval> getIntervalsLeft(LocalDateTime from)
      Gets the intervals that end after given LocalDateTime.
      Returns:
      a list of TimeInterval objects representing the remaining intervals
    • getIntervalsLeft

      public List<TimeInterval> getIntervalsLeft(LocalDate from)
      Gets the intervals that end after given LocalDate.
      Returns:
      a list of TimeInterval objects representing the remaining intervals
    • getPastIntervals

      public List<TimeInterval> getPastIntervals()
      Gets the intervals that ended before the current date and time.
      Returns:
      a list of TimeInterval objects representing the past intervals
    • getPastIntervals

      public List<TimeInterval> getPastIntervals(LocalDate from)
      Gets the intervals that ended before given LocalDate.
      Returns:
      a list of TimeInterval objects representing the past intervals
    • getPastIntervals

      public List<TimeInterval> getPastIntervals(LocalDateTime from)
      Gets the intervals that ended before given LocalDateTime.
      Returns:
      a list of TimeInterval objects representing the past intervals
    • getDayDuration

      public Duration getDayDuration()
      Gets the time duration (or time period) of an interval. The duration is calculated as the difference between the start and (exclusive) end times.
      Returns:
      a Duration representing the length of an interval
    • getDatesPeriod

      public Period getDatesPeriod()
      Gets the period between the start and (exclusive) end dates.
    • getStartDate

      public LocalDate getStartDate()
      Gets the start date.
    • getEndDate

      public LocalDate getEndDate()
      Gets the end date (exclusive).
    • getStartTime

      public LocalTime getStartTime()
      Gets the LocalTime when intervals start.
    • getEndTime

      public LocalTime getEndTime()
      Gets the LocalTime when intervals end (exclusive).