{"action":"reopened","issue":{"url":"https://api.github.com/repos/camsci/meteor-pi/issues/41","labels_url":"https://api.github.com/repos/camsci/meteor-pi/issues/41/labels{/name}","comments_url":"https://api.github.com/repos/camsci/meteor-pi/issues/41/comments","events_url":"https://api.github.com/repos/camsci/meteor-pi/issues/41/events","html_url":"https://github.com/camsci/meteor-pi/issues/41","id":89446197,"number":41,"title":"Python datetime module and Unix times","user":{"login":"dcf21","id":10739029,"avatar_url":"https://avatars.githubusercontent.com/u/10739029?v=3","gravatar_id":"","url":"https://api.github.com/users/dcf21","html_url":"https://github.com/dcf21","followers_url":"https://api.github.com/users/dcf21/followers","following_url":"https://api.github.com/users/dcf21/following{/other_user}","gists_url":"https://api.github.com/users/dcf21/gists{/gist_id}","starred_url":"https://api.github.com/users/dcf21/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcf21/subscriptions","organizations_url":"https://api.github.com/users/dcf21/orgs","repos_url":"https://api.github.com/users/dcf21/repos","events_url":"https://api.github.com/users/dcf21/events{/privacy}","received_events_url":"https://api.github.com/users/dcf21/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"tomoinn","id":1400070,"avatar_url":"https://avatars.githubusercontent.com/u/1400070?v=3","gravatar_id":"","url":"https://api.github.com/users/tomoinn","html_url":"https://github.com/tomoinn","followers_url":"https://api.github.com/users/tomoinn/followers","following_url":"https://api.github.com/users/tomoinn/following{/other_user}","gists_url":"https://api.github.com/users/tomoinn/gists{/gist_id}","starred_url":"https://api.github.com/users/tomoinn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomoinn/subscriptions","organizations_url":"https://api.github.com/users/tomoinn/orgs","repos_url":"https://api.github.com/users/tomoinn/repos","events_url":"https://api.github.com/users/tomoinn/events{/privacy}","received_events_url":"https://api.github.com/users/tomoinn/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2015-06-19T02:14:43Z","updated_at":"2015-06-19T08:46:19Z","closed_at":null,"body":"I just made the following grim discovery:\r\n\r\n```\r\n>>> import datetime\r\n>>> import time\r\n>>> dt = datetime.datetime.now()\r\n>>> time.mktime( dt.timetuple() )\r\n1434678196.0\r\n>>> dt2 = datetime.datetime.utcnow()\r\n>>> time.mktime( dt2.timetuple() )\r\n1434674612.0\r\n```\r\n\r\nIn short, python datetime objects don't store any timezone information. If you create a datetime object with a calendar time in local time (which is the default behaviour), and convert it to a Unix time (using Python's exceptionally verbose syntax), you get the wrong answer.\r\n\r\nI'm not sure how much this screws us up. When I insert things into the database, all datetime objects are in UTC (which is the only sane thing for it to do).\r\n\r\nUsers will almost certainly expect to supply datetimes in local time. In summer there'll be an hour offset.\r\n\r\nNow I remember why I always end up using raw unix times, and writing my own utility functions to turn them to/from calendar dates using tzdata..."}}