{"action":"created","comment":{"url":"https://api.github.com/repos/superdesk/superdesk/pulls/comments/42195621","id":42195621,"diff_hunk":"@@ -301,20 +329,52 @@ def __check_if_rule_name_is_unique(self, routing_scheme):\n             if len(rules_with_same_name) > 1:\n                 raise SuperdeskApiError.badRequestError(\"Rule Names must be unique within a scheme\")\n \n-    def __get_scheduled_routing_rules(self, rules, current_datetime=datetime.now()):\n+    def _get_scheduled_routing_rules(self, rules, current_dt_utc):\n         \"\"\"\n         Iterates rules list and returns the list of rules that are scheduled.\n+\n+        :param list rules: routing rules to check\n+        :param datetime current_dt_utc: the value to take as the current\n+            time in UTC\n+\n+        :return: the rules scheduled to be appplied at `current_dt_utc`\n+        :rtype: list\n         \"\"\"\n+        # make it a timezone-aware object\n+        current_dt_utc = current_dt_utc.replace(tzinfo=pytz.utc)\n+        delta_minute = timedelta(minutes=1)\n+\n         scheduled_rules = []\n         for rule in rules:\n             is_scheduled = True\n             schedule = rule.get('schedule', {})\n             if schedule:\n-                from_time = set_time(current_datetime, schedule.get('hour_of_day_from', '0000'))\n-                to_time = set_time(current_datetime, schedule.get('hour_of_day_to', '2359'), second=59)\n-                if not (Weekdays.is_scheduled_day(current_datetime, schedule.get('day_of_week', []))\n-                        and (from_time < current_datetime < to_time)):\n-                    is_scheduled = False\n+                # adjust current time to the schedule's timezone\n+                tz_name = schedule.get('time_zone')\n+                schedule_tz = pytz.timezone(tz_name) if tz_name else pytz.utc","path":"server/apps/rules/routing_rules.py","position":118,"original_position":118,"commit_id":"eb39959b98ace811be79647b0c44d1d81e2a59b0","original_commit_id":"eb39959b98ace811be79647b0c44d1d81e2a59b0","user":{"login":"plamut","id":1235663,"avatar_url":"https://avatars.githubusercontent.com/u/1235663?v=3","gravatar_id":"","url":"https://api.github.com/users/plamut","html_url":"https://github.com/plamut","followers_url":"https://api.github.com/users/plamut/followers","following_url":"https://api.github.com/users/plamut/following{/other_user}","gists_url":"https://api.github.com/users/plamut/gists{/gist_id}","starred_url":"https://api.github.com/users/plamut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plamut/subscriptions","organizations_url":"https://api.github.com/users/plamut/orgs","repos_url":"https://api.github.com/users/plamut/repos","events_url":"https://api.github.com/users/plamut/events{/privacy}","received_events_url":"https://api.github.com/users/plamut/received_events","type":"User","site_admin":false},"body":"Well no, because it won't be executed in that case. :)","created_at":"2015-10-15T23:47:36Z","updated_at":"2015-10-15T23:47:36Z","html_url":"https://github.com/superdesk/superdesk/pull/1252#discussion_r42195621","pull_request_url":"https://api.github.com/repos/superdesk/superdesk/pulls/1252","_links":{"self":{"href":"https://api.github.com/repos/superdesk/superdesk/pulls/comments/42195621"},"html":{"href":"https://github.com/superdesk/superdesk/pull/1252#discussion_r42195621"},"pull_request":{"href":"https://api.github.com/repos/superdesk/superdesk/pulls/1252"}}},"pull_request":{"url":"https://api.github.com/repos/superdesk/superdesk/pulls/1252","id":47774953,"html_url":"https://github.com/superdesk/superdesk/pull/1252","diff_url":"https://github.com/superdesk/superdesk/pull/1252.diff","patch_url":"https://github.com/superdesk/superdesk/pull/1252.patch","issue_url":"https://api.github.com/repos/superdesk/superdesk/issues/1252","number":1252,"state":"open","locked":false,"title":"Fix handling different time zones in ingest routing schedule","user":{"login":"plamut","id":1235663,"avatar_url":"https://avatars.githubusercontent.com/u/1235663?v=3","gravatar_id":"","url":"https://api.github.com/users/plamut","html_url":"https://github.com/plamut","followers_url":"https://api.github.com/users/plamut/followers","following_url":"https://api.github.com/users/plamut/following{/other_user}","gists_url":"https://api.github.com/users/plamut/gists{/gist_id}","starred_url":"https://api.github.com/users/plamut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plamut/subscriptions","organizations_url":"https://api.github.com/users/plamut/orgs","repos_url":"https://api.github.com/users/plamut/repos","events_url":"https://api.github.com/users/plamut/events{/privacy}","received_events_url":"https://api.github.com/users/plamut/received_events","type":"User","site_admin":false},"body":"Resolves [SD-3350](https://dev.sourcefabric.org/browse/SD-3350).\r\n\r\nThis PR fixes various issues with ingest routing schedule, e.g.:\r\n* `sdTimepickerAlt` can be optionally configured to *not* convert selected times to UTC in the client browser, avoiding problems when time zone settings on the client's machine differ from the server time zone.\r\n* It is now possible to select the time zone of the times of day in a routing schedule rule. This avoids the trouble of defining a time interval in a local time zone that would span across two different days in UTC due to the time shift (the latter was pretty much impossible to define until now).\r\nThe default behavior of the directive is still the same, preserving the backward compatibility.\r\nIf no time zone is defined in the routing schedule, UTC is assumed, meaning that all the existing schedules that do not have this information will still work normally.\r\n* It is now possible to omit the ending time of day in a routing rule, which is interpreted as \"until the end of the day\". Until now it was not possible to do that, the latest possible time to choose for an end time was 23:55, meaning that there was a 5-minute gap until midnight, which was impossible  to cover.\r\n* Optimization: time zone data is now fetched from the server only once - when the `tzdata` factory is instantiated. Before the change this data was fetched every time when a service/directive that uses `tzdata` was created.\r\n\r\n**To be aware of:**\r\nCurrently the list of all time zones on the client and the server differ. While the server recognizes almost 500 common time zones (using `pytz`, based on the Olson database), the client only know about 50 of them. The reason is that `tzdata` service fetches the `world-clock/timezones-all.json` file which seems to be incomplete.","created_at":"2015-10-15T11:37:06Z","updated_at":"2015-10-15T23:47:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0a0a1a945458ebb3c85eb6b192d312cbf6365f4f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/superdesk/superdesk/pulls/1252/commits","review_comments_url":"https://api.github.com/repos/superdesk/superdesk/pulls/1252/comments","review_comment_url":"https://api.github.com/repos/superdesk/superdesk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/superdesk/superdesk/issues/1252/comments","statuses_url":"https://api.github.com/repos/superdesk/superdesk/statuses/eb39959b98ace811be79647b0c44d1d81e2a59b0","head":{"label":"plamut:sd-3350","ref":"sd-3350","sha":"eb39959b98ace811be79647b0c44d1d81e2a59b0","user":{"login":"plamut","id":1235663,"avatar_url":"https://avatars.githubusercontent.com/u/1235663?v=3","gravatar_id":"","url":"https://api.github.com/users/plamut","html_url":"https://github.com/plamut","followers_url":"https://api.github.com/users/plamut/followers","following_url":"https://api.github.com/users/plamut/following{/other_user}","gists_url":"https://api.github.com/users/plamut/gists{/gist_id}","starred_url":"https://api.github.com/users/plamut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plamut/subscriptions","organizations_url":"https://api.github.com/users/plamut/orgs","repos_url":"https://api.github.com/users/plamut/repos","events_url":"https://api.github.com/users/plamut/events{/privacy}","received_events_url":"https://api.github.com/users/plamut/received_events","type":"User","site_admin":false},"repo":{"id":30860876,"name":"superdesk","full_name":"plamut/superdesk","owner":{"login":"plamut","id":1235663,"avatar_url":"https://avatars.githubusercontent.com/u/1235663?v=3","gravatar_id":"","url":"https://api.github.com/users/plamut","html_url":"https://github.com/plamut","followers_url":"https://api.github.com/users/plamut/followers","following_url":"https://api.github.com/users/plamut/following{/other_user}","gists_url":"https://api.github.com/users/plamut/gists{/gist_id}","starred_url":"https://api.github.com/users/plamut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plamut/subscriptions","organizations_url":"https://api.github.com/users/plamut/orgs","repos_url":"https://api.github.com/users/plamut/repos","events_url":"https://api.github.com/users/plamut/events{/privacy}","received_events_url":"https://api.github.com/users/plamut/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/plamut/superdesk","description":"","fork":true,"url":"https://api.github.com/repos/plamut/superdesk","forks_url":"https://api.github.com/repos/plamut/superdesk/forks","keys_url":"https://api.github.com/repos/plamut/superdesk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/plamut/superdesk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/plamut/superdesk/teams","hooks_url":"https://api.github.com/repos/plamut/superdesk/hooks","issue_events_url":"https://api.github.com/repos/plamut/superdesk/issues/events{/number}","events_url":"https://api.github.com/repos/plamut/superdesk/events","assignees_url":"https://api.github.com/repos/plamut/superdesk/assignees{/user}","branches_url":"https://api.github.com/repos/plamut/superdesk/branches{/branch}","tags_url":"https://api.github.com/repos/plamut/superdesk/tags","blobs_url":"https://api.github.com/repos/plamut/superdesk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/plamut/superdesk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/plamut/superdesk/git/refs{/sha}","trees_url":"https://api.github.com/repos/plamut/superdesk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/plamut/superdesk/statuses/{sha}","languages_url":"https://api.github.com/repos/plamut/superdesk/languages","stargazers_url":"https://api.github.com/repos/plamut/superdesk/stargazers","contributors_url":"https://api.github.com/repos/plamut/superdesk/contributors","subscribers_url":"https://api.github.com/repos/plamut/superdesk/subscribers","subscription_url":"https://api.github.com/repos/plamut/superdesk/subscription","commits_url":"https://api.github.com/repos/plamut/superdesk/commits{/sha}","git_commits_url":"https://api.github.com/repos/plamut/superdesk/git/commits{/sha}","comments_url":"https://api.github.com/repos/plamut/superdesk/comments{/number}","issue_comment_url":"https://api.github.com/repos/plamut/superdesk/issues/comments{/number}","contents_url":"https://api.github.com/repos/plamut/superdesk/contents/{+path}","compare_url":"https://api.github.com/repos/plamut/superdesk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/plamut/superdesk/merges","archive_url":"https://api.github.com/repos/plamut/superdesk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/plamut/superdesk/downloads","issues_url":"https://api.github.com/repos/plamut/superdesk/issues{/number}","pulls_url":"https://api.github.com/repos/plamut/superdesk/pulls{/number}","milestones_url":"https://api.github.com/repos/plamut/superdesk/milestones{/number}","notifications_url":"https://api.github.com/repos/plamut/superdesk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/plamut/superdesk/labels{/name}","releases_url":"https://api.github.com/repos/plamut/superdesk/releases{/id}","created_at":"2015-02-16T09:09:52Z","updated_at":"2015-09-01T12:43:31Z","pushed_at":"2015-10-15T22:41:17Z","git_url":"git://github.com/plamut/superdesk.git","ssh_url":"git@github.com:plamut/superdesk.git","clone_url":"https://github.com/plamut/superdesk.git","svn_url":"https://github.com/plamut/superdesk","homepage":null,"size":58446,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"superdesk:master","ref":"master","sha":"ab7d676381b8a67ad821749bedcfc4fb3bdf5ed9","user":{"login":"superdesk","id":5527298,"avatar_url":"https://avatars.githubusercontent.com/u/5527298?v=3","gravatar_id":"","url":"https://api.github.com/users/superdesk","html_url":"https://github.com/superdesk","followers_url":"https://api.github.com/users/superdesk/followers","following_url":"https://api.github.com/users/superdesk/following{/other_user}","gists_url":"https://api.github.com/users/superdesk/gists{/gist_id}","starred_url":"https://api.github.com/users/superdesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superdesk/subscriptions","organizations_url":"https://api.github.com/users/superdesk/orgs","repos_url":"https://api.github.com/users/superdesk/repos","events_url":"https://api.github.com/users/superdesk/events{/privacy}","received_events_url":"https://api.github.com/users/superdesk/received_events","type":"Organization","site_admin":false},"repo":{"id":23570030,"name":"superdesk","full_name":"superdesk/superdesk","owner":{"login":"superdesk","id":5527298,"avatar_url":"https://avatars.githubusercontent.com/u/5527298?v=3","gravatar_id":"","url":"https://api.github.com/users/superdesk","html_url":"https://github.com/superdesk","followers_url":"https://api.github.com/users/superdesk/followers","following_url":"https://api.github.com/users/superdesk/following{/other_user}","gists_url":"https://api.github.com/users/superdesk/gists{/gist_id}","starred_url":"https://api.github.com/users/superdesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superdesk/subscriptions","organizations_url":"https://api.github.com/users/superdesk/orgs","repos_url":"https://api.github.com/users/superdesk/repos","events_url":"https://api.github.com/users/superdesk/events{/privacy}","received_events_url":"https://api.github.com/users/superdesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/superdesk/superdesk","description":"Superdesk is an end-to-end news creation, production, curation, distribution, and publishing platform.","fork":false,"url":"https://api.github.com/repos/superdesk/superdesk","forks_url":"https://api.github.com/repos/superdesk/superdesk/forks","keys_url":"https://api.github.com/repos/superdesk/superdesk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/superdesk/superdesk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/superdesk/superdesk/teams","hooks_url":"https://api.github.com/repos/superdesk/superdesk/hooks","issue_events_url":"https://api.github.com/repos/superdesk/superdesk/issues/events{/number}","events_url":"https://api.github.com/repos/superdesk/superdesk/events","assignees_url":"https://api.github.com/repos/superdesk/superdesk/assignees{/user}","branches_url":"https://api.github.com/repos/superdesk/superdesk/branches{/branch}","tags_url":"https://api.github.com/repos/superdesk/superdesk/tags","blobs_url":"https://api.github.com/repos/superdesk/superdesk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/superdesk/superdesk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/superdesk/superdesk/git/refs{/sha}","trees_url":"https://api.github.com/repos/superdesk/superdesk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/superdesk/superdesk/statuses/{sha}","languages_url":"https://api.github.com/repos/superdesk/superdesk/languages","stargazers_url":"https://api.github.com/repos/superdesk/superdesk/stargazers","contributors_url":"https://api.github.com/repos/superdesk/superdesk/contributors","subscribers_url":"https://api.github.com/repos/superdesk/superdesk/subscribers","subscription_url":"https://api.github.com/repos/superdesk/superdesk/subscription","commits_url":"https://api.github.com/repos/superdesk/superdesk/commits{/sha}","git_commits_url":"https://api.github.com/repos/superdesk/superdesk/git/commits{/sha}","comments_url":"https://api.github.com/repos/superdesk/superdesk/comments{/number}","issue_comment_url":"https://api.github.com/repos/superdesk/superdesk/issues/comments{/number}","contents_url":"https://api.github.com/repos/superdesk/superdesk/contents/{+path}","compare_url":"https://api.github.com/repos/superdesk/superdesk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/superdesk/superdesk/merges","archive_url":"https://api.github.com/repos/superdesk/superdesk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/superdesk/superdesk/downloads","issues_url":"https://api.github.com/repos/superdesk/superdesk/issues{/number}","pulls_url":"https://api.github.com/repos/superdesk/superdesk/pulls{/number}","milestones_url":"https://api.github.com/repos/superdesk/superdesk/milestones{/number}","notifications_url":"https://api.github.com/repos/superdesk/superdesk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/superdesk/superdesk/labels{/name}","releases_url":"https://api.github.com/repos/superdesk/superdesk/releases{/id}","created_at":"2014-09-02T07:56:17Z","updated_at":"2015-10-07T12:28:54Z","pushed_at":"2015-10-15T23:06:18Z","git_url":"git://github.com/superdesk/superdesk.git","ssh_url":"git@github.com:superdesk/superdesk.git","clone_url":"https://github.com/superdesk/superdesk.git","svn_url":"https://github.com/superdesk/superdesk","homepage":"http://www.superdesk.org/","size":70197,"stargazers_count":38,"watchers_count":38,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":36,"mirror_url":null,"open_issues_count":9,"forks":36,"open_issues":9,"watchers":38,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/superdesk/superdesk/pulls/1252"},"html":{"href":"https://github.com/superdesk/superdesk/pull/1252"},"issue":{"href":"https://api.github.com/repos/superdesk/superdesk/issues/1252"},"comments":{"href":"https://api.github.com/repos/superdesk/superdesk/issues/1252/comments"},"review_comments":{"href":"https://api.github.com/repos/superdesk/superdesk/pulls/1252/comments"},"review_comment":{"href":"https://api.github.com/repos/superdesk/superdesk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/superdesk/superdesk/pulls/1252/commits"},"statuses":{"href":"https://api.github.com/repos/superdesk/superdesk/statuses/eb39959b98ace811be79647b0c44d1d81e2a59b0"}}}}