anerjan / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

If a DateTime is serialized, then unserialized, the .ToBinary string changes. #233

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please include an e-mail address if this might need a dialogue!
==============

What steps will reproduce the problem?

Under .NET 4.0, if a DateTime is serialized, then deserialized, the .ToBinary() 
value changes, due to the fact that its changing the internal time offset. This 
doesn't change the time itself, but it changes the output of 
MyDateTime.ToString("O"); (which includes the time offset).

Example:

Before:

// Prints "2011-09 21T12:05:31.5277993+02:00":
myNow = MyDateTime.ToString("O"); 

After serialization/deserialization:

// Prints "2011-09 21T12:05:31.5277993+01:00":
MyDateTime.ToString("O"); 

Notice that the time itself it exactly the same, down to the nanosecond, but 
the offset has changed by 1 hour, from "+02:00" to "+01:00". In order to 
accommodate the changed offset, the base time has been altered by 1 hour, which 
ends up changing the .ToBinary() output of said DateTime.

If we look at the binary value of the string, we can see:

// Before serialization
"MyDateTime": "\/Date(1316599531526+0200)\/"

// After serialization
"MyDateTime": "\/Date(1316603131527+0100)\/"

You can see that although the time offset changed from "+0200" to "+0100", the 
middle 4 digits changed from 5995 to 6013 to keep the absolute time the same as 
the original.

What is the expected output? What do you see instead?

As above.

What version of the product are you using? On what operating system?

Windows 7 x64, Microsoft Visual Studio 2010 SP1, compiling latest beta version 
of protobuf-net from SVN (as of 2011-09-21) for .NET 4.0.

Please provide any additional information below.

Original issue reported on code.google.com by shane.to...@neuralfutures.com on 21 Sep 2011 at 11:07