You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it would make more sense if both DateTimeOffset and DateTime don't get converted to local time.
Here is my test code:
varmyInstance=newMyClass(){DateTimeOffsetProperty=DateTimeOffset.UtcNow,DateTimeProperty=DateTime.UtcNow};using(varstore=newDataStore("data.json")){IDocumentCollection<MyClass>collection=store.GetCollection<MyClass>();collection.DeleteMany(_ =>true);// Some cleaningcollection.InsertOne(myInstance);// Serializes DateTimeOffset with local offset and time (incorrect!)// Serializes DateTime as Zulu/UTC and UTC time (correct)}using(varstore=newDataStore("data.json")){IDocumentCollection<MyClass>collection=store.GetCollection<MyClass>();MyClassmyInstanceDeserialized=collection.Find(_ =>true).Single();// DateTimeOffset offset and time are local (incorrect!)// DateTime Kind property and the time are UTC (correct)}stringserialized=JsonConvert.SerializeObject(myInstance);// JSON.NET serializes DateTimeOffset with offset 0 and UTC time (correct)MyClassmyInstanceDeserializedByJsonDotNet=JsonConvert.DeserializeObject<MyClass>(serialized);// JSON.NET deserializes DateTimeOffset to offset 0 and UTC time (correct)
When I manually change data.json to have UTC time and offset for the DateTimeOffset then it still gets deserialized to a local DateTimeOffset.
The text was updated successfully, but these errors were encountered:
I think it would make more sense if both
DateTimeOffset
andDateTime
don't get converted to local time.Here is my test code:
When I manually change data.json to have UTC time and offset for the
DateTimeOffset
then it still gets deserialized to a localDateTimeOffset
.The text was updated successfully, but these errors were encountered: