Class DateTimeRange
java.lang.Object
com.flowingcode.vaadin.addons.recurrentschedulefield.api.DateTimeRange
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionDateTimeRange(LocalDate startDate, LocalDate endDate) Creates a newDateTimeRangewith the specified start and end dates, including all days of the week.DateTimeRange(LocalDate startDate, LocalDate endDate, LocalTime startTime, LocalTime endTime) Creates a newDateTimeRangewith the specified dates and time boundaries, including all days of the week.DateTimeRange(LocalDate startDate, LocalDate endDate, LocalTime startTime, LocalTime endTime, Set<DayOfWeek> weekDays) Creates a newDateTimeRangewith the specified dates, time boundaries, and included days of the week.DateTimeRange(LocalDate startDate, LocalDate endDate, Set<DayOfWeek> weekDays) Creates a newDateTimeRangewith the specified start and end dates, and included days of the week. -
Method Summary
Modifier and TypeMethodDescriptionGets the period between the start and (exclusive) end dates.Gets the time duration (or time period) of an interval.Gets the end date (exclusive).Gets theLocalTimewhen intervals end (exclusive).Gets the intervals that conform to the current date and time constraints.Gets the intervals that end after the current date and time.getIntervalsLeft(LocalDate from) Gets the intervals that end after givenLocalDate.Gets the intervals that end after givenLocalDateTime.Gets the next interval that ends after the current date and time.getNextInterval(LocalDate from) Gets the next interval that ends after the givenLocalDate.getNextInterval(LocalDateTime from) Gets the next interval that ends after the givenLocalDateTime.Gets the intervals that ended before the current date and time.getPastIntervals(LocalDate from) Gets the intervals that ended before givenLocalDate.Gets the intervals that ended before givenLocalDateTime.Gets the start date.Gets theLocalTimewhen intervals start.Returns the days of the week on which intervals are defined.booleanChecks if the givenLocalDatefalls within any interval.booleanincludes(LocalDateTime dateTime) Checks if the givenLocalDateTimefalls within any interval.voidSets the interval creation to include all days of the week.voidsetDayDuration(LocalTime startTime, LocalTime endTime) Sets time boundaries for the intervals.voidsetWeekDays(Set<DayOfWeek> weekDays) Defines on which days of the week intervals are defined.
-
Constructor Details
-
DateTimeRange
Creates a newDateTimeRangewith the specified start and end dates, and included days of the week.- Parameters:
startDate- the inclusive start date of the rangeendDate- the exclusive end date of the rangeweekDays- the set of includedDayOfWeekvalues- Throws:
IllegalArgumentException- ifstartDateis not beforeendDate, or ifweekDaysis null or empty
-
DateTimeRange
Creates a newDateTimeRangewith the specified start and end dates, including all days of the week.- Parameters:
startDate- the inclusive start date of the rangeendDate- the exclusive end date of the range- Throws:
IllegalArgumentException- ifstartDateis not beforeendDate
-
DateTimeRange
public DateTimeRange(LocalDate startDate, LocalDate endDate, LocalTime startTime, LocalTime endTime, Set<DayOfWeek> weekDays) Creates a newDateTimeRangewith the specified dates, time boundaries, and included days of the week.- Parameters:
startDate- the inclusive start date of the rangeendDate- the exclusive end date of the rangestartTime- the inclusive start time of each intervalendTime- the exclusive end time of each intervalweekDays- the set of includedDayOfWeekvalues- Throws:
IllegalArgumentException- ifstartDateis not beforeendDate, ifstartTimeis not beforeendTime, or ifweekDaysis null or empty
-
DateTimeRange
public DateTimeRange(LocalDate startDate, LocalDate endDate, LocalTime startTime, LocalTime endTime) Creates a newDateTimeRangewith the specified dates and time boundaries, including all days of the week.- Parameters:
startDate- the inclusive start date of the rangeendDate- the exclusive end date of the rangestartTime- the inclusive start time of each intervalendTime- the exclusive end time of each interval- Throws:
IllegalArgumentException- ifstartDateis not beforeendDate, or ifstartTimeis not beforeendTime
-
-
Method Details
-
setDayDuration
Sets time boundaries for the intervals.- Parameters:
startTime- the starting pointendTime- the ending point (exclusive)
-
setWeekDays
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 callingsetWeekDays(Set)with all days. -
getWeekDays
Returns the days of the week on which intervals are defined.- Returns:
- an immutable set of
DayOfWeek
-
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
TimeIntervalobjects, sorted by their time range
-
includes
Checks if the givenLocalDatefalls within any interval.- Returns:
trueif the argument is within an interval,falseotherwise
-
includes
Checks if the givenLocalDateTimefalls within any interval.- Returns:
trueif the argument is within an interval,falseotherwise
-
getNextInterval
Gets the next interval that ends after the givenLocalDate.- Returns:
- the next
TimeIntervalafter the given date, ornullif no such interval exists
-
getNextInterval
Gets the next interval that ends after the current date and time.- Returns:
- the next
TimeIntervalafter the current date and time, ornullif no such interval exists
-
getNextInterval
Gets the next interval that ends after the givenLocalDateTime.- Returns:
- the next
TimeIntervalafter the given date, ornullif no such interval exists
-
getIntervalsLeft
Gets the intervals that end after the current date and time.- Returns:
- a list of
TimeIntervalobjects representing the remaining intervals
-
getIntervalsLeft
Gets the intervals that end after givenLocalDateTime.- Returns:
- a list of
TimeIntervalobjects representing the remaining intervals
-
getIntervalsLeft
Gets the intervals that end after givenLocalDate.- Returns:
- a list of
TimeIntervalobjects representing the remaining intervals
-
getPastIntervals
Gets the intervals that ended before the current date and time.- Returns:
- a list of
TimeIntervalobjects representing the past intervals
-
getPastIntervals
Gets the intervals that ended before givenLocalDate.- Returns:
- a list of
TimeIntervalobjects representing the past intervals
-
getPastIntervals
Gets the intervals that ended before givenLocalDateTime.- Returns:
- a list of
TimeIntervalobjects representing the past intervals
-
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
Durationrepresenting the length of an interval
-
getDatesPeriod
Gets the period between the start and (exclusive) end dates. -
getStartDate
Gets the start date. -
getEndDate
Gets the end date (exclusive). -
getStartTime
Gets theLocalTimewhen intervals start. -
getEndTime
Gets theLocalTimewhen intervals end (exclusive).
-