{"action":"closed","issue":{"url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/910","labels_url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/910/labels{/name}","comments_url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/910/comments","events_url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/910/events","html_url":"https://github.com/MongoEngine/mongoengine/issues/910","id":63088327,"number":910,"title":"ComplexDateTimeField lexographic comparison is broken","user":{"login":"jimmyshen","id":548125,"avatar_url":"https://avatars.githubusercontent.com/u/548125?v=3","gravatar_id":"","url":"https://api.github.com/users/jimmyshen","html_url":"https://github.com/jimmyshen","followers_url":"https://api.github.com/users/jimmyshen/followers","following_url":"https://api.github.com/users/jimmyshen/following{/other_user}","gists_url":"https://api.github.com/users/jimmyshen/gists{/gist_id}","starred_url":"https://api.github.com/users/jimmyshen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jimmyshen/subscriptions","organizations_url":"https://api.github.com/users/jimmyshen/orgs","repos_url":"https://api.github.com/users/jimmyshen/repos","events_url":"https://api.github.com/users/jimmyshen/events{/privacy}","received_events_url":"https://api.github.com/users/jimmyshen/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-03-19T20:49:31Z","updated_at":"2015-04-29T20:45:21Z","closed_at":"2015-04-29T20:45:21Z","body":"Hi,\r\n\r\nI've run into a bug where the microsecond part of a datetime is not serialized with leading zeros (should be 6 digits long). This breaks being able to use it in lexographic comparisons. See test below:\r\n\r\n```python\r\nfrom datetime import datetime\r\nimport mongoengine\r\n\r\n\r\ndef test_complex_datetime_lexographic_comparison():\r\n    class TestDocument(mongoengine.Document):\r\n        timestamp = mongoengine.ComplexDateTimeField()\r\n\r\n    connection = mongoengine.connect('test')\r\n    connection.drop_database('test')\r\n\r\n    timestamp = datetime.now()\r\n    older = timestamp.replace(microsecond=99)\r\n    newer = timestamp.replace(microsecond=999)\r\n    upper = timestamp.replace(microsecond=1000)\r\n\r\n    older_doc = TestDocument(timestamp=older)\r\n    older_doc.save()\r\n    newer_doc = TestDocument(timestamp=newer)\r\n    newer_doc.save()\r\n\r\n    assert len(TestDocument.objects(timestamp__lte=upper)) == 2\r\n\r\n\r\ntest_complex_datetime_lexographic_comparison()\r\n```"}}