Data structure to set up shop hours

3

First of all, I found this doubt , which in fact is similar, but did not seem to involve some criteria that I need, such as the hours of operation after midnight.

I'm developing an app where I need to show the 'open / closed' stauts of a store. This time is based on the current time and the 'hours of operation' that the company itself sets up within the administrative panel.

The problem to make this work, is connected with the structure of the database to store this data, because there are some variables. For example, let's say it's a restaurant, and on Thursday it has the following hours: 10h-14h, 19h-02h . In this case the time after midnight, which is still referring to the fifth period, should be played for the sixth day so the Friday would have an operating time like this: 00h-02, 10h-14h, 19h-02h .

This array of data still needs to be returned to front in JSON since the front base is in AngularJs , in addition - for a correct display, every day of the week can only appear once in the array so that there is no confusion on the part of the user at the time of reading.

It may be strange for the user to 'read' that the first time on Friday is from 00h to 02h, and in fact this time is referring to Thursday. So the template (just idea) of how I should return the values would look like this:

qui: 11 - 14, 19 - 23:59, (quebra de dia) 00 - 02

And not like this:

qui: 11 - 14
qui: 19 - 23:59,
sex: 00 - 02

At the moment, I've tried to use the following bank structure:

dia abre1   fecha1  abre2   fecha2
1   11:00   14:00   19:00   23:59
2    --:--   --:--   --:--   --:--
3    --:--   --:--   --:--   --:--
4   11:00   14:00   19:00   23:59
5   11:00   14:00   19:00   23:59
6   11:00   14:00   19:00   23:59
7   11:00   14:00   19:00   23:59

This structure is good, but it has the limitation of being able to have only 2 working ranges (or 3, 4 ... but then it would be necessary to include more columns).

The other tried solution was this:

loja_id    dia  abre    fecha
   1         1  11:00   14:00
   1         1  19:00   23:59
   1         1  00:00   02:00
   1         2  11:00   14:00
   1         2  19:00   23:59
   1         2  00:00   02:00
   1         3   --:--   --:--

However, the problem with this structure is the generation of the final code, putting all Monday times on the same result line.

  • Does anyone know how to improve this structure?
  • Is there any easier way? Or one of those models that I already use the most ideal?
  • Any other consideration?
asked by anonymous 17.11.2015 / 11:09

0 answers