-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 1.3
-
Component/s: None
-
None
-
Minor Change
When a BsonDocument is read back from the database all DateTime values are in UTC. It would be nice to have a helper method that walked the BsonDocument and converted all DateTime values to LocalTime. For example:
var document = collection.FindOne(); // DateTimes are in UTC
document.ToLocalTime(); // converts any DateTime values found to LocalTime (in place)
While less frequently useful, for symmetry there should probably be a ToUniversalTime method as well.
An alternative to consider is whether there should be a mode (on the collection?) that would cause all DateTimes to be automatically converted to LocalTime without having to call a helper method. Although the helper method is by far simpler to implement.
As an aside, I recommend that you always keep your DateTimes in UTC throughout, and only convert them to LocalTime when displaying them to the user. But I know that many developers prefer to just do a wholesale conversion to LocalTime after reading from the database, so this helper method would be attractive to them.
- depends on
-
CSHARP-567 Improvements to BsonDateTime class
- Closed