Any tips for managing opening hours?

Hello dear Bubblers!

I’d love getting advices or tips regarding a efficient way to manage opening hours for shops, with Bubble.

These shops can either be opened for the day (from hour H1 to hour H2), either have a break in between (so opened from H1 to H2, than from H3 to H4).

Not sure what’s the best way to achieve this in the database. At the moment, I’ve created 28 fields in my database for each shop… MondayH1, mondayH2, MondayH3 and so on… And I really don’t like that. I’m pretty sure I can do better.

Also, if I’d like to implement a “currently opened” functionality, to let people know in real time if these shops are opened or closed. With my previous (ugly) method, not so easy to provide this result in case a shop opens at 8am but close at 2am (aka closed the day after, at 2am).

Well, that being said, if anybody has good advice or tips, or even tutorial, to share with me/us, I’d be very happy and will pay beers to all :smile:

Cheers

2 Likes

I’ve found a “tips” topic, by @ambroisedlg (thanks Ambroise). My understanding is that I can optimize my implementation (for sure, create a openhours_day data type and instantiate this data type for each of the 7 days of the week. That will avoid these f**king 28 data fields in my shop data type :roll_eyes:

Let’s see. I try to go further and will let you know (at least me :blush:) if I succeed in getting the expected result!

3 Likes

UP - I am experiencing the same issue…

1 Like

did you ever find a solution?

1 Like

Does anyone have a solution for this?

1 Like

See if helps:

Thanks for the reply!

However my question is: how is the best way to structure the data types to avoid having too many fields in order to store the users opening hours?

For each day of the week there are 2 opening hours and 2 closing hours so that would lead up to at least 28 fields. I wonder if there is a more efficient way to do this.

What you can do is to build a database called “Store-hours” to save the opening and closing hours of your users. You can create 14 lines automatically after he creates an account, something with this sctructure:

  • User (Type = User) → To link this line to a specific user
  • Day (Type = number) → To store the day of the week (going from 0 [sunday] to 6 [saturday])
  • Open Hour 1 (Type = number) → To store the first opening hours in minutes
  • Close Hour 1 (Type = number) → To store the first closing hours in minutes
  • Open Hour 2 (Type = number) → To store the second opening hours in minutes
  • Close Hour 2 (Type = number) → To store the second closing hours in minutes
1 Like

Thanks! That really helped.

1 Like