{"action":"created","issue":{"url":"https://api.github.com/repos/sahana/eden/issues/1447","repository_url":"https://api.github.com/repos/sahana/eden","labels_url":"https://api.github.com/repos/sahana/eden/issues/1447/labels{/name}","comments_url":"https://api.github.com/repos/sahana/eden/issues/1447/comments","events_url":"https://api.github.com/repos/sahana/eden/issues/1447/events","html_url":"https://github.com/sahana/eden/issues/1447","id":293316348,"number":1447,"title":"Ability to specify relative date(time)s in URL queries","user":{"login":"nursix","id":1257183,"avatar_url":"https://avatars1.githubusercontent.com/u/1257183?v=4","gravatar_id":"","url":"https://api.github.com/users/nursix","html_url":"https://github.com/nursix","followers_url":"https://api.github.com/users/nursix/followers","following_url":"https://api.github.com/users/nursix/following{/other_user}","gists_url":"https://api.github.com/users/nursix/gists{/gist_id}","starred_url":"https://api.github.com/users/nursix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nursix/subscriptions","organizations_url":"https://api.github.com/users/nursix/orgs","repos_url":"https://api.github.com/users/nursix/repos","events_url":"https://api.github.com/users/nursix/events{/privacy}","received_events_url":"https://api.github.com/users/nursix/received_events","type":"User","site_admin":false},"labels":[{"id":337204437,"url":"https://api.github.com/repos/sahana/eden/labels/Core","name":"Core","color":"207de5","default":false},{"id":337201889,"url":"https://api.github.com/repos/sahana/eden/labels/Enhancement","name":"Enhancement","color":"fbca04","default":false},{"id":336396218,"url":"https://api.github.com/repos/sahana/eden/labels/Minor","name":"Minor","color":"e11d21","default":false},{"id":337206587,"url":"https://api.github.com/repos/sahana/eden/labels/S3","name":"S3","color":"207de5","default":false}],"state":"open","locked":false,"assignee":{"login":"nursix","id":1257183,"avatar_url":"https://avatars1.githubusercontent.com/u/1257183?v=4","gravatar_id":"","url":"https://api.github.com/users/nursix","html_url":"https://github.com/nursix","followers_url":"https://api.github.com/users/nursix/followers","following_url":"https://api.github.com/users/nursix/following{/other_user}","gists_url":"https://api.github.com/users/nursix/gists{/gist_id}","starred_url":"https://api.github.com/users/nursix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nursix/subscriptions","organizations_url":"https://api.github.com/users/nursix/orgs","repos_url":"https://api.github.com/users/nursix/repos","events_url":"https://api.github.com/users/nursix/events{/privacy}","received_events_url":"https://api.github.com/users/nursix/received_events","type":"User","site_admin":false},"assignees":[{"login":"nursix","id":1257183,"avatar_url":"https://avatars1.githubusercontent.com/u/1257183?v=4","gravatar_id":"","url":"https://api.github.com/users/nursix","html_url":"https://github.com/nursix","followers_url":"https://api.github.com/users/nursix/followers","following_url":"https://api.github.com/users/nursix/following{/other_user}","gists_url":"https://api.github.com/users/nursix/gists{/gist_id}","starred_url":"https://api.github.com/users/nursix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nursix/subscriptions","organizations_url":"https://api.github.com/users/nursix/orgs","repos_url":"https://api.github.com/users/nursix/repos","events_url":"https://api.github.com/users/nursix/events{/privacy}","received_events_url":"https://api.github.com/users/nursix/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2018-01-31T21:23:20Z","updated_at":"2018-03-01T20:52:19Z","closed_at":null,"author_association":"MEMBER","body":"Current implementation requires ISO format absolute date(time) expressions in URL queries when filtering by date(time) fields.\r\n\r\nThat makes it impossible to store date/time filter expressions (e.g. in subscriptions, map layers) where they shall be relative to NOW (e.g. \"14 days ago\") - as those static expressions would not progress.\r\n\r\nTo overcome this, it should be made possible to specify relative date(time)s instead, like \"-2Y\" (2 years ago), or \"-14D\" (14 days ago), or \"+24h\" (24 hours from now).\r\n\r\nA solution would implement an expression syntax (parser) for relative date(time)s, and apply it in the respective S3TypeConverter function when converting strings into date(time)s."},"comment":{"url":"https://api.github.com/repos/sahana/eden/issues/comments/369726869","html_url":"https://github.com/sahana/eden/issues/1447#issuecomment-369726869","issue_url":"https://api.github.com/repos/sahana/eden/issues/1447","id":369726869,"user":{"login":"nursix","id":1257183,"avatar_url":"https://avatars1.githubusercontent.com/u/1257183?v=4","gravatar_id":"","url":"https://api.github.com/users/nursix","html_url":"https://github.com/nursix","followers_url":"https://api.github.com/users/nursix/followers","following_url":"https://api.github.com/users/nursix/following{/other_user}","gists_url":"https://api.github.com/users/nursix/gists{/gist_id}","starred_url":"https://api.github.com/users/nursix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nursix/subscriptions","organizations_url":"https://api.github.com/users/nursix/orgs","repos_url":"https://api.github.com/users/nursix/repos","events_url":"https://api.github.com/users/nursix/events{/privacy}","received_events_url":"https://api.github.com/users/nursix/received_events","type":"User","site_admin":false},"created_at":"2018-03-01T20:52:19Z","updated_at":"2018-03-01T20:52:19Z","author_association":"MEMBER","body":"For a parser, I was imagining something like this:\r\n\r\n```\r\nimport re\r\nimport datetime\r\nfrom dateutil import relativedelta\r\n\r\ndef relative_datetime(dtexpr):\r\n\r\n    dtexpr = dtexpr.strip()\r\n    if dtexpr[0] not in (\"+\", \"-\"):\r\n        return None\r\n\r\n    syntax = re.compile(r\"([+-]{0,1})([0-9]*)([YMDhms])\")\r\n\r\n    seconds = {\"D\": 86400,\r\n               \"h\": 3600,\r\n               \"m\": 60,\r\n               \"s\": 1,\r\n               }\r\n\r\n    now = datetime.datetime.utcnow()\r\n\r\n    then = now\r\n    f = 1\r\n    for m in syntax.finditer(dtexpr):\r\n\r\n        try:\r\n            value = int(m.group(2))\r\n        except ValueError:\r\n            continue\r\n\r\n        sign = m.group(1)\r\n        if sign == \"-\":\r\n            f = -1\r\n        elif sign == \"+\":\r\n            f = 1\r\n\r\n        unit = m.group(3)\r\n        if unit == \"Y\":\r\n            then += relativedelta.relativedelta(years = f * value)\r\n        elif unit == \"M\":\r\n            then += relativedelta.relativedelta(months = f * value)\r\n        else:\r\n            u = seconds.get(unit)\r\n            if u:\r\n                then += relativedelta.relativedelta(seconds = f * u * value)\r\n\r\n    return then\r\n\r\nprint relative_datetime(\"-2D\")      # two days ago\r\nprint relative_datetime(\"-1Y6M\")    # 1 year and 6 months ago\r\nprint relative_datetime(\"+14D\")     # 14 days from now\r\nprint relative_datetime(\"+36h\")     # 36 hours from now\r\n```\r\n\r\nMaybe you can improve this, both for speed and flexibility?\r\n\r\nThe relative date/time string must be distinguishable from absolute date/time strings - which is why I would require it to start with + or -. After that, it can be any combination of relative interval expressions.\r\n\r\nNote that these relative strings will always be generated, never entered by hand - so they don't need to look nice. But they must be URL-safe, should be as compact as possible and must not clash with any recognizable date/time format (in particular not with the ISO format).\r\n\r\nI can add this parser in the right places, so if you want to make suggestions how to improve it...?\r\n\r\nSpeed matters, yes - but scalability less so (the relative strings won't be endlessly complex). Destructive testing also welcome (how can this parse be crashed?)."}}
{"actor":{"display_login":"nursix"}}