My REST app makes a query and the result is this
but when i receive data in json format on client side i have this result
where date values are different from those in my cursor.... One day less....
Why ?
Thanks
I found AssumeUtcDates property.... But if i want to change it i need to change directly in wwjsonserializer.prg ? or not ?
It's a property of the class, change it in the instantiated object.
loSer = CREATEOBJECT("wwJsonSerializer")
loSer.AssumeUtcDate = .T.
You really should not mess with the date format in the JSON. By default the date will be in UTC format and will get adjusted when you deserialize. IOW, if you do two way serialization the date in and out will be the same.
DO wwJsonSerializer
ldDate = DATETIME()
? ldDate && 04/20/2022 10:15:45 AM
loSer = CREATEOBJECT("wwJsonSerializer")
lcJson = loSer.Serialize(DATETIME())
? lcJson && "2022-04-20T20:15:45Z"
ldDate2 = loSer.Deserialize(lcJson)
? ldDate2 && 04/20/2022 10:15:45 AM
ASSERT(ldDate2 == ldDate)
You don't want the date to be in local date format in the JSON. because then every client will have to explicitly know that the data is in some specific date format and has to be calculate the date offset if dates are deserialized in a different time zone.
Not recommended.
The only reason you should use the lAssumeUtcDates
flag is to deserialize JSON that has dates that are not UTC in the first place (which should be rare).
+++ Rick ---