[TimezoneReactiveUtils] Timezone seems to be reversed
timezonemobileutils
Reactive icon
Forge component by Magda Pereira
Application Type
Reactive
Service Studio Version
11.14.16 (Build 60354)

Greetings, due to a issue I had I installed this component ... but it doesn't seem to work as expected. 

In an expression, I used the function GetCurrentTimezoneOffset() but to my surprise it returned -120 whereas I would have expected it to return 120. 

Because of this, I did some more digging, and to my surprise, when I created a expression that explictely creates a datetime, and use the ConvertDateTimeByTimeZoneOffset function it actually end up in less than UTC time, instead of a later timezone ( as mentioned before, I'm with DST currently in +2h )

To be preciese, the following expression 

FormatDateTime(NewDateTime(2022,5,20,10,0,0), "yyyy MMM d HH:mm")+NewLine()+
FormatDateTime(ConvertDateTimeToUTC(NewDateTime(2022,5,20,10,0,0)), "yyyy MMM d HH:mm")+NewLine()+
FormatDateTime(ConvertDateTimeByTimezoneOffset(NewDateTime(2022,5,20,10,0,0),TextToInteger(GetCurrentTimezoneOffset())),"yyyy MMM d HH:mm")

leads to this output

Perhaps I'm using it wrong ( I am fairly new to outsystems .. so this is not unthinkable ) ... but if so I have to say that it has been implemented rather counter intuitive. If I am using it right, then I think there is an issue ...

Hope to hear from  you soon.

Kind regards,

Vincent

mvp_badge
MVP
Solution

Hi Vincent,

I just published a new version, 1.0.3, that has the bug fixed. Could you please try and see whether it meets your expectations? Thanks in advance!

Hey Kilian,

ConvertDateTimeByTimezoneOffset now does work as expected! To be honest, I still find the value for GetCurrentTimezoneOffset counterintuitive ... but you yourself said the same thing. Thanks for the quick reply.

kind regards,

Vincent

mvp_badge
MVP

Yeah, I would've done it differently, but too late to change it now without a breaking change to all existing code...

mvp_badge
MVP

Hi Vincent,

There's a number of things to say here. First, GetCurrentTimezoneOffset just returns the JavaScript timezone offset, which is counterintuitive, as it is calculated by subtracting the local time from the UTC time. Since we are ahead of UTC, the result is negative. This is described here.

Secondly, there's an obvious bug in the ConvertDateTimeByTimezoneOffset code. The code first converts the date time to UTC, then adds the number of minutes to the UTC date time as returned by GetCurrentTimezoneOffset. As your example shows, this yields the wrong results.

I'll see if I can upload a new version shortly.

ah, so it's a bit of both ... a bit counter intuitive, but also a bug! Thank you for the quick reply, and perhaps it's usefull to add this javascript explanation to the documentation so it's clear that the offset is in fact inverted.

Anyway, knowing this, it is a usefull addition!

mvp_badge
MVP

Agree with the documentation, but that's pretty lacking at the moment. I'll see if I can add something.

mvp_badge
MVP
Solution

Hi Vincent,

I just published a new version, 1.0.3, that has the bug fixed. Could you please try and see whether it meets your expectations? Thanks in advance!

Hey Kilian,

ConvertDateTimeByTimezoneOffset now does work as expected! To be honest, I still find the value for GetCurrentTimezoneOffset counterintuitive ... but you yourself said the same thing. Thanks for the quick reply.

kind regards,

Vincent

mvp_badge
MVP

Yeah, I would've done it differently, but too late to change it now without a breaking change to all existing code...

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.