-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 1.7
-
Component/s: None
-
None
-
Minor Change
Make a few small improvements to BsonDateTime:
- DateTime constructor should throw if dateTime is not already in UTC
- remove ToLocalDateTime and ToUniversalTime helper methods
- remove Value property (keep MillisecondsSinceEpoch)
The reason we are going to require that the DateTime passed to the constructor already be in UTC is to emphasize that the database only stores UTC values. If you are passing a local time you probably have a bug anyway (or at least would have wondered why the value you got back when reading it back from the database was different), and this exception alerts you to the fact that you are not working in UTC as required by MongoDB.
Recommended changes if you were are affected by any of these:
var d = new BsonDateTime(dateTime.ToUniversalTime()); var lt = ((DateTime)v).ToLocalTime(); var utc = (DateTime)v; // it's already in UTC var dt = (DateTime)v; // instead of ((BsonDateTime)v).Value
- is depended on by
-
CSHARP-357 Add a way to convert all DateTime values in a BsonDocument to local or universal time
- Closed