TimeZome conversion issue with "Date" attributes
STR:
-
Have an entity with
Date
attribute.- For example (a real example):
{ "name": "deliveryDate", "caption": "Delivery Date", "dataType": "Date", "allowNull": false }
- For example (a real example):
-
Client-side: generate a value for the attribute. Many UI controls (most) generate begin of the date in local TZ of the browser.
- That would be a value like
Tue Nov 13 2018 00:00:00 GMT+0200 (Eastern European Standard Time)
:
- That would be a value like
-
Save (insert or update) an instance of the entity with the value.
- Request would looke like:
{ "entity": "pln_ProjectSkuCategory", "method": "update", "execParams": { "ID": 3000000062661, "mi_modifyDate": "2018-11-05T14:53:44.000Z", "deliveryDate": "2018-11-12T22:00:00.000Z" } }
- Note - no handling in
UB.connection
happened, no TZ shifting, nothing. Date value goes to JSON "as is" and in UTC it is not a start of a day anymore.
- Request would looke like:
-
In DB you would have:
| ID | deliveryDate | | 3000000062661 | 2018-11-12 22:00:00.000 |
-
And when you query that value from the server, you'd get (
resultData.data[0]
):[ 3000000062661, "2018-11-12T22:00:00Z" ]
-
This value returned by
selectAsArray
:- NOTE: now the value is all wrong.
EXPECTED:
- The best would be to
UB.connection.query
to patch date values, so that DB would store them as start of the day in UTC. - Though "fixing"
selectAsArray
(to not change value) may look like a fix, it would be not: users with local TZ differ from the user saved the value would see different result, which is highly undesiraeble.
WORKAROUND APPLIED:
- We manually patch value before sending to server as the following:
const deliverDateConverted = new Date((deliveryDate.getTime() / 60000 - deliveryDate.getTimezoneOffset())*60000)