msgpack-cli icon indicating copy to clipboard operation
msgpack-cli copied to clipboard

Pre-Epoch DateTimes With Fractional Seconds Can't Be Serialized

Open adamrodger opened this issue 6 years ago • 4 comments
trafficstars

This code works fine:

DateTime original = new DateTime(1969, 12, 31, 23, 59, 59);
MessagePackSerializer<DateTime> ser = MessagePackSerializer.Get<DateTime>();
byte[] b = ser.PackSingleObject(original);
Console.WriteLine(string,Join(", ", b));

---> 199, 12, 255, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255

but when I add fractions of a second the code breaks:

DateTime original = new DateTime(1969, 12, 31, 23, 59, 59).AddTicks(1); // 100ns
MessagePackSerializer<DateTime> ser = MessagePackSerializer.Get<DateTime>();
byte[] b = ser.PackSingleObject(original);

---> System.ArgumentOutOfRangeException : nanoseconds must be non negative value and lessor than 999,999,999.
Parameter name: nanoseconds
   at MsgPack.Timestamp.FromDateTime(DateTime value)
   at MsgPack.Serialization.DefaultSerializers.TimestampDateTimeMessagePackSerializer.PackToCore(Packer packer, DateTime objectTree)
   at MsgPack.Serialization.MessagePackSerializer`1.PackTo(Packer packer, T objectTree)
   at MsgPack.Serialization.MessagePackSerializer`1.PackSingleObjectAsBytes(T objectTree)
   at MsgPack.Serialization.MessagePackSerializer`1.PackSingleObject(T objectTree)

As far as I can tell this should be serialising to the Timestamp 96 format which supports pre-epoch timestamps and fractional seconds, but this seems to be a bug in the serialisation to Timestamp 96.

adamrodger avatar Jan 15 '19 08:01 adamrodger

Sorry, just realised this is a duplicate of #296

Please could we release the fixed version? I notice there's a tag for v1.0.1 but the latest on nuget.org is 1.0.0

adamrodger avatar Jan 15 '19 09:01 adamrodger

Ah, sorry for delaying release. I've just busy to maintain source, but it should be fixed in fix/#296-1.1 branch. I will release the fix in few weeks.

yfakariya avatar Feb 03 '19 08:02 yfakariya

I forgot that it should be released as 1.0.1, but I also found that the released process failed. I will fix the pipeline and release it to the NuGet soon.

yfakariya avatar Feb 03 '19 08:02 yfakariya

I have just released 1.0.1 including fix of #296 (and #312) issues.

yfakariya avatar Feb 03 '19 11:02 yfakariya