Recording the correct user's UTC time

Brian is generally right when turning into minutes but there is a little correction to the calculation.

In the case of -3:30
-3 * 60 = -180
+ 30 would give -150 (not -210)

You will have to have to have a way of subtracting minutes when negative hours / adding when positive - ternary expression would do:
time[0] >= 0 ? time[0]* 60 + time[1] : time[0]* 60 - time[1]

2 Likes

Thank you for your help! I always like to close the loop and be helpful to the next person with the same issue. Here is how this was resolved.

After obtaining the TimeZone Difference including UTC with your favourite API - I use the Microsoft BING API https://dev.virtualearth.net/REST/v1/TimeZone/?key=YouNeedToRegister
This value is called "utcOffsetWithDst" and comes in the X:XX format ex 3:30 or -4:15
image

Like @bpj and @Hyperbytes note, you need then to Split it on ":" and do a ternary if hours are positive or negative.
image
image
The formula code is: getTZdifference.data.resourceSets[0].resources[0].timeZoneAtLocation[0].timeZone[0].convertedTime.utcOffsetWithDst.split(':')

I have a variable set to the first part of the split (array[0]) to test if the hours are positive or negative:
image

And the difference is calculated like this, basically hours + or - minutes depending on hours being positive or negative (@bpj comment above)
image
The code is

(TZhours.value >= 0) ? (TZsplit.value[0].toNumber() * 60 +TZsplit.value[1].toNumber()) : (TZsplit.value[0].toNumber() * 60 -TZsplit.value[1].toNumber())

Last, I display any timing by adding the minutes calculated, and formatting to HH:mm
Ex, my created_on database record + addMinutes + formatDate
{{created_on.addMinutes(TZdiff.value).formatDate('MMM d HH:mm')}}

I hope this helps the next person :slight_smile:

2 Likes