{"action":"opened","issue":{"url":"https://api.github.com/repos/sdispater/pendulum/issues/252","repository_url":"https://api.github.com/repos/sdispater/pendulum","labels_url":"https://api.github.com/repos/sdispater/pendulum/issues/252/labels{/name}","comments_url":"https://api.github.com/repos/sdispater/pendulum/issues/252/comments","events_url":"https://api.github.com/repos/sdispater/pendulum/issues/252/events","html_url":"https://github.com/sdispater/pendulum/issues/252","id":340115590,"node_id":"MDU6SXNzdWUzNDAxMTU1OTA=","number":252,"title":"A suggestion for the Period class - constraints on the Period class creation","user":{"login":"Phuket2","id":11646675,"node_id":"MDQ6VXNlcjExNjQ2Njc1","avatar_url":"https://avatars1.githubusercontent.com/u/11646675?v=4","gravatar_id":"","url":"https://api.github.com/users/Phuket2","html_url":"https://github.com/Phuket2","followers_url":"https://api.github.com/users/Phuket2/followers","following_url":"https://api.github.com/users/Phuket2/following{/other_user}","gists_url":"https://api.github.com/users/Phuket2/gists{/gist_id}","starred_url":"https://api.github.com/users/Phuket2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Phuket2/subscriptions","organizations_url":"https://api.github.com/users/Phuket2/orgs","repos_url":"https://api.github.com/users/Phuket2/repos","events_url":"https://api.github.com/users/Phuket2/events{/privacy}","received_events_url":"https://api.github.com/users/Phuket2/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-11T07:00:10Z","updated_at":"2018-07-11T07:00:10Z","closed_at":null,"author_association":"NONE","body":"A suggestion for the Period class.\r\nThe abilty to somehow set some constraints on the Period class creation\r\neg.\r\n- min_start, max_start\r\n- min_end, max_end\r\n- min_duration , max_duration\r\n\r\nAs api's go I really dont know what the best approach here is. But it does seem like normally you want to control Periods to some sort of sane values that makes sense to the contex of your application (I know I want to). Also to me it seems like a nice place to have that logic.\r\n\r\nMaybe nothing should be done and the best way is to subclass Period as I tried below. Or if worked into the api maybe could be kwargs or another class constructor etc...\r\n\r\nAnyway, just a suggestion.\r\n\r\n\r\n```python\r\nimport pendulum\r\n\r\nclass PeriodSanityError(ValueError):\r\n    pass\r\n\r\nclass MyPeriod(pendulum.Period):\r\n    _min_start = None\r\n    _max_start = None\r\n\r\n    def __init__(self, start, end):\r\n        super().__init__(start=start, end=end)\r\n\r\n        # could do this before the calling super\r\n        self._sanity_check()\r\n\r\n    def _sanity_check(self):\r\n        if self._min_start:\r\n            if self.start < self._min_start:\r\n                raise PeriodSanityError('min start error...Blah Blah....')\r\n        if self._max_start:\r\n            if self.start > self._max_start:\r\n                raise PeriodSanityError('max start error...Blah Blah....')\r\n\r\n\r\nif __name__ == '__main__':\r\n    # use class vars to set the constraints\r\n    MyPeriod._min_start = pendulum.today()\r\n    MyPeriod._max_start = pendulum.today().add(years=1)\r\n\r\n    today = pendulum.today()\r\n    yesterday = today.subtract(days=1)\r\n    end = today.add(days=5)\r\n\r\n    p = MyPeriod(today, end)\r\n\r\n    # will raise a PeriodSanityError\r\n    p2 = MyPeriod(yesterday, end)           # start to early\r\n    p3 = MyPeriod(today.add(years=2), end)  # start to late\r\n```"}}
{"actor":{"display_login":"Phuket2"}}