public List<WorkItem> getWorkItemsByDate(String startDate, String endDate) throws ParseException {
LocalDate parsedStartDate = LocalDate.parse(startDate);
LocalDate parsedEndDate = LocalDate.parse(endDate);
return workItemRepository.findAll().stream().filter(w -> w.getUpdateDate().isAfter(parsedStartDate) &&
w.getUpdateDate().isBefore(parsedEndDate))
.collect(Collectors.toList());
}
I have two dates that I want to compare between and find all the workitems(has LocalDate) for the dates. I have one problem though I can't figure out how to check for the same date. When you run a date in my code it works fine untill you write the date that the item was created, then it does not work.
How do I make this work with say 2018-05-28 - 2018-05-28, if the items were created on this day it will not work in my lambda.
If the day is the same day it is not before, nor after, so it will return false in these cases.
You can replace the
isAfter
andisBefore
with a call tocompareTo
and check theint
return value. Less clear in code, but still understandable.I usually use “not before” as a short way to say “on or after”. And the other way around:
Depending on taste you may of course use the more wordy but also more direct