Answer the question
In order to leave comments, you need to log in
How to store organization working hours in postgresql?
There is a table of organizations, each organization has working hours:
Monday: 24 hours
Tuesday: from 10:00 to 22:00
Wednesday from 15:00 to 01:00
Thursday closed
How to store all this in jsonb and filter by: open now, open until 23:00, around the clock?
Answer the question
In order to leave comments, you need to log in
Storage is selected based on the goals: the schedule only needs to be shown or it needs to be searched for.
If you only show it, then you can come up with an intricate design in JSON format for any schedule, or you can store it in text, or you can also HTML.
If you want to search, then you need to understand whether it is possible to write a search algorithm using this structure. Perhaps it would be more efficient to represent the schedule as records: on such and such a day of the week from such and such time to such and such time WORKING or vice versa DOES NOT WORK
CREATE table `workinghours` (
`timefrom` unsigner integer COMMENT "Время начала", /*0 ... 2359 - перевод часов минут в целочисленный формат*/
`timeto ` unsigner integer COMMENT "Время окончания", /* 0 ... 2359 */
`weekday` unsigner integer COMMENT "День недели" /* { 1, 2, 3, 4, 5, 6, 7 } */
);
`datefrom` date COMMENT "Начало календарного периода",
`dateto` date COMMENT "Окончание календарного периода",
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question