[TimezoneReactiveUtils] Timezone offset issue

Forge Component
Published on 29 Jun (8 days ago) by João Barata
1 vote
Published on 29 Jun (8 days ago) by João Barata

There is an issue when using this component for timezones with an offset that is not a full hour value.

I've tried it by changing my device timezone to the Tehran timezone (UTC + 04:30) and the UTC timestamp returned by the action was off by 30 minutes.

In the image, the first value is the current device datetime, the second is datetime returned by the component's GetUTCTime action and the 3rd is the true UTC datetime.

Hi Anna,

This seems a bug in the component. If only provides for offsets of one hour, per this line of code:

var utc_timestamp = now.setHours(now.getHours()+offset);

Unfortunately my time's up for today, if the maintainers don't respond I'll see if I can do something about it tomorrow.

Hi Anna,

Could you try replacing the following three lines from GetUTCTime:

var offset = timezone/60;

var utc_timestamp = now.setHours(now.getHours()+offset);

var utc_time = new Date(utc_timestamp);

to this:

var utc_time = new Date(now.getTime() + timezone * 60000)

and see if this works for you? If so, I'll try to join this team and fix the bug.


Come to think of it, since OutSystems already uses UTC date/times on mobile, it's probably possible to change the output parameter type to DateTime, reduce the entire action to only the JavaScript node with these lines:

var now = new Date();
var utc_time = new Date(now.getTime() + now.getTimezoneOffset() * 60000);
$parameters.utc_datetime = utc_time;

But I'd have to check whether this always works.


Thank you for your answers Kilian,

I've tried both your suggestions and both work great. I also tried a different approach which also yields the same result.

This is the same test as yesterday, Tehran timezone (UTC + 04:30).

My version uses the getUTC... methods to avoid using the offset. Thank you for your answers which helped me make it more concise.

var utc_time = new Date();

var time = new Date(utc_time.getUTCFullYear(),utc_time.getUTCMonth(),utc_time.getUTCDate(),utc_time.getUTCHours(),utc_time.getUTCMinutes(),utc_time.getUTCSeconds());

$parameters.utc_datetime = time;

Hi Anna,

Glad I could be of help. I didn't know the getUTC variants, thanks for mentioning them!