本文整理汇总了Python中bson.EPOCH_AWARE属性的典型用法代码示例。如果您正苦于以下问题:Python bson.EPOCH_AWARE属性的具体用法?Python bson.EPOCH_AWARE怎么用?Python bson.EPOCH_AWARE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类bson
的用法示例。
在下文中一共展示了bson.EPOCH_AWARE属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_datetime
# 需要导入模块: import bson [as 别名]
# 或者: from bson import EPOCH_AWARE [as 别名]
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"])