O
O
Optimus2017-07-23 18:03:57
PHP
Optimus, 2017-07-23 18:03:57

How to quickly overlay time intervals?

If you make the work mode in JSON (1-7 are the days of the week Mon-Sun, the first value is the work time, the second is the lunch time, then special settings for certain days):

{
"1": "09:00-18:00",
"2": "09:00-18:00",
"3": "09:00-18:00",
"4": "09: 00-18:00",
"5": "09:00-18:00",
"6": "09:00-18:00",
"7": "09:00-17:00",
" 1": "13:00-14:00",
"2": "13:00-14:00",
"3": "13:00-14:00",
"4": "13:00-13:00- 14:00",
"5": "13:00-14:00",
"6": 0,
"7": 0,
"2017-12-31": "09:00-16:00",
" 2018-01-01": 0,
"2018-01-02": "10:00-16:00",
}

Plus, over time, busy time appears, 1 line 1 record for example:
id/date/start/finish
1 2017-07-31 09:00 10:00

Questions:
1. How can now quickly and efficiently superimpose all the records on the time of work and give the client the remaining free periods of time?
2. Do you need a database with a JSON search in this case, i.e. one of the latest versions of mysql or postgresql? After all, then you can not parse the entire JSON every time, but immediately extract the necessary values, for example, to see if there is a unique mode of operation for this date. 3.
Is it not worth storing not lunch time, but 2 working intervals 09:00-13:00 and 14:00-18:00 then lunch time and busy intervals will be brought to the same format
to search for intervals, use one of the ready-made php functions to increase the speed of work?
I thought about the key > value of the database, but I don’t really understand what will be key and what will be value in this case

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fortop, 2017-07-24
Pyan @marrk2

  1. There are no ready-made functions for finding intervals.
  2. And if you do it not in json .... but in a normal way in the form of a database structure?
    That's exactly how you keep busy time
  3. The approach when lunch is the same busy interval as the others is correct

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question