{"action":"created","issue":{"url":"https://api.github.com/repos/segmentio/analytics-python/issues/74","repository_url":"https://api.github.com/repos/segmentio/analytics-python","labels_url":"https://api.github.com/repos/segmentio/analytics-python/issues/74/labels{/name}","comments_url":"https://api.github.com/repos/segmentio/analytics-python/issues/74/comments","events_url":"https://api.github.com/repos/segmentio/analytics-python/issues/74/events","html_url":"https://github.com/segmentio/analytics-python/issues/74","id":144425914,"number":74,"title":"\"Python's standard datetime object is broken\"","user":{"login":"dwieeb","id":236501,"avatar_url":"https://avatars.githubusercontent.com/u/236501?v=3","gravatar_id":"","url":"https://api.github.com/users/dwieeb","html_url":"https://github.com/dwieeb","followers_url":"https://api.github.com/users/dwieeb/followers","following_url":"https://api.github.com/users/dwieeb/following{/other_user}","gists_url":"https://api.github.com/users/dwieeb/gists{/gist_id}","starred_url":"https://api.github.com/users/dwieeb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dwieeb/subscriptions","organizations_url":"https://api.github.com/users/dwieeb/orgs","repos_url":"https://api.github.com/users/dwieeb/repos","events_url":"https://api.github.com/users/dwieeb/events{/privacy}","received_events_url":"https://api.github.com/users/dwieeb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-30T00:27:28Z","updated_at":"2016-03-31T09:17:17Z","closed_at":null,"body":"This is a documentation issue, but I figure it may be best to talk directly to developers. \r\n\r\nhttps://segment.com/docs/libraries/python/#timezones-in-python\r\n\r\nPython datetime objects are not \"broken\". The Python datetime module, in fact, is one of the best standard library implementations of all the programming languages I've worked with. The Python core devs knew timezones were [difficult to work with](https://www.youtube.com/watch?v=-5wpm-gesOY). Libraries that deal with timezones are gnarly messes of spaghetti code that are constantly updated. Most people use `pytz`, which is able to be versioned independently of your installed Python, instead of being locked into timezones that existed at the date your version of Python was released.\r\n\r\nThe core team abstracted the timezone madness into the `tzinfo` classes, which you can implement to determine the offsets for a particular date.\r\n\r\n`tzinfo` classes are not required to use datetime objects in Python, which is good. It allows you to work with dates in an abstract way. These are called \"naive\" datetime objects. datetime objects which do have `tzinfo` objects are called \"aware\" datetime objects. This is documented in the second paragraph of the [datetime module docs](https://docs.python.org/3.5/library/datetime.html).\r\n\r\nThe following sentence on your docs shows a misunderstanding of how Python datetime objects work.\r\n\r\n![image](https://cloud.githubusercontent.com/assets/236501/14128074/03e1c6ca-f5e3-11e5-976d-8131ad766abd.png)\r\n\r\nThey don't \"lose timezone information\", whatever that means. You're not giving timezone information to the `now()` function in the first place. Try this: `datetime.datetime.now(tz=pytz.utc)`.\r\n\r\nThe following image on your docs depict the behavior of naive datetime objects in a way as if you're expecting them to be timezone aware. `now()` doesn't create timezone aware datetime objects unless you pass the `tz` keyword.\r\n\r\n![image](https://cloud.githubusercontent.com/assets/236501/14127660/3e12d20c-f5df-11e5-9483-21302fbe6ee4.png)\r\n\r\nAll you need to do, as a library, is require timezone aware datetime objects. Then you can `isoformat` them and all will be fine.\r\n\r\nPlease fix the documentation to not hate on Python datetime objects because of a misunderstanding."},"comment":{"url":"https://api.github.com/repos/segmentio/analytics-python/issues/comments/203839384","html_url":"https://github.com/segmentio/analytics-python/issues/74#issuecomment-203839384","issue_url":"https://api.github.com/repos/segmentio/analytics-python/issues/74","id":203839384,"user":{"login":"sametmax","id":1673950,"avatar_url":"https://avatars.githubusercontent.com/u/1673950?v=3","gravatar_id":"","url":"https://api.github.com/users/sametmax","html_url":"https://github.com/sametmax","followers_url":"https://api.github.com/users/sametmax/followers","following_url":"https://api.github.com/users/sametmax/following{/other_user}","gists_url":"https://api.github.com/users/sametmax/gists{/gist_id}","starred_url":"https://api.github.com/users/sametmax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sametmax/subscriptions","organizations_url":"https://api.github.com/users/sametmax/orgs","repos_url":"https://api.github.com/users/sametmax/repos","events_url":"https://api.github.com/users/sametmax/events{/privacy}","received_events_url":"https://api.github.com/users/sametmax/received_events","type":"User","site_admin":false},"created_at":"2016-03-31T09:17:17Z","updated_at":"2016-03-31T09:17:17Z","body":"Or really, just use arrow, which abstract all that stuff, and let you go from and to datetime when you need it."}}