Record Class DateRange
java.lang.Object
java.lang.Record
nl.colorize.util.DateRange
- All Implemented Interfaces:
Comparable<DateRange>, Predicate<Date>
public record DateRange(Date start, Date end)
extends Record
implements Predicate<Date>, Comparable<DateRange>
Defines a range between two
Dates, with the start date being inclusive
and the end date being exclusive. Although the name of this class implies a
date range, this is technically a date/time range since
Date instances always include a time.
If dates do not specify an explicit time zone, the default time zone will be
used. See Platform.getDefaultTimeZone() for how to configure the
default time zone.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintbooleanReturns true if this date range contains the specified date.Factory method that returns a list ofDateRanges for every day between the specified start date (inclusive) and end date (exclusive).end()Returns the value of theendrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.Returns the first matchingDateRangecontaining the specified date.Factory method that returns a list ofDateRanges for every month between the specified start date (inclusive) and end date (exclusive).Factory method that returns a list ofDateRanges for every quarter between the specified start date (inclusive) and end date (exclusive).Creates a new date range that represents the smallest possible period that includes both this date range and the specified other date range.Splits this date range into monthly intervals.Splits this date range into weekly intervals.Splits this date range into yearly intervals.start()Returns the value of thestartrecord component.booleanReturns true if this date range contains the specified date.toString()Returns a string representation of this record class.Factory method that returns a list ofDateRanges for every week between the specified start date (inclusive) and end date (exclusive).Factory method that returns a list ofDateRanges for every year between the specified start date (inclusive) and end date (exclusive).
-
Constructor Details
-
DateRange
-
DateRange
Secondary constructor that usesDateParser.parse(String)to parse the specified start and end date.
-
-
Method Details
-
contains
Returns true if this date range contains the specified date. Note the start date is considered inclusive but the end date is considered exclusive, so this method will return false if the argument matches the end date exactly. -
test
-
splitWeeks
-
splitMonths
-
splitYears
-
span
-
compareTo
- Specified by:
compareToin interfaceComparable<DateRange>
-
toString
-
daily
-
weekly
Factory method that returns a list ofDateRanges for every week between the specified start date (inclusive) and end date (exclusive). Weeks are assumed to start on Monday. The result may include partial weeks if the start and end date do not align to week boundaries. -
monthly
-
quarterly
Factory method that returns a list ofDateRanges for every quarter between the specified start date (inclusive) and end date (exclusive). The result may include partial quarters if the start and end date do not align to quarter boundaries. -
yearly
-
match
-
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. All components in this record class are compared withObjects::equals(Object,Object). -
start
Returns the value of thestartrecord component.- Returns:
- the value of the
startrecord component
-
end
Returns the value of theendrecord component.- Returns:
- the value of the
endrecord component
-