BSON uses Extended Json (v2); and BSON does have a UTC Time/Date function. 
Granted, it converts to Time rather than DateTime. BSON also has marshalling 
support to/from objects.

If interested in that: 
[https://nimble.directory/pkg/bson](https://nimble.directory/pkg/bson)

Example of use with objects:
    
    
    import json
    import times
    import bson
    import bson/marshal
    
    type
      MyType = object
        cannonicalDate: Time
        relaxedDate: Time
    
    marshal(MyType)
    
    let example = """{
       "cannonicalDate": {"$date": {"$numberLong": "1567367316000"}},
       "relaxedDate": {"$date": "2019-08-11T17:54:14"},
    }"""
    
    let parsedJsonDoc = parseJson(example)
    let bsonDoc = interpretExtendedJson(parsedJsonDoc)
    
    var exampleObj = MyType()
    exampleObj.pull(bsonDoc)   # this applies the BSON to the object
    
    assert exampleObj.relaxedDate.format("yyyy-MM-dd\'T\'HH:mm:ss", utc()) == 
"2019-08-11T17:54:14"
    
    
    Run

But, this does not solve the original poster's problem if the JSON he receives 
is not ExtendedJSON compliant.

As to modifying the library, IMO Araq is correct, since JSON does not support 
dates, putting such support into the standard library would be improper. 
Someone could write a nimble support library though.

Reply via email to