I am having some problems where DateTime values sent in RSB messages ,
ultimately stored in an XML file and then later read back are not
reading back the same as the are being submitted in the message.  I
tracked this down to RSB serialization not perserving the Kind
property of the DateTime structure as shown in the following test.

[Fact]
public void Roundtrip_with_datetime_should_preserved_DateTimeKind()
{
    var serializer = new XmlMessageSerializer(new DefaultReflection(),
                                            new
CastleServiceLocator(new WindsorContainer()));

    var stream = new MemoryStream();
    var date = DateTime.Now;
    serializer.Serialize(new object[] { new Bar { Date = date } },
stream);

    stream.Position = 0;

    var bar = (Bar)serializer.Deserialize(stream)[0];
    Assert.Equal(date, bar.Date);  //This passes
    Assert.Equal(date.Kind, bar.Date.Kind); //This fails date.Kind is
local, bar.Date.Kind is UTC
}

Of course part of the problem is the inherent ambiguity of DateTime
when Kind == Local.

It seems to me that the correct solution would be this:
1) If DateTime.Kind == UTC, serialize the time as is, and deserialize
it as is.

2) If Kind == Local, convert the time to UTC based on senders time
zone and serialize that.  Then when deserializing, covert from UTC
back to the receivers timezone on that end (In case they are
different.)  Thoughts?

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino Tools Dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rhino-tools-dev?hl=en.

Reply via email to