[CSHARP-392] Create a standard serializer for DateTimeOffset Created: 16/Feb/12  Updated: 20/Mar/14  Resolved: 12/Apr/12

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

Type: New Feature Priority: Trivial - P5
Reporter: Brian Knight Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: bson
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Create a serializer for the DateTimeOffset type based on the Microsoft implementation of DateTimeOffset in JSON. Represent it as a complex type:

{"DateTime":dateTime,"OffsetMinutes":offsetMinutes}

. The offsetMinutes member is the local time offset from Greenwich Mean Time (GMT), also now referred to as Coordinated Universal Time (UTC), associated with the location of the event of interest. The dateTime member represents the instance in time when the event of interest occurred. On serialization, the dateTime member is always serialized in GMT. So, if describing 3:00 AM New York time, dateTime has a time component of 8:00 AM and offsetMinutes are 300 (minus 300 minutes or 5 hours from GMT).



 Comments   
Comment by Robert Stam [ 02/Apr/12 ]

Any feedback on this? I'm planning to close this as "works as designed" soon otherwise.

Comment by Robert Stam [ 16/Feb/12 ]

There already is a standard serializer for DateTimeOffset, but at the time I was unaware that Microsoft had a representation for DateTimeOffset in JSON so the format is just a little different.

By default, it looks like this:

{ "_id" : 1, "Time" : [ NumberLong("634649453952683788"), -300 ] }

If you use [BsonRepresentation(BsonType.Document)] it looks like this:

{ "_id" : 1, "Time" : { "DateTime" : ISODate("2012-02-16T04:30:36.686Z"), "Ticks" : NumberLong("634649454366861830"), "Offset" : -300 } }

The DateTime and Offset fields are almost the same, although the DateTime field is a BsonDateTime and therefore only has millisecond precision, and the offset field is named "Offset" instead of "OffsetMinutes". The Ticks field allows the DateTimeOffset to be round-tripped without loss of precision (but the DateTime field to do DateTime-based queries easily).

Given the existence of this serializer and what it does today, would that meet your needs?

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