{"action":"created","issue":{"url":"https://api.github.com/repos/sdispater/pendulum/issues/178","repository_url":"https://api.github.com/repos/sdispater/pendulum","labels_url":"https://api.github.com/repos/sdispater/pendulum/issues/178/labels{/name}","comments_url":"https://api.github.com/repos/sdispater/pendulum/issues/178/comments","events_url":"https://api.github.com/repos/sdispater/pendulum/issues/178/events","html_url":"https://github.com/sdispater/pendulum/issues/178","id":298231010,"number":178,"title":"Period length calculation problem","user":{"login":"dekoza","id":210980,"avatar_url":"https://avatars3.githubusercontent.com/u/210980?v=4","gravatar_id":"","url":"https://api.github.com/users/dekoza","html_url":"https://github.com/dekoza","followers_url":"https://api.github.com/users/dekoza/followers","following_url":"https://api.github.com/users/dekoza/following{/other_user}","gists_url":"https://api.github.com/users/dekoza/gists{/gist_id}","starred_url":"https://api.github.com/users/dekoza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dekoza/subscriptions","organizations_url":"https://api.github.com/users/dekoza/orgs","repos_url":"https://api.github.com/users/dekoza/repos","events_url":"https://api.github.com/users/dekoza/events{/privacy}","received_events_url":"https://api.github.com/users/dekoza/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-02-19T10:46:51Z","updated_at":"2018-02-20T22:20:54Z","closed_at":null,"author_association":"NONE","body":"I discovered something odd when experimenting with period length calculations around DST change time. Please consider this example:\r\n\r\n```python\r\ntz = pendulum.timezone('America/Los_Angeles')\r\nstart_time = pendulum.parse('2018-03-11 09:00:00+00:00')\r\nend_time = pendulum.parse('2018-03-11 10:00:00+00:00')\r\nprint((end_time - start_time).hours)     # 1\r\nprint((end_time.in_tz(tz) - start_time).hours)  # 1\r\nprint((end_time - start_time.in_tz(tz)).hours)  # 1\r\nprint((end_time.in_tz(tz) - start_time.in_tz(tz)).hours)  # 2 ?!\r\n\r\np1 = end_time - start_time\r\nprint(start_time + p1 == end_time)   # True\r\nprint(p1.total_hours())  # 1.0\r\n\r\np2 = end_time.in_tz(tz) - start_time.in_tz(tz)\r\nprint(start_time + p2 == end_time)  # False\r\nprint(p2.total_hours())  # 1.0\r\n\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/sdispater/pendulum/issues/comments/367140964","html_url":"https://github.com/sdispater/pendulum/issues/178#issuecomment-367140964","issue_url":"https://api.github.com/repos/sdispater/pendulum/issues/178","id":367140964,"user":{"login":"sdispater","id":555648,"avatar_url":"https://avatars1.githubusercontent.com/u/555648?v=4","gravatar_id":"","url":"https://api.github.com/users/sdispater","html_url":"https://github.com/sdispater","followers_url":"https://api.github.com/users/sdispater/followers","following_url":"https://api.github.com/users/sdispater/following{/other_user}","gists_url":"https://api.github.com/users/sdispater/gists{/gist_id}","starred_url":"https://api.github.com/users/sdispater/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sdispater/subscriptions","organizations_url":"https://api.github.com/users/sdispater/orgs","repos_url":"https://api.github.com/users/sdispater/repos","events_url":"https://api.github.com/users/sdispater/events{/privacy}","received_events_url":"https://api.github.com/users/sdispater/received_events","type":"User","site_admin":false},"created_at":"2018-02-20T22:20:54Z","updated_at":"2018-02-20T22:20:54Z","author_association":"OWNER","body":"@pganssle \r\n\r\nThe idea is we should always have:\r\n\r\n```python\r\ndt_end = dt + (dt_end - dt)\r\n```\r\n\r\nwhich Pendulum actually does right when adding/subtracting units of variable length (like days):\r\n\r\n```python\r\n>>> import pendulum\r\n>>> dt = pendulum.create(2018, 3, 11, 0, 30, tz='America/Los_Angeles')\r\n>>> dt_end = pendulum.create(2018, 3, 12, 0, 30, tz='America/Los_Angeles')\r\n>>> dt_end == dt + (dt_end - dt)\r\nTrue \r\n```\r\n\r\nbut not for other units:\r\n\r\n```python\r\n>>> dt = pendulum.create(2018, 3, 11, 0, 30, tz='America/Los_Angeles')\r\n>>> dt_end = pendulum.create(2018, 3, 12, 3, 30, tz='America/Los_Angeles')\r\n>>> dt_end == dt + (dt_end - dt)\r\nFalse\r\n```\r\n\r\nThis is more or less what this issue is about.\r\n\r\nAnd the thing is the standard library does not get this right:\r\n\r\n```python\r\n>>> from datetime import datetime, timedelta\r\n>>> from dateutil.tz import gettz\r\n>>> dt = datetime(2018, 3, 11, 0, 30, tzinfo=gettz('America/Los_Angeles'))\r\n>>> dt_end = datetime(2018, 3, 12, 0, 30, tzinfo=gettz('America/Los_Angeles'))\r\n>>> dt_end == dt + (dt_end - dt)\r\nFalse\r\n>>> dt_end - dt\r\ndatetime.timedelta(0, 82800) \r\n# This is actually correct (23 hours) but it's also a full day\r\n# however there is no way to handle that in the standard library\r\n>>> dt_end = datetime(2018, 3, 11, 3, 30, tzinfo=gettz('America/Los_Angeles'))\r\n>>> dt_end == dt + (dt_end - dt)\r\nFalse\r\n>>> dt_end - dt\r\ndatetime.timedelta(0, 7200)  # But only one hour has passed\r\n```"}}
{"actor":{"display_login":"sdispater"}}