I made a very simple program to demonstrate the problem as simply as possible to myself, and eliminate as many variable as possible.
it connects to Crm with a given user, lets say: bob
bob's timezone is set to CET (currently 2+ offset from UTC as its summer time)
my own computer, where the program runs is also set to CET.
My program does the following:
- as bob, it retrieve a entity
- it fills a datefield on the entity like so: entitie["datefield"] = DateTime.now
- update entity back to CRM.
- and retrieve entity again from CRM and checks the date (the raw UTC value, not the formatted one)
The date is now not the expected 2 hours behind local time, but 4 hours.
The value displayed to the user is therefor 2 hours behind what's expected.
- Changing bobs timezone in CRM to +4 (Baku) and running the program again:
results in 6 hours offset instead of 2
- Setting my computer timezone to +8 (Beijing):
Results in a offset of 12 instead of 2.
so it seems to apply both the local computer's offset where the code runs, AND the user's configured timezone's offset!
I can understand it adjusting for either the PC's local time, OR the users timezone, either one would have made at least some sort of sense.
but not both right?
Can anyone help me and explain whats going on? And is there a way to save local time and have it end up correct? (We do this extensively throughout or code it would be a time consuming to adjust it all)
our on premise installation doesn't have this problem, despite both the user and the server being set to CET.
Crm: (versie 1612 (8.2.2.1259) (DB 8.2.2.339) online)
SKD/DLL version used 8.2.0 (nugets)
(side note: saving the time as entitie["datefield"] = DateTime.UtcNow always gives the correct result.)
*This post is locked for comments