Localized DateTimes in Widgets

0
So I have a page in our app that is displaying Time portions of date-times using a CustomString widget, which is getting the time as a string from a Microflow that is just doing the following: formatDateTime($Statistics/Start,'HH:mm'). This attribute is localized in the Domain Model, and appears to be using the timezone set by the user (users can choose their own timezone). I then have a custom widget which I have written that is getting another DateTime which is also localized in the Domain Model, and I am using the Time portion of that within the custom widget. However, this Time does not seem to be sent to the widget localized, it seems to be the UTC time. Is there something specific I need to do within the widget to either get the localized time, or to convert it? I did some searching in the API documentation but didn't find anything obvious. I would prefer to not have to use the browser UTC offset, but instead use the timezone set by the user in Mendix. Anybody have some knowledge about this? Thanks!
asked
4 answers
3

Ok, so I did basically what Jeroen suggested.

You can get information about the current logged in user by using the mx.session.getUserAttribute() function, so I used it to get the association (GUID) to the TimeZone object for that user, then I used mx.data.get() to get the actual TimeZone object using that GUID.

After that, I got the RawOffset attribute of the TimeZone object. This is in milliseconds, and so is the value returned from MxObj.get() when used on a DateTime field. So, you can just use MxObj.get() to get the DateTime value and then add the RawOffset value to it directly, then in JavaScript, create a Date object with the resulting sum.

After that, it looks like the times coming from both sources are matching up.

answered
2

Hi David,

Have a look at this datetime faq in the docs.
In brief:

  • When parsing a datetime on the server, the users timezone setting is used.
  • When parsing a datetime in the browser, the browers locale or the UTC locale is used

 

Unfortunatly, I don't know a neat way to deal with this in the widget.
Perhaps you could retrieve the System.TimeZone for the current user and apply the offset to the date that you receive before formatting it, but that might also lead to some inconsistencies on the long run..

Hope it at least gives you a little more info.

answered
2

I think you can use

dojo.date.locale.format

 

answered
0

Ok, so coming back to this issue, I've noticed that the DateTime offset I'm getting in the widget is not being adjusted for Daylight Savings. Currently here in the Netherlands, we are in CEST, which is GMT + 2:00, but the offset I'm getting in the widget is still GMT + 1:00, which is our normal timezone. However, times shown in the browser through, for instance, a Date Picker widget, are being adjusted to GMT + 2:00 because the browser is reporting that I'm in CEST. 

According to the DateTime FAQ that Jeroen mentioned, timezone should be adjusted automatically for daylight savings time, but that doesn't seem to be the case, or I'm doing something wrong. Anyone have any thoughts?

answered