[CSHARP-48] TimeSpan serialization not working Created: 02/Jul/10  Updated: 19/Oct/16  Resolved: 04/Jul/10

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Matthias Goetzke Assignee: Steve Wagner
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

in BsonWriter the if statement is missing an else and thus always falls through to the last else which tries to cast the timespan into a long

case BsonType.Long:
if(obj is TimeSpan)
_writer.Write(((TimeSpan)obj).Ticks);
if (obj is DateTime)
Write((DateTime)obj);
else
_writer.Write((long)obj);
return;

should be

case BsonType.Long:
if(obj is TimeSpan)
_writer.Write(((TimeSpan)obj).Ticks);
else if (obj is DateTime)
Write((DateTime)obj);
else
_writer.Write((long)obj);
return;



 Comments   
Comment by Matthias Götzke [ 04/Jul/10 ]

The code was a LOCAL change in our repository and i realized this too late. The change was made since we changed the codebase to store DateTime as long in order to avoid the error with mongo to store datetimes before 1970 correctly.
(see http://jira.mongodb.org/browse/SERVER-405)

Sadly we wrote a test for the changed behavior of DateTime but not Timespan.

We consider the this ticket as closed. It might be interesting though to think about changing the driver to store dates as longs until the mongo issue is fixed.

I am extremely sorry for the mixup.

Comment by Steve Wagner [ 03/Jul/10 ]

Can you tell me where dose you have that code from? In the current code base that looks like:

case BsonType.Long:
if(obj is TimeSpan)
_writer.Write(((TimeSpan)obj).Ticks);
else
_writer.Write((long)obj);
return;

Generated at Wed Feb 07 21:35:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.