Working hours logic - How to automate time calculation?

:question: How to Properly Handle Working Hours Logic in Bubble with Text-Based Time Values?

I’m working on automating working hours logic in my Bubble app. My working hours (Start and End) are stored as text fields in an Option Set. Here’s what I’m trying to achieve:

Goal:

Calculate the due date by adding hours based on scan type deadlines.
If the calculated due date exceeds the working hours (End time), the due date should shift to the next working day*starting from Start time.

Bubble doesn’t seem to handle the text-to-number conversion correctly when comparing working hours.
How can I ensure my working hours comparison works without errors?
Should I switch my Option Set fields from text to numbers, or is there a cleaner workaround for handling working hours

Yes, you should switch those values to numbers to make the calculations a lot easier. And, use 24 hour values. E.g. 1 pm = 13, 2pm = 14, etc.

1 Like

definitely standardize into 24 hr and number format

I am wondering though why you’d need to store number/text and not just a date?
wouldn’t you want to store the date for start and end? there are date time plugins that do this - although honestly they are pretty terrible UX for time selection.

What I normally do is create a reuseable for the date time selector. Put the data picker I like into it, plus then create a custom hour and minute selector to fit the clients preferences. Often this looks like either a dropdown of numbers, or a number input for hour/minute plus most US clients want 12 hr format so I put an AM/PM drop.

Then I write those values all into a date field in the database using “change hours to X” etc.

For a lot of apps I usually also just use UTC since most clients I work with find daylight savings confusing and put in the wrong times when crossing over the changeovers. So using UTC ensures the times never change.

1 Like