Storing Business Hours in a Database

后端 未结 6 666
迷失自我
迷失自我 2020-12-04 07:05

I\'m currently trying to work out the best way to store a business\' hours of operation in a database.

For example:

Business A has the following hours of ope

6条回答
  •  渐次进展
    2020-12-04 07:54

    Most of results works fine for the given scenario, but it wont be as effective if you have periods that runs through multiple days, eg. 8:00 AM ~ 2:00 AM, then I recommend using a multi period design.

       0: [
             id: 1,
             business_id: 1,
             open: true,
             day: 1,
             periods: [
                 0: { open: 08:00, close: 23:59 }
             ]
          ],
       1: [
             id: 2,
             business_id: 1,
             open: true,
             day: 2,
             periods: [
                 0: { open: 00:00, close: 02:00 }
                 1: { open: 08:00, close: 23:59 }
             ]
          ]
    

提交回复
热议问题