{"action":"created","comment":{"url":"https://api.github.com/repos/apache/metamodel/pulls/comments/38073796","id":38073796,"diff_hunk":"@@ -0,0 +1,41 @@\n+/**\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ *\n+ *   http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+package org.apache.metamodel.elasticsearch;\n+\n+import org.apache.metamodel.util.TimeComparator;\n+\n+import java.text.ParseException;\n+import java.text.SimpleDateFormat;\n+import java.util.Date;\n+\n+/**\n+ * Util class to convert date strings from ElasticSearch to\n+ * proper java Dates.\n+ */\n+final class ElasticSearchDateConverter {\n+\n+    public static Date tryToConvert(String dateAsString) {\n+        try {\n+            SimpleDateFormat dateFormat = new SimpleDateFormat(\"yyyy-MM-dd'T'HH:mm:ss.SSSX\");\n+            return dateFormat.parse(dateAsString);\n+        } catch (ParseException e) {\n+            return TimeComparator.toDate(dateAsString);","path":"elasticsearch/src/main/java/org/apache/metamodel/elasticsearch/ElasticSearchDateConverter.java","position":38,"original_position":38,"commit_id":"69c5f4c825cda3f77f378247bab1c705c26dfabe","original_commit_id":"69c5f4c825cda3f77f378247bab1c705c26dfabe","user":{"login":"albertostratio","id":7139146,"avatar_url":"https://avatars.githubusercontent.com/u/7139146?v=3","gravatar_id":"","url":"https://api.github.com/users/albertostratio","html_url":"https://github.com/albertostratio","followers_url":"https://api.github.com/users/albertostratio/followers","following_url":"https://api.github.com/users/albertostratio/following{/other_user}","gists_url":"https://api.github.com/users/albertostratio/gists{/gist_id}","starred_url":"https://api.github.com/users/albertostratio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/albertostratio/subscriptions","organizations_url":"https://api.github.com/users/albertostratio/orgs","repos_url":"https://api.github.com/users/albertostratio/repos","events_url":"https://api.github.com/users/albertostratio/events{/privacy}","received_events_url":"https://api.github.com/users/albertostratio/received_events","type":"User","site_admin":false},"body":"@kaspersorensen if the TimeComparator method can't parse the date format and returns null we are just setting the value as String, see the code from ElasticSearchUtils below:\r\n\r\n```\r\nDate valueToDate = ElasticSearchDateConverter.tryToConvert((String) value);\r\n                    if (valueToDate == null) {\r\n                        values[i] = value;\r\n                    } else {\r\n                        values[i] = valueToDate;\r\n                    }\r\n```\r\nI don't like a method that returns null though. I'd love to have the concept of Optional in Java7 so this method would return a Optional[Date] but for the time being I think this is a solution that might work.\r\n\r\n@LosD Unfortunately I don't think that there is such utility method in ES.","created_at":"2015-08-27T08:43:32Z","updated_at":"2015-08-27T08:43:32Z","html_url":"https://github.com/apache/metamodel/pull/43#discussion_r38073796","pull_request_url":"https://api.github.com/repos/apache/metamodel/pulls/43","_links":{"self":{"href":"https://api.github.com/repos/apache/metamodel/pulls/comments/38073796"},"html":{"href":"https://github.com/apache/metamodel/pull/43#discussion_r38073796"},"pull_request":{"href":"https://api.github.com/repos/apache/metamodel/pulls/43"}}},"pull_request":{"url":"https://api.github.com/repos/apache/metamodel/pulls/43","id":43146177,"html_url":"https://github.com/apache/metamodel/pull/43","diff_url":"https://github.com/apache/metamodel/pull/43.diff","patch_url":"https://github.com/apache/metamodel/pull/43.patch","issue_url":"https://api.github.com/repos/apache/metamodel/issues/43","number":43,"state":"open","locked":false,"title":"METAMODEL-172: Adding Date parsing to ES module","user":{"login":"ardlema","id":1173286,"avatar_url":"https://avatars.githubusercontent.com/u/1173286?v=3","gravatar_id":"","url":"https://api.github.com/users/ardlema","html_url":"https://github.com/ardlema","followers_url":"https://api.github.com/users/ardlema/followers","following_url":"https://api.github.com/users/ardlema/following{/other_user}","gists_url":"https://api.github.com/users/ardlema/gists{/gist_id}","starred_url":"https://api.github.com/users/ardlema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ardlema/subscriptions","organizations_url":"https://api.github.com/users/ardlema/orgs","repos_url":"https://api.github.com/users/ardlema/repos","events_url":"https://api.github.com/users/ardlema/events{/privacy}","received_events_url":"https://api.github.com/users/ardlema/received_events","type":"User","site_admin":false},"body":"When working with ElasticSearch indexes that contains Date types the API is returning Strings instead of proper Date objects. We found out this problem querying an index with a time-zone format field.\r\n\r\nChanges made in this PR:\r\n\r\n   - Added time-zone format dates support in the TimeComparator class\r\n   - Added a string to date direct conversion through the TimeComparator class in the ElasticSearchUtils class that will convert the string from ES into a proper Date (when the format will be supported by Metamodel)\r\n   - Added a new unit test for the ElasticSearchUtils class","created_at":"2015-08-24T07:20:06Z","updated_at":"2015-08-27T08:43:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3cadb096e66bd40606e5d8e99b612c6477a69de5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/metamodel/pulls/43/commits","review_comments_url":"https://api.github.com/repos/apache/metamodel/pulls/43/comments","review_comment_url":"https://api.github.com/repos/apache/metamodel/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/metamodel/issues/43/comments","statuses_url":"https://api.github.com/repos/apache/metamodel/statuses/69c5f4c825cda3f77f378247bab1c705c26dfabe","head":{"label":"ardlema:METAMODEL-172","ref":"METAMODEL-172","sha":"69c5f4c825cda3f77f378247bab1c705c26dfabe","user":{"login":"ardlema","id":1173286,"avatar_url":"https://avatars.githubusercontent.com/u/1173286?v=3","gravatar_id":"","url":"https://api.github.com/users/ardlema","html_url":"https://github.com/ardlema","followers_url":"https://api.github.com/users/ardlema/followers","following_url":"https://api.github.com/users/ardlema/following{/other_user}","gists_url":"https://api.github.com/users/ardlema/gists{/gist_id}","starred_url":"https://api.github.com/users/ardlema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ardlema/subscriptions","organizations_url":"https://api.github.com/users/ardlema/orgs","repos_url":"https://api.github.com/users/ardlema/repos","events_url":"https://api.github.com/users/ardlema/events{/privacy}","received_events_url":"https://api.github.com/users/ardlema/received_events","type":"User","site_admin":false},"repo":{"id":32088352,"name":"metamodel","full_name":"ardlema/metamodel","owner":{"login":"ardlema","id":1173286,"avatar_url":"https://avatars.githubusercontent.com/u/1173286?v=3","gravatar_id":"","url":"https://api.github.com/users/ardlema","html_url":"https://github.com/ardlema","followers_url":"https://api.github.com/users/ardlema/followers","following_url":"https://api.github.com/users/ardlema/following{/other_user}","gists_url":"https://api.github.com/users/ardlema/gists{/gist_id}","starred_url":"https://api.github.com/users/ardlema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ardlema/subscriptions","organizations_url":"https://api.github.com/users/ardlema/orgs","repos_url":"https://api.github.com/users/ardlema/repos","events_url":"https://api.github.com/users/ardlema/events{/privacy}","received_events_url":"https://api.github.com/users/ardlema/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ardlema/metamodel","description":"Mirror of Apache Metamodel","fork":true,"url":"https://api.github.com/repos/ardlema/metamodel","forks_url":"https://api.github.com/repos/ardlema/metamodel/forks","keys_url":"https://api.github.com/repos/ardlema/metamodel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ardlema/metamodel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ardlema/metamodel/teams","hooks_url":"https://api.github.com/repos/ardlema/metamodel/hooks","issue_events_url":"https://api.github.com/repos/ardlema/metamodel/issues/events{/number}","events_url":"https://api.github.com/repos/ardlema/metamodel/events","assignees_url":"https://api.github.com/repos/ardlema/metamodel/assignees{/user}","branches_url":"https://api.github.com/repos/ardlema/metamodel/branches{/branch}","tags_url":"https://api.github.com/repos/ardlema/metamodel/tags","blobs_url":"https://api.github.com/repos/ardlema/metamodel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ardlema/metamodel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ardlema/metamodel/git/refs{/sha}","trees_url":"https://api.github.com/repos/ardlema/metamodel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ardlema/metamodel/statuses/{sha}","languages_url":"https://api.github.com/repos/ardlema/metamodel/languages","stargazers_url":"https://api.github.com/repos/ardlema/metamodel/stargazers","contributors_url":"https://api.github.com/repos/ardlema/metamodel/contributors","subscribers_url":"https://api.github.com/repos/ardlema/metamodel/subscribers","subscription_url":"https://api.github.com/repos/ardlema/metamodel/subscription","commits_url":"https://api.github.com/repos/ardlema/metamodel/commits{/sha}","git_commits_url":"https://api.github.com/repos/ardlema/metamodel/git/commits{/sha}","comments_url":"https://api.github.com/repos/ardlema/metamodel/comments{/number}","issue_comment_url":"https://api.github.com/repos/ardlema/metamodel/issues/comments{/number}","contents_url":"https://api.github.com/repos/ardlema/metamodel/contents/{+path}","compare_url":"https://api.github.com/repos/ardlema/metamodel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ardlema/metamodel/merges","archive_url":"https://api.github.com/repos/ardlema/metamodel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ardlema/metamodel/downloads","issues_url":"https://api.github.com/repos/ardlema/metamodel/issues{/number}","pulls_url":"https://api.github.com/repos/ardlema/metamodel/pulls{/number}","milestones_url":"https://api.github.com/repos/ardlema/metamodel/milestones{/number}","notifications_url":"https://api.github.com/repos/ardlema/metamodel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ardlema/metamodel/labels{/name}","releases_url":"https://api.github.com/repos/ardlema/metamodel/releases{/id}","created_at":"2015-03-12T16:36:57Z","updated_at":"2015-05-04T07:22:17Z","pushed_at":"2015-08-26T06:13:25Z","git_url":"git://github.com/ardlema/metamodel.git","ssh_url":"git@github.com:ardlema/metamodel.git","clone_url":"https://github.com/ardlema/metamodel.git","svn_url":"https://github.com/ardlema/metamodel","homepage":null,"size":3713,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"apache:master","ref":"master","sha":"fc2752abd48f35f91e8058df19c379b37197ef53","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":11943595,"name":"metamodel","full_name":"apache/metamodel","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/metamodel","description":"Mirror of Apache Metamodel","fork":false,"url":"https://api.github.com/repos/apache/metamodel","forks_url":"https://api.github.com/repos/apache/metamodel/forks","keys_url":"https://api.github.com/repos/apache/metamodel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/metamodel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/metamodel/teams","hooks_url":"https://api.github.com/repos/apache/metamodel/hooks","issue_events_url":"https://api.github.com/repos/apache/metamodel/issues/events{/number}","events_url":"https://api.github.com/repos/apache/metamodel/events","assignees_url":"https://api.github.com/repos/apache/metamodel/assignees{/user}","branches_url":"https://api.github.com/repos/apache/metamodel/branches{/branch}","tags_url":"https://api.github.com/repos/apache/metamodel/tags","blobs_url":"https://api.github.com/repos/apache/metamodel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/metamodel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/metamodel/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/metamodel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/metamodel/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/metamodel/languages","stargazers_url":"https://api.github.com/repos/apache/metamodel/stargazers","contributors_url":"https://api.github.com/repos/apache/metamodel/contributors","subscribers_url":"https://api.github.com/repos/apache/metamodel/subscribers","subscription_url":"https://api.github.com/repos/apache/metamodel/subscription","commits_url":"https://api.github.com/repos/apache/metamodel/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/metamodel/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/metamodel/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/metamodel/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/metamodel/contents/{+path}","compare_url":"https://api.github.com/repos/apache/metamodel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/metamodel/merges","archive_url":"https://api.github.com/repos/apache/metamodel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/metamodel/downloads","issues_url":"https://api.github.com/repos/apache/metamodel/issues{/number}","pulls_url":"https://api.github.com/repos/apache/metamodel/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/metamodel/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/metamodel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/metamodel/labels{/name}","releases_url":"https://api.github.com/repos/apache/metamodel/releases{/id}","created_at":"2013-08-07T07:00:14Z","updated_at":"2015-08-25T21:27:01Z","pushed_at":"2015-08-26T06:13:26Z","git_url":"git://github.com/apache/metamodel.git","ssh_url":"git@github.com:apache/metamodel.git","clone_url":"https://github.com/apache/metamodel.git","svn_url":"https://github.com/apache/metamodel","homepage":null,"size":5046,"stargazers_count":32,"watchers_count":32,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":28,"mirror_url":"git://git.apache.org/incubator-metamodel.git","open_issues_count":4,"forks":28,"open_issues":4,"watchers":32,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/metamodel/pulls/43"},"html":{"href":"https://github.com/apache/metamodel/pull/43"},"issue":{"href":"https://api.github.com/repos/apache/metamodel/issues/43"},"comments":{"href":"https://api.github.com/repos/apache/metamodel/issues/43/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/metamodel/pulls/43/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/metamodel/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/metamodel/pulls/43/commits"},"statuses":{"href":"https://api.github.com/repos/apache/metamodel/statuses/69c5f4c825cda3f77f378247bab1c705c26dfabe"}}}}