A work around for the datetime save/read(?) bug. #2205
-
|
I found out that after saving a DateTime field to file, MessagePack either saves as a random future date, or reads as a random future date. While I have checked the field before saving to make sure it is correct, I am unable to figure out how to poke the resulting file to see if the data was saved correctly. Anyhow, a (probably slow) work around for this bug, is to save dates as strings or longs (anything other than datetime):
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
I suspect what's biting you is that your So take care to set Kind on all your DateTime's before serialization, and you should find the time comes back as intended. Relevant code: MessagePack-CSharp/src/MessagePack/MessagePackPrimitives.Writers.cs Lines 744 to 750 in 44aa149 |
Beta Was this translation helpful? Give feedback.
-
|
Thank you. I must have missed that :/ I will do so! |
Beta Was this translation helpful? Give feedback.
I suspect what's biting you is that your
DateTime.Kindis set to =Unspecified. The MessagePack format requires that all date-time values are serialized as UTC (which is good). But this means that if you leave Kind asUnspecified, we assume it is already (IIRC) UTC and serialize it as such. Then when we deserialize it and you look at Local time, it may be shifted by your time zone if the original Unspecified value was actually local time.So take care to set Kind on all your DateTime's before serialization, and you should find the time comes back as intended.
Relevant code:
MessagePack-CSharp/src/MessagePack/MessagePackPrimitives.Writers.cs
Lines 744 to 750 in 44aa149