Web Connection
wwJsonSerializer datetime conversions
Gravatar is a globally recognized avatar based on your email address. wwJsonSerializer datetime conversions
  Derek
  All
  Mar 26, 2018 @ 01:20pm

I'm having an issue with a new app we're working on here. The times seem to be converting whether AssumeUtcDates = .T. or .F. When true, it seems to be out by the same amount as the time difference between the two computers, when false, it seems to be out 2 hours. The app is supposed to allow clients to create schedules across multiple time zones. The goal here is to save and pull the exact datetime being entered from our existing desktop application as they will be synchronized.

I could be out in left field here, but the issue appears to be this line in wwJsonSerializer.DeserializeJson:

loRes = loSer.DeserializeJsonNet(lcJson)

Before this line of code the Json string shows the correct time. DeserializeJsonNet seems to exist in a DLL and not within the web connection source code.

Does anyone have any idea if I could be doing something wrong, or if not, could there be a work around for this?

Gravatar is a globally recognized avatar based on your email address. re: wwJsonSerializer datetime conversions
  Rick Strahl
  Derek
  Mar 26, 2018 @ 02:12pm

Can you provide some examples of what you're doing exactly? I don't quite follow what you're trying to do...

SerializeJson() serializes to UTC time - it assumes you're using local time and turns the JSON time to UTC time. The AssumeUtcDates property affects whether the input date is converted to UTC or whether it already is UTC which affects how the encoding is performed (ie. whether the time is adjusted).

The Deserialize() function deserializes to local machine time - always. If the JSON includes date time offset (wwJsonSerializer does not do this - we always serialize to UTC - Z offset) then that offset is taken into account. Otherwise, UTC (Z) time is used. This is the default behavior of the JSON deserializer in JSON.NET which the serializer we rely on. So the only way to get back time for a different time zone directly from DeserializeJson() is to be in a different time zone. Otherwise you have to perform offset calculations.

If you switch time zones on the machine you should get consistent results for deserialization for each of the timezones - ie. different values for different timezones. You do have to quit FoxPro to see a new timezone if you change it at the system level I believe.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwJsonSerializer datetime conversions
  Derek
  Rick Strahl
  Mar 26, 2018 @ 02:48pm

Thanks, Rick. Switching the timezone on the web server to GMT seems to have resolved the issue.

Gravatar is a globally recognized avatar based on your email address. re: wwJsonSerializer datetime conversions
  Rick Strahl
  Derek
  Mar 26, 2018 @ 03:10pm

Hmmm... that shouldn't be necessary. Are you on recent bits? There have been tweaks to the way this is handled in recent updates (6.10+ I believe).

+++ Rick ---

© 1996-2024