Zaid-Ajaj / LiteDB.FSharp

Advanced F# Support for LiteDB, an embedded NoSql database for .NET with type-safe query expression through F# quotations
MIT License
181 stars 20 forks source link

Fix datetime roundtrip, do not use AsDateTime directly #22

Closed Zaid-Ajaj closed 5 years ago

Zaid-Ajaj commented 5 years ago

fixed #21

The problem seemed to be internal to the tests only and does not affect actual roundtrip values. this is because reading values directly from Bson (what we do in the tests) is not what actually runs with the F# Bson mapper (Entity -> JSON -> Bson -> JSON -> Entity).

Fixed this by applying the same consistent conversion from Bson.readDate as well: Before

module Bson = 
    /// Reads a field from a BsonDocument as DateTime
    let readDate (key: string) (doc: BsonDocument) = 
        doc.[key].AsDateTime

After

module Bson = 
    /// Reads a field from a BsonDocument as DateTime
    let readDate (key: string) (doc: BsonDocument) = 
        let date = doc.[key].AsDateTime
        if date.Kind = DateTimeKind.Local 
        then date.ToUniversalTime() 
        else date