{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/781","repository_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py","labels_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/781/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/781/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/781/events","html_url":"https://github.com/elastic/elasticsearch-dsl-py/issues/781","id":277004258,"number":781,"title":"[bug]Date fields parse to a local date without timezone information","user":{"login":"okke-formsma","id":486179,"avatar_url":"https://avatars3.githubusercontent.com/u/486179?v=4","gravatar_id":"","url":"https://api.github.com/users/okke-formsma","html_url":"https://github.com/okke-formsma","followers_url":"https://api.github.com/users/okke-formsma/followers","following_url":"https://api.github.com/users/okke-formsma/following{/other_user}","gists_url":"https://api.github.com/users/okke-formsma/gists{/gist_id}","starred_url":"https://api.github.com/users/okke-formsma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/okke-formsma/subscriptions","organizations_url":"https://api.github.com/users/okke-formsma/orgs","repos_url":"https://api.github.com/users/okke-formsma/repos","events_url":"https://api.github.com/users/okke-formsma/events{/privacy}","received_events_url":"https://api.github.com/users/okke-formsma/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-11-27T12:38:43Z","updated_at":"2017-11-27T15:05:56Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nDates parsed by elasticsearch-dsl do not have the right unix timestamp, because they are UTC times that are interpreted as local times.\r\n\r\nElasticsearch stores dates without timezone information, and these should be interpreted as UTC (see https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html). \r\n\r\nUnfortunately, `dateutil.parser.parse` which is used by the `Date._deserialize` function, interprets the date received from elasticsearch as a local date!\r\n\r\nExample:\r\n```python\r\nIn [26]: dateutil.parser.parse('2016-01-22 15:43:08.957').timestamp()\r\nOut[26]: 1453473788.957 \r\n```\r\n\r\nThis timestamp (1453473788) does not correspond to 2016-01-22 15:43:08.957 UTC, but to local time (UTC+1). You can verify the correct UTC date on http://www.convert-unix-time.com/?t=1453473788 or by using utcfromtimestamp():\r\n\r\n```python\r\nIn [27]: datetime.datetime.utcfromtimestamp(dateutil.parser.parse('2016-01-22 15:43:08.957').timestamp())\r\nOut[27]: datetime.datetime(2016, 1, 22, 14, 43, 8, 957000)\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/comments/347209780","html_url":"https://github.com/elastic/elasticsearch-dsl-py/issues/781#issuecomment-347209780","issue_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/781","id":347209780,"user":{"login":"HonzaKral","id":32132,"avatar_url":"https://avatars0.githubusercontent.com/u/32132?v=4","gravatar_id":"","url":"https://api.github.com/users/HonzaKral","html_url":"https://github.com/HonzaKral","followers_url":"https://api.github.com/users/HonzaKral/followers","following_url":"https://api.github.com/users/HonzaKral/following{/other_user}","gists_url":"https://api.github.com/users/HonzaKral/gists{/gist_id}","starred_url":"https://api.github.com/users/HonzaKral/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HonzaKral/subscriptions","organizations_url":"https://api.github.com/users/HonzaKral/orgs","repos_url":"https://api.github.com/users/HonzaKral/repos","events_url":"https://api.github.com/users/HonzaKral/events{/privacy}","received_events_url":"https://api.github.com/users/HonzaKral/received_events","type":"User","site_admin":false},"created_at":"2017-11-27T15:05:55Z","updated_at":"2017-11-27T15:05:55Z","author_association":"MEMBER","body":"Hi Okke,\r\n\r\nthank you for raising this issue! I am honestly not 100% sure how to proceed here. On one hand you are absolutely correct - elasticsearch will interpret the datetimes as being in UTC.\r\n\r\nOn the other hand this would be a major breaking change forcing all users to always use timezone-aware datetimes throughout their code.\r\n\r\nGiven that we already respect the timezone, if provided, I am leaning towards leaving current behavior to play nice with others - people using timezone-aware timestamps will have the tz info preserved in elasticsearch and properly deserialized and people not concerned with timezones will not have to change their entire code base.\r\n\r\nAlternatively we could also make this a parameter on the `Date` field whether to do the conversion.\r\n\r\nWhat do you think?\r\nThanks!"}}
{"actor":{"display_login":"HonzaKral"}}