B
B
but1head2019-02-27 10:12:04
PostgreSQL
but1head, 2019-02-27 10:12:04

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

1 answer(s)
P
Pavel Volintsev, 2019-03-02
@copist

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 } */
);

in case the schedule is valid for some calendar period of time, you also need to add a couple of properties
`datefrom` date COMMENT "Начало календарного периода",
`dateto` date COMMENT "Окончание календарного периода",

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question