Package nl.colorize.util.stats
Record Class DateRange
java.lang.Object
java.lang.Record
nl.colorize.util.stats.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
Date
s, 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
-
Method Summary
Modifier and TypeMethodDescriptionint
boolean
Returns true if this date range contains the specified date.end()
Returns the value of theend
record component.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.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 daily intervals.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 thestart
record component.boolean
Returns true if this date range includes the specified date, using the same logic describes incontains(Date)
.toString()
Returns a string representation of this record class.
-
Constructor Details
-
DateRange
Creates an instance of aDateRange
record class.- Parameters:
start
- the value for thestart
record componentend
- the value for theend
record component
-
DateRange
Secondary constructor that usesDateParser.parse(String)
to parse dates from strings.
-
-
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
Returns true if this date range includes the specified date, using the same logic describes incontains(Date)
. -
splitDays
Splits this date range into daily intervals. This might include partial days, depending on the start and end date of this date range. -
splitWeeks
Splits this date range into weekly intervals. This might include partial weeks, depending on the start and end date of this date range. -
splitMonths
Splits this date range into monthly intervals. This might include partial months, depending on the start and end date of this date range. -
splitYearly
Splits this date range into yearly intervals. This might include partial years, depending on the start and end date of this date range. -
span
Creates a new date range that represents the smallest possible period that includes both this date range and the specified other date range. -
compareTo
- Specified by:
compareTo
in interfaceComparable<DateRange>
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
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 thestart
record component.- Returns:
- the value of the
start
record component
-
end
Returns the value of theend
record component.- Returns:
- the value of the
end
record component
-