For those who don’t like reading, the key here is that MathJS Local calculates difference between text values: say 02 (as text) minus 01 (as text) gives 1 (as number).
Say, we pick 12th July in a Datepicker input while watching football in Moscow, and as a result we would see it as 12th July 00:00:00.
In London we would see this date as 11th July 22:00:00. i.e. -2 hours current time difference.
Wonderful Bubble server would record this date as 11th July 21:00:00 as Bubble seems to store dates in UTC format (by the way UTC is the same as GMT).
Say, we want to have all dates aligned to London time, which in the summer is UTC (GMT) + 1 hour.
The solution is to adjust what Bubble writes down after we pick a date [and time if you wish so].
To have 12th July 00:00:00 seen in London, we would need to pick 12th July 02:00:00 from Moscow.
To do this without determining Moscow’s timezone [which requires user’s permission to get their location], we would need to:
Calculate the difference in hours between Moscow (i.e. user’s current time, while we don’t know their location) and UTC, this would give us +3 hours;
Calculate the difference in hours between London (our preferred timezone) and UTC, this would give us +1 hours;
Calculate the difference in hours between the above two (this is to adjust to summer/winder time difference), the would give us (+3)-(+1)=(+2) hours (this is needed as, for example, in Moscow time doesn’t change for Summer and Winter, while London’s time does change, so we do need to account for that in each date calculation, i.e. we cannot just take current +2 hours difference and apply for all future adjustments);
Adjust date picked by the difference obtained in 3, so take 12th July 00:00:00 picked in the datepicker and add 2 hours.
How do we do the above with Bubble in a stable and reliable way?
By using MathJS Local plugin we are able to calculate differences between texts.
[!!! MathJS doesn’t seem to return number, so we can’t use the result to adjust date later, use MathJS Local]
Equation below is our calculation, which would need to be performed twice to cover Steps 1 and 2 above:
(so “only Hours of Time in Users Current Timezone Format” minus “only Hours of Time in UTC Format”)
[do not worry, although “HH” is returned as text, MathJS does the calculation, in the first part of our calculation we need to have replacement for 00 to 24, also where the difference in less than -12 we would need to add 24 to account for date change between time zone]
[NB the minus sign is typed as text between two dynamic values]
Below is how to get “only Hours of Time in Users Current Timezone Format” (in our case London):
(HH returns only hours)
Below is how to get “only Hours of Time in UTC Format”:
(HH returns only hours)
DO NOT forget that 00 hours should be 24 rather than 00, so we use find & replace, as below:
(you can see this is in calculation above)
Please let me know if you know an easier way or found an error in my thinking, otherwise you are welcome, it took me a day to work out.
Bubble, can we have a Loop function please?, If you like, just allowed a limited it to a reasonable extent number of steps and loops.