Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-729

Serializing a class with two dates to BsonDocument creates wrong value in one date

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Blocker - P1 Blocker - P1
    • None
    • Affects Version/s: 1.8.1
    • Component/s: None
    • Environment:
      Windows 7 Professional 64-bit. Visual Studio 2010 SP1. .Net Framework 4.0. Central Time Zone.
    • Major Change

      The following code will convert both dates to UTC, but with the same hour! This output is produced:

      2:52:26 AM (Notice the hour)
      3:05:26 AM (Notice the hour)
      2013-03-10T08:52:26Z (shows wrong hour. Should be 7, not 8)
      2013-03-10T08:05:26Z (this is correct)

      public class TestDateSerialize
      {
      public DateTime EntryDtTm

      { get; set; }
      public DateTime ExitDtTm { get; set; }

      }

      public void testSerializeDateTime()

      { var obj = new TestDateSerialize(); obj.EntryDtTm = Convert.ToDateTime("3/10/2013 02:52:26"); obj.ExitDtTm = Convert.ToDateTime("3/10/2013 03:05:26"); var doc = obj.ToBsonDocument(); Console.WriteLine(obj.EntryDtTm.ToLongTimeString()); Console.WriteLine(obj.ExitDtTm.ToLongTimeString()); Console.WriteLine(doc["EntryDtTm"].AsBsonValue); Console.WriteLine(doc["ExitDtTm"].AsBsonValue); }

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            paulbrower Paul Brower
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: