An "Easy" Way to Convert Bubble Date/Times to the Same Date, but in a Different Timezone

@mebeingken we have this already. You’re talking about converting a date/time object to a static, non-date representation, such as a string. The date:formatted as… operator is that.

We can do that all day long, and with a great deal of flexibility.

However: There is no such thing as a date/time object without a GMT offset. A date/time (“date data type in Bubble” – which is the same thing as a "date data type in JavaScript) describes a unique point in time.

What Bubble does not give us an easy way to do is to take a text representation of a date (which, again, we can make with a great deal of flexibility) and, from that representation, create a new date object *with the correct offset from GMT such that the new date object could be said to be “created in some arbitrary timezone”.

And, of course, JavaScript does not give us such a feature either. Hence, packages like moment-timezone, which give us a way to do this with a bit of ease.

(If you’re interested in this, you might want to check out my Timezoner explainer app which might give you an a-ha moment.)

Anyway, the way that moment-timezone is used to create a date in a given zone is to start with an unambiguous text representation of a date/time, create a moment from that, and then turn it back into a JS date object. (If the source thing is an already existing moment, we actually do the same thing.)

1 Like