28
Views
14
Comments
Solved
Assign add an hour to DateTime parameter
Application Type
Traditional Web

Hi everyone,

my issue is the following: I'm retrieving from external source (API Rest that get data from one database) a list of elements which are one DateTime parameter. Everything seems go well until I represent the data in a table. We the data is shown in the table the DateTime attribute has added an hour... 

I've debugged the code until the last point before paint the data over the table and the data remains well (with the same value that in the database) so far... However, when the data is shown, the datatime parameter appears with one hour more... I don't now the reason...

NOTE: I've tried to represente the data as text but the test wasn't work...

Thank you for your help in advance!

Best regards!

Solution

Outsystems always transfer datetime in UTC.

Then convert to device time zone when displaying it.

Yes, this is tricky in some use case.

I had a salesforce app which is used across 3 time zone, and user want to show the time as is.

My solution was to store a Text datatype attribute which stored the formatted text of datetime that was calculated in Client Action logic (to prevent time zone conversion).

Solution

Hi @Manuel Rubio ,

This is just how it works, in Reactive, DateTimes are assumed to be stored in the timezone of where the server is, and are presented to the user in their own timezone.  So whenever a timezone value is brought from server to device, Outsystems does the conversion for you.

If that is not right for your usecase, the easiest solution is to get away from the datetime format at some point before bringing your data to the UI from the server.  

So your starting point is an API, right, so you are using a dataAction to fetch data from that api ?

Just add extra fields in your dataAction output structure, to contain a converted value of that datetime.  This could be a single text attribute, or a separate date and time attribute, dependant on what you plan to do with the information on client side.

After getting response from the api, fill your dataAction output, and do the conversion of the datetime there.  On device side, use this converted attribute instead of the datetime attribute itself.

Dorine

Hi @Dorine Boudry ,

I was thinking in the solution that you provide me as @Harlin Setiadarma told me. Finally, I'll do it but for me it's very strange that ODC does this kind of things... Maybe this behavoir shuold be optional or configurable otherwise I have to create a addtional text attribute for each DateTime that my data has...

Thanks for your help and your solution!

Best regards!

the assumption they made, is that in most cases where a datetime is used, users on different timezones want to know when something happened in relation the their own clock.  For example, when I'm here on the forum, I now see that you replied 3 minutes ago, but I also see a datetime at the top of my reply saying I'm replying to your comment of 09:45:23.  For me as  a user that's very confusing, because in my world, you made that reply at 10:45, not 09:45.  

So this is the problem they are trying to solve by auto converting.  I think in most cases, that's ok, except when it is not.

Dorine

I agree with you but, according with your example, it should be configurable, isn't it? Anyway, thank you for your help and your advices!

Thank you so much!

Regards!

Hi,


This could be due to time zones, are you in a different timezone than UTC?

Hello,

maybe this is the reason but not my solution because I need to show the real time without transformation... I mean, the information that I want to show is like a Log of the system so I need that the Date and Time are the same that database...

I hope to explained myself well... or  at least describe the need of the application...

Thanks for your answer but it's no valid to fix my problem...

Best regards!

Hi,

what you can you can do is convert your time to UTC, because OutSytems Cloud runs in UTC. You can use this Component for it, and use the Server Action  "ConvertToUTC" this way the DateTime is in UTC just like all other OutSystems Date times, and it should display in your local time on the client side. 


https://www.outsystems.com/forge/component-overview/11419/time-zone-service 

Hi Manuel, 

As a workaround, you can format your DateTime values on the server side. After that they behave as text, without timezone impact.

Hi Damian,

the question is not the Time Zone but why ODC change the value. Althoug the Time Zone is different the date is the date and ODC don't have to change the value adding an hour. This is the point.

Thanks for your help!

Regards!

Hi Daryne,

Even doing this conversion ODC add an hour...It's a mess!

Thanks for your help!

Regards!

Hi,

I understand the confusion, but what happens is that you get a date from a remote database, OutSystems will parse this, but by default OutSystems thinks this is UTC, so OutSystems handles the date as UTC, but when you display it on a screen your browsers sees UTC, and converts it to your local time zone.

What you can do is trick OutSystems by casting your datetime to UTC by providing the origin timezone, this way the date is now the correct date as UTC, and your browser wil parse this again to the correct datetime.

I hope my explanation is clear, and I understand your confusion 

Hi Damian,

I could try your advice but, I don't know why, I think that it will happen the same... I'm going to give you more background of the issue. In the following pictures you can see the problem:

When I retrieve the data (see the picture below), I have the datetime value well:

But when this value is shown in the front automatically ODC add an hour:

I don't know why...

So, regarding to your advice @Damian Fonville, I expect that even I cast the data to DateTime UTF the problem will appear again...

Thanks for your help!

Regards!


Hi, 

Please try my advice, because now Outystems thinks the DateTime in the database is UTC, but it really is a different time zone, by converting it to UTC, OutSystems will work correctly with the datetime, and then convert the time in the table again to your local time zone. 

Solution

Outsystems always transfer datetime in UTC.

Then convert to device time zone when displaying it.

Yes, this is tricky in some use case.

I had a salesforce app which is used across 3 time zone, and user want to show the time as is.

My solution was to store a Text datatype attribute which stored the formatted text of datetime that was calculated in Client Action logic (to prevent time zone conversion).

Solution

Hi @Manuel Rubio ,

This is just how it works, in Reactive, DateTimes are assumed to be stored in the timezone of where the server is, and are presented to the user in their own timezone.  So whenever a timezone value is brought from server to device, Outsystems does the conversion for you.

If that is not right for your usecase, the easiest solution is to get away from the datetime format at some point before bringing your data to the UI from the server.  

So your starting point is an API, right, so you are using a dataAction to fetch data from that api ?

Just add extra fields in your dataAction output structure, to contain a converted value of that datetime.  This could be a single text attribute, or a separate date and time attribute, dependant on what you plan to do with the information on client side.

After getting response from the api, fill your dataAction output, and do the conversion of the datetime there.  On device side, use this converted attribute instead of the datetime attribute itself.

Dorine

Hi @Dorine Boudry ,

I was thinking in the solution that you provide me as @Harlin Setiadarma told me. Finally, I'll do it but for me it's very strange that ODC does this kind of things... Maybe this behavoir shuold be optional or configurable otherwise I have to create a addtional text attribute for each DateTime that my data has...

Thanks for your help and your solution!

Best regards!

the assumption they made, is that in most cases where a datetime is used, users on different timezones want to know when something happened in relation the their own clock.  For example, when I'm here on the forum, I now see that you replied 3 minutes ago, but I also see a datetime at the top of my reply saying I'm replying to your comment of 09:45:23.  For me as  a user that's very confusing, because in my world, you made that reply at 10:45, not 09:45.  

So this is the problem they are trying to solve by auto converting.  I think in most cases, that's ok, except when it is not.

Dorine

I agree with you but, according with your example, it should be configurable, isn't it? Anyway, thank you for your help and your advices!

Thank you so much!

Regards!

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