{"action":"created","comment":{"url":"https://api.github.com/repos/mapsme/omim/pulls/comments/58171293","id":58171293,"diff_hunk":"@@ -164,6 +169,115 @@ editor::ui::TOpeningDays const kWholeWeek = {\n   osmoh::Weekday::Saturday,\n   osmoh::Weekday::Sunday\n };\n+\n+editor::ui::TOpeningDays GetCommonDays(editor::ui::TOpeningDays const & a,\n+                                       editor::ui::TOpeningDays const & b)\n+{\n+  editor::ui::TOpeningDays result;\n+  set_intersection(begin(a), end(a), begin(b), end(b), inserter(result, begin(result)));\n+  return result;\n+}\n+\n+osmoh::HourMinutes::TMinutes::rep GetDuration(osmoh::Time const & time)\n+{\n+  return time.GetHourMinutes().GetDurationCount();\n+}\n+\n+bool Includes(osmoh::Timespan const & a, osmoh::Timespan const & b)\n+{\n+  return GetDuration(a.GetStart()) <= GetDuration(b.GetStart()) &&\n+         GetDuration(b.GetEnd()) <= GetDuration(a.GetEnd());\n+}\n+\n+bool ExcludeRulePart(osmoh::RuleSequence const & rulePart, editor::ui::TimeTableSet & tts)\n+{\n+  auto const ttsInitialSize = tts.Size();\n+  for (size_t i = 0; i < ttsInitialSize; ++i)\n+  {\n+    auto tt = tts.Get(i);\n+    auto const ttOpeningDays = tt.GetOpeningDays();\n+    auto const commonDays = GetCommonDays(ttOpeningDays,\n+                                          MakeOpeningDays(rulePart.GetWeekdays()));\n+\n+    auto const removeCommonDays = [&commonDays](editor::ui::TTimeTableProxy & tt)\n+    {\n+      for (auto const day : commonDays)\n+        ASSERT(tt.RemoveWorkingDay(day), (\"Can't remove working day\"));\n+      ASSERT(tt.Commit(), (\"Can't commit changes\"));\n+    };\n+\n+    auto const twentyFourHoursGuard = [](editor::ui::TimeTable & tt)\n+    {\n+      using osmoh::operator \"\"_h;\n+      if (tt.IsTwentyFourHours())\n+      {\n+        tt.SetTwentyFourHours(false);\n+        tt.SetOpeningTime({0_h, 24_h});\n+      }\n+    };\n+\n+    auto const & excludeTime = rulePart.GetTimes();\n+    // The whole rule matches to the tt.\n+    if (commonDays.size() == ttOpeningDays.size())\n+    {\n+      // rulePart applies to commonDays in a whole.\n+      if (excludeTime.empty())\n+        return tts.Remove(i);\n+\n+      twentyFourHoursGuard(tt);\n+\n+      for (auto const & time : excludeTime)\n+      {\n+        // Whatever it is, it's already closed at a time out of opening time.\n+        if (!Includes(tt.GetOpeningTime(), time))\n+          continue;\n+\n+        // The whole opening time interval should be switched off\n+        if (!tt.AddExcludeTime(time))\n+          return tts.Remove(i);\n+      }\n+      ASSERT(tt.Commit(), (\"Can't update time table\"));\n+      return true;\n+    }\n+    // A rule is applyed to a subset of a time table. We should\n+    // substruct common parts from tt and add a new time table if neded.","path":"editor/ui2oh.cpp","position":98,"original_position":98,"commit_id":"4a4de47aae7310c4ae4d1aca101b3efc68e74915","original_commit_id":"4a4de47aae7310c4ae4d1aca101b3efc68e74915","user":{"login":"mgsergio","id":6658987,"avatar_url":"https://avatars.githubusercontent.com/u/6658987?v=3","gravatar_id":"","url":"https://api.github.com/users/mgsergio","html_url":"https://github.com/mgsergio","followers_url":"https://api.github.com/users/mgsergio/followers","following_url":"https://api.github.com/users/mgsergio/following{/other_user}","gists_url":"https://api.github.com/users/mgsergio/gists{/gist_id}","starred_url":"https://api.github.com/users/mgsergio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgsergio/subscriptions","organizations_url":"https://api.github.com/users/mgsergio/orgs","repos_url":"https://api.github.com/users/mgsergio/repos","events_url":"https://api.github.com/users/mgsergio/events{/privacy}","received_events_url":"https://api.github.com/users/mgsergio/received_events","type":"User","site_admin":false},"body":"Done.","created_at":"2016-04-01T07:36:18Z","updated_at":"2016-04-01T07:36:18Z","html_url":"https://github.com/mapsme/omim/pull/2655#discussion_r58171293","pull_request_url":"https://api.github.com/repos/mapsme/omim/pulls/2655","_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments/58171293"},"html":{"href":"https://github.com/mapsme/omim/pull/2655#discussion_r58171293"},"pull_request":{"href":"https://api.github.com/repos/mapsme/omim/pulls/2655"}}},"pull_request":{"url":"https://api.github.com/repos/mapsme/omim/pulls/2655","id":64773154,"html_url":"https://github.com/mapsme/omim/pull/2655","diff_url":"https://github.com/mapsme/omim/pull/2655.diff","patch_url":"https://github.com/mapsme/omim/pull/2655.patch","issue_url":"https://api.github.com/repos/mapsme/omim/issues/2655","number":2655,"state":"open","locked":false,"title":"Simple mode can handle oh rules with off modifier.","user":{"login":"mgsergio","id":6658987,"avatar_url":"https://avatars.githubusercontent.com/u/6658987?v=3","gravatar_id":"","url":"https://api.github.com/users/mgsergio","html_url":"https://github.com/mgsergio","followers_url":"https://api.github.com/users/mgsergio/followers","following_url":"https://api.github.com/users/mgsergio/following{/other_user}","gists_url":"https://api.github.com/users/mgsergio/gists{/gist_id}","starred_url":"https://api.github.com/users/mgsergio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgsergio/subscriptions","organizations_url":"https://api.github.com/users/mgsergio/orgs","repos_url":"https://api.github.com/users/mgsergio/repos","events_url":"https://api.github.com/users/mgsergio/events{/privacy}","received_events_url":"https://api.github.com/users/mgsergio/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-31T11:16:26Z","updated_at":"2016-04-01T07:36:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"267e4fbc4cd56d7352d813ad6657132ec2561905","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mapsme/omim/pulls/2655/commits","review_comments_url":"https://api.github.com/repos/mapsme/omim/pulls/2655/comments","review_comment_url":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mapsme/omim/issues/2655/comments","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/4a4de47aae7310c4ae4d1aca101b3efc68e74915","head":{"label":"mgsergio:support-off-modifier","ref":"support-off-modifier","sha":"4a4de47aae7310c4ae4d1aca101b3efc68e74915","user":{"login":"mgsergio","id":6658987,"avatar_url":"https://avatars.githubusercontent.com/u/6658987?v=3","gravatar_id":"","url":"https://api.github.com/users/mgsergio","html_url":"https://github.com/mgsergio","followers_url":"https://api.github.com/users/mgsergio/followers","following_url":"https://api.github.com/users/mgsergio/following{/other_user}","gists_url":"https://api.github.com/users/mgsergio/gists{/gist_id}","starred_url":"https://api.github.com/users/mgsergio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgsergio/subscriptions","organizations_url":"https://api.github.com/users/mgsergio/orgs","repos_url":"https://api.github.com/users/mgsergio/repos","events_url":"https://api.github.com/users/mgsergio/events{/privacy}","received_events_url":"https://api.github.com/users/mgsergio/received_events","type":"User","site_admin":false},"repo":{"id":43430406,"name":"omim","full_name":"mgsergio/omim","owner":{"login":"mgsergio","id":6658987,"avatar_url":"https://avatars.githubusercontent.com/u/6658987?v=3","gravatar_id":"","url":"https://api.github.com/users/mgsergio","html_url":"https://github.com/mgsergio","followers_url":"https://api.github.com/users/mgsergio/followers","following_url":"https://api.github.com/users/mgsergio/following{/other_user}","gists_url":"https://api.github.com/users/mgsergio/gists{/gist_id}","starred_url":"https://api.github.com/users/mgsergio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgsergio/subscriptions","organizations_url":"https://api.github.com/users/mgsergio/orgs","repos_url":"https://api.github.com/users/mgsergio/repos","events_url":"https://api.github.com/users/mgsergio/events{/privacy}","received_events_url":"https://api.github.com/users/mgsergio/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mgsergio/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":true,"url":"https://api.github.com/repos/mgsergio/omim","forks_url":"https://api.github.com/repos/mgsergio/omim/forks","keys_url":"https://api.github.com/repos/mgsergio/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mgsergio/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mgsergio/omim/teams","hooks_url":"https://api.github.com/repos/mgsergio/omim/hooks","issue_events_url":"https://api.github.com/repos/mgsergio/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mgsergio/omim/events","assignees_url":"https://api.github.com/repos/mgsergio/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mgsergio/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mgsergio/omim/tags","blobs_url":"https://api.github.com/repos/mgsergio/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mgsergio/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mgsergio/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mgsergio/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mgsergio/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mgsergio/omim/languages","stargazers_url":"https://api.github.com/repos/mgsergio/omim/stargazers","contributors_url":"https://api.github.com/repos/mgsergio/omim/contributors","subscribers_url":"https://api.github.com/repos/mgsergio/omim/subscribers","subscription_url":"https://api.github.com/repos/mgsergio/omim/subscription","commits_url":"https://api.github.com/repos/mgsergio/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mgsergio/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mgsergio/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mgsergio/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mgsergio/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mgsergio/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mgsergio/omim/merges","archive_url":"https://api.github.com/repos/mgsergio/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mgsergio/omim/downloads","issues_url":"https://api.github.com/repos/mgsergio/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mgsergio/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mgsergio/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mgsergio/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mgsergio/omim/labels{/name}","releases_url":"https://api.github.com/repos/mgsergio/omim/releases{/id}","deployments_url":"https://api.github.com/repos/mgsergio/omim/deployments","created_at":"2015-09-30T11:59:31Z","updated_at":"2016-03-17T15:31:31Z","pushed_at":"2016-03-31T11:15:57Z","git_url":"git://github.com/mgsergio/omim.git","ssh_url":"git@github.com:mgsergio/omim.git","clone_url":"https://github.com/mgsergio/omim.git","svn_url":"https://github.com/mgsergio/omim","homepage":null,"size":2260540,"stargazers_count":0,"watchers_count":0,"language":"C++","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":"mapsme:master","ref":"master","sha":"e72a0efc641e3b6a480c8169d2375e35a0e33e91","user":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"repo":{"id":42798033,"name":"omim","full_name":"mapsme/omim","owner":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapsme/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":false,"url":"https://api.github.com/repos/mapsme/omim","forks_url":"https://api.github.com/repos/mapsme/omim/forks","keys_url":"https://api.github.com/repos/mapsme/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapsme/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapsme/omim/teams","hooks_url":"https://api.github.com/repos/mapsme/omim/hooks","issue_events_url":"https://api.github.com/repos/mapsme/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mapsme/omim/events","assignees_url":"https://api.github.com/repos/mapsme/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mapsme/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mapsme/omim/tags","blobs_url":"https://api.github.com/repos/mapsme/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapsme/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapsme/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapsme/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mapsme/omim/languages","stargazers_url":"https://api.github.com/repos/mapsme/omim/stargazers","contributors_url":"https://api.github.com/repos/mapsme/omim/contributors","subscribers_url":"https://api.github.com/repos/mapsme/omim/subscribers","subscription_url":"https://api.github.com/repos/mapsme/omim/subscription","commits_url":"https://api.github.com/repos/mapsme/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapsme/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapsme/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapsme/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapsme/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mapsme/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapsme/omim/merges","archive_url":"https://api.github.com/repos/mapsme/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapsme/omim/downloads","issues_url":"https://api.github.com/repos/mapsme/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mapsme/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mapsme/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mapsme/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapsme/omim/labels{/name}","releases_url":"https://api.github.com/repos/mapsme/omim/releases{/id}","deployments_url":"https://api.github.com/repos/mapsme/omim/deployments","created_at":"2015-09-20T02:57:13Z","updated_at":"2016-03-31T13:19:05Z","pushed_at":"2016-04-01T07:15:10Z","git_url":"git://github.com/mapsme/omim.git","ssh_url":"git@github.com:mapsme/omim.git","clone_url":"https://github.com/mapsme/omim.git","svn_url":"https://github.com/mapsme/omim","homepage":null,"size":2333870,"stargazers_count":1682,"watchers_count":1682,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":247,"mirror_url":null,"open_issues_count":119,"forks":247,"open_issues":119,"watchers":1682,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/2655"},"html":{"href":"https://github.com/mapsme/omim/pull/2655"},"issue":{"href":"https://api.github.com/repos/mapsme/omim/issues/2655"},"comments":{"href":"https://api.github.com/repos/mapsme/omim/issues/2655/comments"},"review_comments":{"href":"https://api.github.com/repos/mapsme/omim/pulls/2655/comments"},"review_comment":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mapsme/omim/pulls/2655/commits"},"statuses":{"href":"https://api.github.com/repos/mapsme/omim/statuses/4a4de47aae7310c4ae4d1aca101b3efc68e74915"}}}}