Strange data response for Timezone Offset

I am working on a way for a user to be able to input a location and time for an event. When I create the event, it automatically takes the local-time as the default for the Date-Time input, which is fine if the event is happening in the same time-zone of the current location, but a problem if you want to schedule an event in a different time-zone. (this has been a topic any have commented on, but I have some additional questions below)

So I was trying to create a data field called “Timezone offset” that is calculated from the Location Input’s offset from UTC - Current Location’s offset from UTC, and then use that offset to +(hours) to the date/time input.

Something very strange that is happening is that I save the offset as a number to the database, which is very straight forward. But the database holds the offset number for only a few seconds, and then automatically changes to zero, and I can’t figure out why it does that.

Would anyone know why this wouldn’t work and why the value would change automatically after I have already saved the Timezone Offset (number) to the database?

I’m not sure why Bubble wouldn’t incorporate a time-zone feature into the Date/Time picker, maybe just by adding a location field to the picker…maybe I’m to new to this, but I feel it should be possible and a great feature to add.

Thanks in advance.
Alex

1 Like

I am looking at doing something similar in the next few weeks. I don’t know why your problem is occurring, however it may be an idea to convert your times to UNIX timestamp, that way you have a bit more of an ‘absolute’ number to run your workflows on. Who knows what happens behind the scenes in bubble!

I found out what the issue was. There is a new API by Google called Time Zone API. You have to enable that, on top of all the previously required ones, for the calculation of offset to UTC to be complete. So once I enabled that, it is now correctly saving to the database.

One issue I’m having now is that this Time Zone API cannot be HTTP restricted in Google and needs to be IP address restricted, but it is causing problems if I try to restrict it to my IP address. So I don’t know how I need to restrict it for security purposes…maybe someone else knows how to do that?

There’s another plugin called timezone offset that is free. I had some trouble with the plugin in how it calculates the offset, and it changes based on the time of day.

I have another private one that I can share with your apps. The way I’ve solved this timezone problem is by saving the date as shown on the ui, saving the timezone offset, and then adding the difference between the timezone offset and the local timezone when displaying the date on the UI.

1 Like

I was trying to do exactly that (taking the difference in Timezone offsets from UTC and then adding it to the date/time selector. The problem was that my app wasn’t communicating with the Google Cloud APIs because this month they added a new Google API that is Time Zone API. So it took me a while to realize that and correctly link my website to Google.