[CSHARP-2440] Add DateTime representation to DateTimeOffsetSerializer Created: 24/Nov/18 Updated: 28/Oct/23 Resolved: 28/Jan/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Serialization |
| Affects Version/s: | 2.7.2 |
| Fix Version/s: | 2.15.0 |
| Type: | New Feature | Priority: | Trivial - P5 |
| Reporter: | Lukas Vosyka | Assignee: | Robert Stam |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Description |
|
Hi all, I was wondering why the decision was made to not allow a BsonType.DateTime to be (de)serialized as DateTimeOffset? I know you loose the Offset, etc. but I think this is not a big deal. Converting DateTimeOffset to and from DateTimes is generally a valid operation, so why not allowing it in MongoDB C#? Just curios, because it could help, when someone has to handle with DateTimeOffset in models but wants to be persisted as BsonType.DateTime. |
| Comments |
| Comment by James Kovacs [ 31/Jan/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Reverted because this shouldn't have been cherrypicked into a patch release. Will be released in 2.15.0. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 31/Jan/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'James Kovacs', 'email': 'jkovacs@post.harvard.edu', 'username': 'JamesKovacs'}Message: Revert " This reverts commit 29b312a734f7ccea8174a268128b1f6fd23c4ec1. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 31/Jan/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}Message: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 28/Jan/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}Message: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Lukas Vosyka [ 03/Dec/18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Ian, thanks for the response. Ok, I understand that. You could leave the default as is, just adding more serializer by default that cover such scenarios? By definition MongoDB saves BsonType.DateTime as being UTC. Hence anyone who needs to save a DateTimeOffset into MongoDB should already be aware of the fact, that it will and should be stored as a conversion to UTC datetime. Deserialization is then natural to result also into a DateTimeOffset with zero offset. That is my reasoning of why it should not be a big deal. As you suggested, I already created an own serializer. I will leave the code here for reference, if someone is interested:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ian Whalen (Inactive) [ 03/Dec/18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hey lukster - Although losing the offset after serializing might not be a big deal to all users, we believe that there are definitely users for whom this would be extremely surprising, and so we've chosen an API that tries to minimize any such surprises. We will consider for the future adding non-default functionality to do this for those who really know what they're doing. In the meantime you could write and register your own serializer. |