本文整理匯總了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"])