3
First of all, found that doubt, which in fact is similar, but did not seem to involve some criteria I need, such as opening hours 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 'working hours' that the company itself configures within the administrative panel.
The problem to make this work is connected with the database structure 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 opening hours: 10h-14h, 19h-02h
. In this case the time after midnight, which is still referring to the Thursday period, should be played for the day of Friday so the Friday would have a working time like this: 00h-02, 10h-14h, 19h-02h
.
This data array still needs to be returned to the front
in JSON
for the basis front
is in AngularJs
, in addition - for a correct view, each day of the week can only appear once in the array, so there is no user confusion at the time of reading.
Because it can be strange for the user to 'read' that the first time of Friday is from 00h to 02h, and in fact this time is related to Thursday. So the model (just an idea) of how I should return the values would be 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 time, I 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 has the limitation that there can be only 2 working intervals (or 3, 4... but then it would be necessary to include more columns).
The other solution tried 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 of this structure is the generation of the final code, in putting all Monday times in the same result line.
- Does anyone know how to improve this structure?
- Is there an easier way? Or one of these models that I already use the most ideal?
- Any other consideration about?
in that reply i proposed a solution for a chronometer, which are recorded in the database start and end times, which can be adapted to your problem.
– Pedro Sanção
It is, but the biggest problem is in the part of the schedule with the change of day, in case the store has a schedule that exceeds midnight, but is still related to the previous day.
– celsomtrindade
in the case I mentioned, they are used timestamps, and you can extract only the time, so that it is indifferent of past midnight or not, now I am without time to write a complete reply, but it can help
– Pedro Sanção
Yes yes, I am seeing your answer there and I see if I can adapt something, because, if I understand your orientation, the problem is not the manipulation of the date as a time, it is just the play of the days. But I’ll take it easy now
– celsomtrindade