235
Views
5
Comments
Solved
[TimezoneReactiveUtils] Timezone offset issue
Question
timezonemobileutils
Reactive icon
Forge asset by Timezone Mobile Utils

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.


Anotao20200623194149.png
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

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.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

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.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

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.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

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.

2020-12-18 10-43-19
Anna Lysek

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;
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Anna,

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

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