0

i need solution where i need to check overlap, end-start match and start-end match like

startDateTime=2020-10-24T11:30:34 endDateTime=2020-10-27T17:00:02

jpqlQuery.where(
                (
                    (start.loe(startDateTime)
                    .and(end.goe(startDateTime)))

                    .or((start.loe(endDateTime)
                    .and(end.goe(endDateTime))))

                    .or((start.loe(startDateTime)
                    .and(end.goe(endDateTime))))

                    .or((start.loe(endDateTime)
                    .and(end.goe(startDateTime))))
                    )
                );

need to replace where for following scenarios

Scenario ------------------------- Result
start: 2020-10-24T11:30:34
end: 2020-10-27T17:00:02 -- false

start: 2020-10-24T11:30:34
end: 2020-10-28T17:00:02 -- false

start: 2020-10-23T11:30:34
end: 2020-10-25T17:00:02 -- false

start: 2020-10-25T11:30:34
end: 2020-10-26T17:00:02 -- false

start: 2020-10-23T11:30:34
end: 2020-10-28T17:00:02 -- false

start: 2020-10-28T11:30:34
end: 2020-10-30T17:00:02 -- true

start: 2020-10-22T11:30:34
end: 2020-10-23T17:00:02 -- true

start: 2020-10-22T11:30:34
end: 2020-10-24T11:30:34 -- true

start: 2020-10-27T17:00:02
end: 2020-10-30T17:00:02 -- true

all above scenarios should work under single where condition

umesh
  • 155
  • 1
  • 9
  • 2
    Does this answer your question? [Determine Whether Two Date Ranges Overlap](https://stackoverflow.com/questions/325933/determine-whether-two-date-ranges-overlap) – kasptom Oct 24 '20 at 12:15
  • i think it's not covering these cases start: 2020-10-22T11:30:34 end: 2020-10-24T11:30:34 -- true start: 2020-10-27T17:00:02 end: 2020-10-30T17:00:02 -- true – umesh Oct 25 '20 at 06:38
  • You have to slightly tweak the linked answer. If you want to find the ranges that don't overlap (excluding common limits of the ranges) then you have to: 1) negate the `(StartA <= EndB) and (EndA >= StartB)` what gives ([De Morgan's laws](https://en.wikipedia.org/wiki/De_Morgan%27s_laws)):`(StartA > EndB) or (EndA < StartB)`. 2) Additionally, as we include the common limits now, you have to change the inequalities to the weak ones, so: `(StartA >= EndB) or (EndA <= StartB)` - that is the condition we want to check – kasptom Oct 25 '20 at 08:36
  • 1
    Thanks kasptom, i am done with just removing equal condition at all places, in my where condition. – umesh Oct 26 '20 at 04:35

0 Answers0