Python mongoengine 模块,DateTimeField() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用mongoengine.DateTimeField()

项目:mongoengine_utils    作者:aiscenblue    | 项目源码 | 文件源码
def setUp(self):
        """Setup test."""
        from datetime import datetime, timedelta
        from calendar import timegm

        class DateTime(db.Document):
            date = db.DateTimeField()

        self.model_cls = DateTime
        now = datetime.utcnow()
        epoch_mil = int(timegm(now.timetuple())*1000 + now.microsecond / 1000)
        self.data = json.dumps({"date": epoch_mil})
        self.expected_data = {
            "date": datetime.utcfromtimestamp(
                        int(epoch_mil / 1000)
                    ) + timedelta(milliseconds=int(epoch_mil % 1000))
        }
        self.hook = generate_object_hook(self.model_cls)
项目:mongoengine_utils    作者:aiscenblue    | 项目源码 | 文件源码
def setUp(self):
        """Setup test."""
        from datetime import datetime

        class DateTime(db.Document):
            date = db.DateTimeField()

        self.model_cls = DateTime
        now = datetime.utcnow()

        # This format shouldn't be supported.
        self.data = json.dumps({"date": {
            "year": now.year,
            "month": now.month,
            "date": now.day
        }})
        self.hook = generate_object_hook(self.model_cls)
项目:mongoengine_utils    作者:aiscenblue    | 项目源码 | 文件源码
def setUp(self):
        """Setup test."""
        from datetime import datetime
        from dateutil.parser import parse

        class DateTime(db.Document):
            date = db.DateTimeField()

        self.model_cls = DateTime
        now = datetime.utcnow()
        self.data = json.dumps({"date": now.isoformat()})
        self.expected_data = {"date": parse(now.isoformat())}
        self.hook = generate_object_hook(self.model_cls)