{"action":"created","comment":{"url":"https://api.github.com/repos/CanalTP/navitia/pulls/comments/37575363","id":37575363,"diff_hunk":"@@ -275,9 +280,85 @@ std::vector<idx_t> manage_odt_level(const std::vector<type::idx_t>& final_indexe\n     return final_indexes;\n }\n \n+bool keep_vj(const nt::VehicleJourney* vj,\n+             const bt::time_period& period) {\n+    if (vj->stop_time_list.empty()) {\n+        return false; //no stop time, so it cannot be valid\n+    }\n+    const auto first_departure_dt = vj->stop_time_list.front().departure_time;\n+\n+    for (boost::gregorian::day_iterator it(period.begin().date()); it <= period.last().date(); ++it) {\n+        if (! vj->validity_pattern->check(*it)) { continue; }\n+        bt::ptime vj_dt = bt::ptime(*it, bt::seconds(first_departure_dt));\n+        if (period.contains(vj_dt)) { return true; }\n+    }\n+\n+    return false;\n+}\n+\n+std::vector<idx_t> filter_vj_on_period(const std::vector<type::idx_t>& indexes,\n+             boost::optional<bt::ptime> since,\n+             boost::optional<bt::ptime> until,\n+             const type::Data & data) {\n+\n+    // we create the right period using since, until and the production period\n+    if (since && until && until < since) {\n+        throw ptref_error(\"invalid filtering period\");\n+    }\n+    auto start = bt::ptime(data.meta->production_date.begin());\n+    auto end = bt::ptime(data.meta->production_date.last(), bt::seconds(24*3600 - 1));\n+\n+    if (since) {\n+        if (data.meta->production_date.is_before(since->date())) {\n+            throw ptref_error(\"invalid filtering period, not in production period\");\n+        }\n+        if (since->date() >= data.meta->production_date.begin()) {\n+            start = *since;\n+        }\n+    }\n+    if (until) {\n+        if (data.meta->production_date.is_after(until->date())) {\n+            throw ptref_error(\"invalid filtering period, not in production period\");\n+        }\n+        if (until->date() <= data.meta->production_date.last()) {\n+            end = *until;\n+        }\n+    }\n+    bt::time_period period {start, end + bt::seconds(1)}; //the end is not in the period, so we add one second\n+\n+    std::vector<idx_t> res;\n+    for (const idx_t idx: indexes) {\n+        const auto vj = data.pt_data->vehicle_journeys[idx];\n+        if (! keep_vj(vj, period)) { continue; }\n+        res.push_back(idx);\n+    }\n+    return res;\n+}\n+\n+std::vector<idx_t> filter_on_period(const std::vector<type::idx_t>& indexes,\n+                                    const navitia::type::Type_e requested_type,\n+                                    boost::optional<boost::posix_time::ptime> since,\n+                                    boost::optional<boost::posix_time::ptime> until,\n+                                    const type::Data & data) {\n+\n+    switch(requested_type) {\n+        case nt::Type_e::VehicleJourney: {\n+            return filter_vj_on_period(indexes, since, until, data);\n+        }\n+    default:\n+        LOG4CPLUS_INFO(log4cplus::Logger::getInstance(\"log\"),\n+                       \"cannot filter on validity period for this type\");","path":"source/ptreferential/ptreferential.cpp","position":86,"original_position":86,"commit_id":"da5641950ab66063f8e13065403a3e7cb5a27ddf","original_commit_id":"da5641950ab66063f8e13065403a3e7cb5a27ddf","user":{"login":"antoine-de","id":3987698,"avatar_url":"https://avatars.githubusercontent.com/u/3987698?v=3","gravatar_id":"","url":"https://api.github.com/users/antoine-de","html_url":"https://github.com/antoine-de","followers_url":"https://api.github.com/users/antoine-de/followers","following_url":"https://api.github.com/users/antoine-de/following{/other_user}","gists_url":"https://api.github.com/users/antoine-de/gists{/gist_id}","starred_url":"https://api.github.com/users/antoine-de/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antoine-de/subscriptions","organizations_url":"https://api.github.com/users/antoine-de/orgs","repos_url":"https://api.github.com/users/antoine-de/repos","events_url":"https://api.github.com/users/antoine-de/events{/privacy}","received_events_url":"https://api.github.com/users/antoine-de/received_events","type":"User","site_admin":false},"body":"yep you're right","created_at":"2015-08-20T20:08:52Z","updated_at":"2015-08-20T20:08:52Z","html_url":"https://github.com/CanalTP/navitia/pull/1133#discussion_r37575363","pull_request_url":"https://api.github.com/repos/CanalTP/navitia/pulls/1133","_links":{"self":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/comments/37575363"},"html":{"href":"https://github.com/CanalTP/navitia/pull/1133#discussion_r37575363"},"pull_request":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/1133"}}},"pull_request":{"url":"https://api.github.com/repos/CanalTP/navitia/pulls/1133","id":41875752,"html_url":"https://github.com/CanalTP/navitia/pull/1133","diff_url":"https://github.com/CanalTP/navitia/pull/1133.diff","patch_url":"https://github.com/CanalTP/navitia/pull/1133.patch","issue_url":"https://api.github.com/repos/CanalTP/navitia/issues/1133","number":1133,"state":"open","locked":false,"title":"Ptref: filter on the validity period","user":{"login":"antoine-de","id":3987698,"avatar_url":"https://avatars.githubusercontent.com/u/3987698?v=3","gravatar_id":"","url":"https://api.github.com/users/antoine-de","html_url":"https://github.com/antoine-de","followers_url":"https://api.github.com/users/antoine-de/followers","following_url":"https://api.github.com/users/antoine-de/following{/other_user}","gists_url":"https://api.github.com/users/antoine-de/gists{/gist_id}","starred_url":"https://api.github.com/users/antoine-de/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antoine-de/subscriptions","organizations_url":"https://api.github.com/users/antoine-de/orgs","repos_url":"https://api.github.com/users/antoine-de/repos","events_url":"https://api.github.com/users/antoine-de/events{/privacy}","received_events_url":"https://api.github.com/users/antoine-de/received_events","type":"User","site_admin":false},"body":"add new ptref filter on a period:\r\n\r\n`since`, and `until` that take both a datetime\r\n\r\neg:\r\n`api.navitia.io/v1/coverage/fr_idf/vehicle_journeys?since=20150912T120000&until=20150913T110000`\r\n\r\nThe param names can be discussed :wink: \r\n\r\nboth params are optional.\r\n\r\nfor the moment it can only be used with vehicle_journeys","created_at":"2015-08-07T09:48:50Z","updated_at":"2015-08-20T20:08:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bee33637cc3100d7647ea461751b69fbc91638ab","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CanalTP/navitia/pulls/1133/commits","review_comments_url":"https://api.github.com/repos/CanalTP/navitia/pulls/1133/comments","review_comment_url":"https://api.github.com/repos/CanalTP/navitia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CanalTP/navitia/issues/1133/comments","statuses_url":"https://api.github.com/repos/CanalTP/navitia/statuses/da5641950ab66063f8e13065403a3e7cb5a27ddf","head":{"label":"antoine-de:vj_filters","ref":"vj_filters","sha":"da5641950ab66063f8e13065403a3e7cb5a27ddf","user":{"login":"antoine-de","id":3987698,"avatar_url":"https://avatars.githubusercontent.com/u/3987698?v=3","gravatar_id":"","url":"https://api.github.com/users/antoine-de","html_url":"https://github.com/antoine-de","followers_url":"https://api.github.com/users/antoine-de/followers","following_url":"https://api.github.com/users/antoine-de/following{/other_user}","gists_url":"https://api.github.com/users/antoine-de/gists{/gist_id}","starred_url":"https://api.github.com/users/antoine-de/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antoine-de/subscriptions","organizations_url":"https://api.github.com/users/antoine-de/orgs","repos_url":"https://api.github.com/users/antoine-de/repos","events_url":"https://api.github.com/users/antoine-de/events{/privacy}","received_events_url":"https://api.github.com/users/antoine-de/received_events","type":"User","site_admin":false},"repo":{"id":19144843,"name":"navitia","full_name":"antoine-de/navitia","owner":{"login":"antoine-de","id":3987698,"avatar_url":"https://avatars.githubusercontent.com/u/3987698?v=3","gravatar_id":"","url":"https://api.github.com/users/antoine-de","html_url":"https://github.com/antoine-de","followers_url":"https://api.github.com/users/antoine-de/followers","following_url":"https://api.github.com/users/antoine-de/following{/other_user}","gists_url":"https://api.github.com/users/antoine-de/gists{/gist_id}","starred_url":"https://api.github.com/users/antoine-de/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antoine-de/subscriptions","organizations_url":"https://api.github.com/users/antoine-de/orgs","repos_url":"https://api.github.com/users/antoine-de/repos","events_url":"https://api.github.com/users/antoine-de/events{/privacy}","received_events_url":"https://api.github.com/users/antoine-de/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/antoine-de/navitia","description":"","fork":true,"url":"https://api.github.com/repos/antoine-de/navitia","forks_url":"https://api.github.com/repos/antoine-de/navitia/forks","keys_url":"https://api.github.com/repos/antoine-de/navitia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/antoine-de/navitia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/antoine-de/navitia/teams","hooks_url":"https://api.github.com/repos/antoine-de/navitia/hooks","issue_events_url":"https://api.github.com/repos/antoine-de/navitia/issues/events{/number}","events_url":"https://api.github.com/repos/antoine-de/navitia/events","assignees_url":"https://api.github.com/repos/antoine-de/navitia/assignees{/user}","branches_url":"https://api.github.com/repos/antoine-de/navitia/branches{/branch}","tags_url":"https://api.github.com/repos/antoine-de/navitia/tags","blobs_url":"https://api.github.com/repos/antoine-de/navitia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/antoine-de/navitia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/antoine-de/navitia/git/refs{/sha}","trees_url":"https://api.github.com/repos/antoine-de/navitia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/antoine-de/navitia/statuses/{sha}","languages_url":"https://api.github.com/repos/antoine-de/navitia/languages","stargazers_url":"https://api.github.com/repos/antoine-de/navitia/stargazers","contributors_url":"https://api.github.com/repos/antoine-de/navitia/contributors","subscribers_url":"https://api.github.com/repos/antoine-de/navitia/subscribers","subscription_url":"https://api.github.com/repos/antoine-de/navitia/subscription","commits_url":"https://api.github.com/repos/antoine-de/navitia/commits{/sha}","git_commits_url":"https://api.github.com/repos/antoine-de/navitia/git/commits{/sha}","comments_url":"https://api.github.com/repos/antoine-de/navitia/comments{/number}","issue_comment_url":"https://api.github.com/repos/antoine-de/navitia/issues/comments{/number}","contents_url":"https://api.github.com/repos/antoine-de/navitia/contents/{+path}","compare_url":"https://api.github.com/repos/antoine-de/navitia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/antoine-de/navitia/merges","archive_url":"https://api.github.com/repos/antoine-de/navitia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/antoine-de/navitia/downloads","issues_url":"https://api.github.com/repos/antoine-de/navitia/issues{/number}","pulls_url":"https://api.github.com/repos/antoine-de/navitia/pulls{/number}","milestones_url":"https://api.github.com/repos/antoine-de/navitia/milestones{/number}","notifications_url":"https://api.github.com/repos/antoine-de/navitia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/antoine-de/navitia/labels{/name}","releases_url":"https://api.github.com/repos/antoine-de/navitia/releases{/id}","created_at":"2014-04-25T12:12:04Z","updated_at":"2015-04-30T13:08:16Z","pushed_at":"2015-08-07T09:53:25Z","git_url":"git://github.com/antoine-de/navitia.git","ssh_url":"git@github.com:antoine-de/navitia.git","clone_url":"https://github.com/antoine-de/navitia.git","svn_url":"https://github.com/antoine-de/navitia","homepage":"http://www.navitia.io/","size":27605,"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":"dev"}},"base":{"label":"CanalTP:dev","ref":"dev","sha":"5830a9d20182bab9a320595baf4bef33a9abb721","user":{"login":"CanalTP","id":2743985,"avatar_url":"https://avatars.githubusercontent.com/u/2743985?v=3","gravatar_id":"","url":"https://api.github.com/users/CanalTP","html_url":"https://github.com/CanalTP","followers_url":"https://api.github.com/users/CanalTP/followers","following_url":"https://api.github.com/users/CanalTP/following{/other_user}","gists_url":"https://api.github.com/users/CanalTP/gists{/gist_id}","starred_url":"https://api.github.com/users/CanalTP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CanalTP/subscriptions","organizations_url":"https://api.github.com/users/CanalTP/orgs","repos_url":"https://api.github.com/users/CanalTP/repos","events_url":"https://api.github.com/users/CanalTP/events{/privacy}","received_events_url":"https://api.github.com/users/CanalTP/received_events","type":"Organization","site_admin":false},"repo":{"id":10797333,"name":"navitia","full_name":"CanalTP/navitia","owner":{"login":"CanalTP","id":2743985,"avatar_url":"https://avatars.githubusercontent.com/u/2743985?v=3","gravatar_id":"","url":"https://api.github.com/users/CanalTP","html_url":"https://github.com/CanalTP","followers_url":"https://api.github.com/users/CanalTP/followers","following_url":"https://api.github.com/users/CanalTP/following{/other_user}","gists_url":"https://api.github.com/users/CanalTP/gists{/gist_id}","starred_url":"https://api.github.com/users/CanalTP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CanalTP/subscriptions","organizations_url":"https://api.github.com/users/CanalTP/orgs","repos_url":"https://api.github.com/users/CanalTP/repos","events_url":"https://api.github.com/users/CanalTP/events{/privacy}","received_events_url":"https://api.github.com/users/CanalTP/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CanalTP/navitia","description":"The REST API to build cool stuff with public transport","fork":false,"url":"https://api.github.com/repos/CanalTP/navitia","forks_url":"https://api.github.com/repos/CanalTP/navitia/forks","keys_url":"https://api.github.com/repos/CanalTP/navitia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CanalTP/navitia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CanalTP/navitia/teams","hooks_url":"https://api.github.com/repos/CanalTP/navitia/hooks","issue_events_url":"https://api.github.com/repos/CanalTP/navitia/issues/events{/number}","events_url":"https://api.github.com/repos/CanalTP/navitia/events","assignees_url":"https://api.github.com/repos/CanalTP/navitia/assignees{/user}","branches_url":"https://api.github.com/repos/CanalTP/navitia/branches{/branch}","tags_url":"https://api.github.com/repos/CanalTP/navitia/tags","blobs_url":"https://api.github.com/repos/CanalTP/navitia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CanalTP/navitia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CanalTP/navitia/git/refs{/sha}","trees_url":"https://api.github.com/repos/CanalTP/navitia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CanalTP/navitia/statuses/{sha}","languages_url":"https://api.github.com/repos/CanalTP/navitia/languages","stargazers_url":"https://api.github.com/repos/CanalTP/navitia/stargazers","contributors_url":"https://api.github.com/repos/CanalTP/navitia/contributors","subscribers_url":"https://api.github.com/repos/CanalTP/navitia/subscribers","subscription_url":"https://api.github.com/repos/CanalTP/navitia/subscription","commits_url":"https://api.github.com/repos/CanalTP/navitia/commits{/sha}","git_commits_url":"https://api.github.com/repos/CanalTP/navitia/git/commits{/sha}","comments_url":"https://api.github.com/repos/CanalTP/navitia/comments{/number}","issue_comment_url":"https://api.github.com/repos/CanalTP/navitia/issues/comments{/number}","contents_url":"https://api.github.com/repos/CanalTP/navitia/contents/{+path}","compare_url":"https://api.github.com/repos/CanalTP/navitia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CanalTP/navitia/merges","archive_url":"https://api.github.com/repos/CanalTP/navitia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CanalTP/navitia/downloads","issues_url":"https://api.github.com/repos/CanalTP/navitia/issues{/number}","pulls_url":"https://api.github.com/repos/CanalTP/navitia/pulls{/number}","milestones_url":"https://api.github.com/repos/CanalTP/navitia/milestones{/number}","notifications_url":"https://api.github.com/repos/CanalTP/navitia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CanalTP/navitia/labels{/name}","releases_url":"https://api.github.com/repos/CanalTP/navitia/releases{/id}","created_at":"2013-06-19T15:34:30Z","updated_at":"2015-07-29T14:09:54Z","pushed_at":"2015-08-20T16:47:03Z","git_url":"git://github.com/CanalTP/navitia.git","ssh_url":"git@github.com:CanalTP/navitia.git","clone_url":"https://github.com/CanalTP/navitia.git","svn_url":"https://github.com/CanalTP/navitia","homepage":"http://www.navitia.io","size":34788,"stargazers_count":116,"watchers_count":116,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":37,"mirror_url":null,"open_issues_count":22,"forks":37,"open_issues":22,"watchers":116,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/1133"},"html":{"href":"https://github.com/CanalTP/navitia/pull/1133"},"issue":{"href":"https://api.github.com/repos/CanalTP/navitia/issues/1133"},"comments":{"href":"https://api.github.com/repos/CanalTP/navitia/issues/1133/comments"},"review_comments":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/1133/comments"},"review_comment":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/1133/commits"},"statuses":{"href":"https://api.github.com/repos/CanalTP/navitia/statuses/da5641950ab66063f8e13065403a3e7cb5a27ddf"}}}}