I want to determine whether a date is included or not included for a given two periods (dates). For example, for July 20th to July 30th, "August 1st is not included" and "July 20th, July 25th, July 30th" are included. If you compare it with a line ...
---●---------------------●------
7/20 7/30
● will mean that the day is included.
boolean between(LocalDate date){
return (startDate.isBefore(date) && endDate.isAfter(date)) || startDate.equals(date) || endDate.equals(date);
}
boolean between(LocalDate date){
return !(startDate.isAfter(date) || endDate.isBefore(date));
}
---○---------------------○------
7/20 7/30
○ means that the day is not included.
boolean between(LocalDate date){
return (startDate.isBefore(date) && endDate.isAfter(date));
}
boolean between(LocalDate date){
//It shouldn't be based on external values, but it's simple
return date.isAfter(startDate) && date.isBefore(endDate);
}
boolean between(LocalDate date){
return startDate.compareTo(date) * endDate.compareTo(date) < 0;
}
boolean between(LocalDate date){
// //It should not be based on external values, but as a pattern
return startDate.compareTo(date) * date.compareTo(endDate) > 0;
}
or
<introduced
. java.awt.Rectangle # intersects` `` and` `java.awt.Rectangle # intersection
.Recommended Posts