REST GET and (localized) datetime attributes

1
scenario my mendix application publishes a REST GET api with a datetime attribute in the request In the response i return database records with datetime attribute >= requested datetime attribute Both the request and response datetime attribute are defined in nonpersistent domain attributes with property Localize set to Yes. example My request in SoapUI contains "2017-05-12 14:20:50.000" NB: the time is specified as a localized time in the Mendix debugger i see:  UTC time: 2017-05-12 12:20:50.000 Session time: 2017-05-12 14:20:50.000 +0200 NB: the time is interpreted by Mendix as a localized time. Adding a 'Z' in the timestring at 1. does not make a difference. Mendix keeps seeing it as localized  My response in the Mendix debugger contains: UTC time: 2017-05-12 13:51:54.866 Session time: 2017-05-12 15:51:54.866 +0200 NB: this is a correct selection, as the response time >= request time My response in SoapUI "2017-05-12T13:51:54.866Z" NB: this is a correct result, however presented in UTC or Zulu time. problem To a user this is confusing: i cannot manipulate the fact Mendix interprets request as localized: Mendix does not seem to react to nonpersistent datetime domain attributes. Setting localize to yes or no does not make any difference in described behaviour  i cannot manipulate the fact Mendix responds with a UTC time: Mendix does not seem to react to nonpersistent datetime domain attributes. Setting localize to yes or no does not make any difference in described behaviour for the user it is importent that both request and response time are the same type: either both UTC or both localized   Any ideas?
asked
2 answers
0

Hi R.E. van Wijk,

 

You can set the localization for a DateTime attribute in the entity so Mendix handles the DateTime as UTC time. 

Also using the formatDateTimeUTC and parseDateTimeUTC, you can make sure that only UTC times are used. 

I had a similar issue with date of birth for persons, and have solved it using UTC times.

More information about the DateTime can be found in the following article: https://docs.mendix.com/refguide7/datetime-handling-faq.

 

Hope this helps.

answered
0

solution

  • timezone for rest-user must be UTC
  • datetime-attribute in request must be a string
  • datetime-string can be parsed to datetime using parseDateTime(<datetime-string>, 'yyyy-MM-dd HH:mm:ss.SSS')
  • localization setting of datetime-attribute in response is not important

Using the above steps results in request AND response using UTC

answered