Python bson.EPOCH_AWARE Examples
The following are 1
code examples of bson.EPOCH_AWARE().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bson
, or try the search function
.
Example #1
Source File: test_bsonjs.py From python-bsonjs with Apache License 2.0 | 6 votes |
def test_datetime(self): # only millis, not micros self.round_trip({"date": datetime.datetime(2009, 12, 9, 15, 49, 45, 191000, utc)}) jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000+0000"}}' self.assertEqual(EPOCH_AWARE, bsonjs_loads(jsn)["dt"]) jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000Z"}}' self.assertEqual(EPOCH_AWARE, bsonjs_loads(jsn)["dt"]) # No explicit offset or timezone is not supported by libbson jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000"}}' self.assertRaises(ValueError, bsonjs_loads, jsn) # Localtime behind UTC jsn = '{"dt": { "$date" : "1969-12-31T16:00:00.000-0800"}}' self.assertEqual(EPOCH_AWARE, bsonjs_loads(jsn)["dt"]) # Localtime ahead of UTC jsn = '{"dt": { "$date" : "1970-01-01T01:00:00.000+0100"}}' self.assertEqual(EPOCH_AWARE, bsonjs_loads(jsn)["dt"]) dtm = datetime.datetime(1, 1, 1, 1, 1, 1, 0, utc) jsn = '{"dt": {"$date": -62135593139000}}' self.assertEqual(dtm, bsonjs_loads(jsn)["dt"]) jsn = '{"dt": {"$date": {"$numberLong": "-62135593139000"}}}' self.assertEqual(dtm, bsonjs_loads(jsn)["dt"])