| @@ -232,12 +232,16 @@ class DateTimeField(BaseField): | ||||
|     """A datetime field. | ||||
|  | ||||
|     Note: Microseconds are rounded to the nearest millisecond. | ||||
|       Pre UTC microsecond support is effecively broken see | ||||
|       `tests.field.test_datetime` for more information. | ||||
|       Pre UTC microsecond support is effecively broken. | ||||
|       Use :class:`~mongoengine.fields.ComplexDateTimeField` if you | ||||
|       need accurate microsecond support. | ||||
|     """ | ||||
|  | ||||
|     def validate(self, value): | ||||
|         assert isinstance(value, datetime.datetime) | ||||
|         assert isinstance(value, (datetime.datetime, datetime.date)) | ||||
|  | ||||
|     def to_mongo(self, value): | ||||
|         return self.prepare_query_value(None, value) | ||||
|  | ||||
|     def prepare_query_value(self, op, value): | ||||
|         if value is None: | ||||
|   | ||||
| @@ -182,6 +182,9 @@ class FieldTest(unittest.TestCase): | ||||
|         log.time = datetime.datetime.now() | ||||
|         log.validate() | ||||
|  | ||||
|         log.time = datetime.date.today() | ||||
|         log.validate() | ||||
|  | ||||
|         log.time = -1 | ||||
|         self.assertRaises(ValidationError, log.validate) | ||||
|         log.time = '1pm' | ||||
| @@ -199,6 +202,15 @@ class FieldTest(unittest.TestCase): | ||||
|  | ||||
|         LogEntry.drop_collection() | ||||
|  | ||||
|         # Test can save dates | ||||
|         log = LogEntry() | ||||
|         log.date = datetime.date.today() | ||||
|         log.save() | ||||
|         log.reload() | ||||
|         self.assertEquals(log.date.date(), datetime.date.today()) | ||||
|  | ||||
|         LogEntry.drop_collection() | ||||
|  | ||||
|         # Post UTC - microseconds are rounded (down) nearest millisecond and dropped | ||||
|         d1 = datetime.datetime(1970, 01, 01, 00, 00, 01, 999) | ||||
|         d2 = datetime.datetime(1970, 01, 01, 00, 00, 01) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user