0

I am developing a booking spring java application to book a request for specific time (year , month , day , hour , minutes) the request time is fixed by the variable REQUEST_PERIOD , i want a solution to see if the request time is valid or not . more explanation for the problem : the user reserve an appointment if the appointment is valid (not in any other reserved appointment range [request_Time ]) then the system will reserve the request else will reject it .

example :

REQUEST_PERIOD = 100 min;

reserved requests :

 requestA [year : 2018 , month : 5 , day : 1 , hour : 12 , minutes : 40]
 requestB [year : 2018 , month : 5 , day : 1 , hour : 15 , minutes : 30]

new request (valid) :

 requestC [year : 2018 , month : 5 , day : 1 , hour : 18 , minutes : 20]

new request (not valid) :

 requestD [year : 2018 , month : 5 , day : 1 , hour : 15  , minutes : 40]
 requestF [year : 2018 , month : 5 , day : 1 , hour : 15  , minutes : 50]
 requestT [year : 2018 , month : 5 , day : 1 , hour : 15  , minutes : 50]

not valid becouse it in the range requestB time + REQUEST_PERIOD

  • 1
    Separating the dates into year, month, day, and time components is going to set you up for a nightmarish query scenario. You should really just store dates here. As it stands now, this is just the overlapping date range problem, with some added work to convert your columns into single dates. – Tim Biegeleisen Jan 25 '18 at 10:09

1 Answers1

1

A way to solve this problem is to transform the interval times into longs (like unix timestamp) and then search for any overlapping intervals.

To this search, there is an explanation here: search for interval overlap in list of intervals?

gus3001
  • 851
  • 9
  • 19