Spring boot overlap of two dates

47 views Asked by At

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

0

There are 0 answers