GitHub PullRequestReviewCommentEvent at 2014-07-24 05:30:39
Repository: Twig-extensions
Actor: fabpot
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/fabpot/Twig-extensions/pulls/comments/15330521","id":15330521,"diff_hunk":"@@ -0,0 +1,189 @@\n+<?php\n+\n+/**\n+ * This file is part of Twig.\n+ *\n+ * (c) 2014 Fabien Potencier\n+ *\n+ * For the full copyright and license information, please view the LICENSE\n+ * file that was distributed with this source code.\n+ *\n+ * @author Robin van der Vleuten <robinvdvleuten@gmail.com>\n+ * @package Twig\n+ * @subpackage Twig-extensions\n+ */\n+\n+use Symfony\\Component\\Translation\\TranslatorInterface;\n+\n+class Twig_Extensions_Extension_Date extends Twig_Extension\n+{\n+    static $units = array(\n+        'y' => 'year',\n+        'm' => 'month',\n+        'd' => 'day',\n+        'h' => 'hour',\n+        'i' => 'minute',\n+        's' => 'second',\n+    );\n+\n+    /**\n+     * @var TranslatorInterface\n+     */\n+    private $translator;\n+\n+    /**\n+     * Constructor.\n+     *\n+     * @param TranslatorInterface $translator A TranslatorInterface instance.\n+     */\n+    public function __construct(TranslatorInterface $translator = null)\n+    {\n+        $this->translator = $translator;\n+    }\n+\n+    /**\n+     * Returns a list of filters.\n+     *\n+     * @return array\n+     */\n+    public function getFilters()\n+    {\n+        return array(\n+            new Twig_SimpleFilter('time_diff', array($this, 'diff')),\n+        );\n+    }\n+\n+    /**\n+     * Name of this extension\n+     *\n+     * @return string\n+     */\n+    public function getName()\n+    {\n+        return 'date';\n+    }\n+\n+    /**\n+     * Filter for converting dates to a time ago string like Facebook and Twitter has.\n+     *\n+     * @param string|DateTime $date A string or DateTime object to convert.\n+     * @param string|DateTime $now  A string or DateTime object to compare with. If none given, the current time will be used.\n+     *\n+     * @return string The converted time.\n+     */\n+    public function diff($date, $now = null)\n+    {\n+        // Convert the $date variable to a DateTime object if it's a string.\n+        if (is_string($date)) {\n+            $date = new DateTime($date);\n+        }\n+\n+        if (!$date instanceof DateTime) {\n+            throw new InvalidArgumentException('$date must be a valid DateTime instance');\n+        }\n+\n+        // If no $now variable is given, use the current time.\n+        if (!$now) {\n+            $now = new DateTime();\n+        } elseif (is_string($now)) {\n+            // Else if it's a string, convert it to a DateTime object.\n+            $now = new DateTime($now);\n+        }\n+\n+        if (!$now instanceof DateTime) {\n+            throw new InvalidArgumentException('$now must be a valid DateTime instance');\n+        }\n+\n+        // Get the difference between the two DateTime objects.\n+        $diff = method_exists($date, 'diff') ? $date->diff($now) : $this->diffDates($date, $now);\n+\n+        // Check for each interval if it appears in the $diff object.\n+        foreach (self::$units as $attribute => $unit) {\n+            $count = $diff->$attribute;\n+\n+            if (0 !== $count) {\n+                return $this->getPluralizedInterval($count, $diff->invert, $unit);\n+            }\n+        }\n+\n+        return '';\n+    }\n+\n+    /**\n+     * Get the differences between two DateTime objects.\n+     *\n+     * Function is a replacement for DateTime::diff because Twig needs to support PHP 5.2.\n+     */\n+    protected function diffDates(DateTime $datetime1, DateTime $datetime2)","path":"lib/Twig/Extensions/Extension/Date.php","position":117,"original_position":117,"commit_id":"43076d94546fa0dd7b37b33b2735591d9b191bf2","original_commit_id":"43076d94546fa0dd7b37b33b2735591d9b191bf2","user":{"login":"fabpot","id":47313,"avatar_url":"https://avatars.githubusercontent.com/u/47313?","gravatar_id":"f1a2c5905e121d09feba5ad73898ffca","url":"https://api.github.com/users/fabpot","html_url":"https://github.com/fabpot","followers_url":"https://api.github.com/users/fabpot/followers","following_url":"https://api.github.com/users/fabpot/following{/other_user}","gists_url":"https://api.github.com/users/fabpot/gists{/gist_id}","starred_url":"https://api.github.com/users/fabpot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabpot/subscriptions","organizations_url":"https://api.github.com/users/fabpot/orgs","repos_url":"https://api.github.com/users/fabpot/repos","events_url":"https://api.github.com/users/fabpot/events{/privacy}","received_events_url":"https://api.github.com/users/fabpot/received_events","type":"User","site_admin":false},"body":"IMO, this should be removed. Instead, just mark this class as being compatible with PHP 5.3+.","created_at":"2014-07-24T05:30:39Z","updated_at":"2014-07-24T05:30:39Z","html_url":"https://github.com/fabpot/Twig-extensions/pull/109#discussion_r15330521","pull_request_url":"https://api.github.com/repos/fabpot/Twig-extensions/pulls/109","_links":{"self":{"href":"https://api.github.com/repos/fabpot/Twig-extensions/pulls/comments/15330521"},"html":{"href":"https://github.com/fabpot/Twig-extensions/pull/109#discussion_r15330521"},"pull_request":{"href":"https://api.github.com/repos/fabpot/Twig-extensions/pulls/109"}}},"pull_request":{"url":"https://api.github.com/repos/fabpot/Twig-extensions/pulls/109","id":15228112,"html_url":"https://github.com/fabpot/Twig-extensions/pull/109","diff_url":"https://github.com/fabpot/Twig-extensions/pull/109.diff","patch_url":"https://github.com/fabpot/Twig-extensions/pull/109.patch","issue_url":"https://api.github.com/repos/fabpot/Twig-extensions/issues/109","number":109,"state":"open","title":"Extension for displaying dates in a time ago format #partdeux","user":{"login":"RobinvdVleuten","id":238295,"avatar_url":"https://avatars.githubusercontent.com/u/238295?","gravatar_id":"836ddb644e4551401f98d5c4a7d95b39","url":"https://api.github.com/users/RobinvdVleuten","html_url":"https://github.com/RobinvdVleuten","followers_url":"https://api.github.com/users/RobinvdVleuten/followers","following_url":"https://api.github.com/users/RobinvdVleuten/following{/other_user}","gists_url":"https://api.github.com/users/RobinvdVleuten/gists{/gist_id}","starred_url":"https://api.github.com/users/RobinvdVleuten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RobinvdVleuten/subscriptions","organizations_url":"https://api.github.com/users/RobinvdVleuten/orgs","repos_url":"https://api.github.com/users/RobinvdVleuten/repos","events_url":"https://api.github.com/users/RobinvdVleuten/events{/privacy}","received_events_url":"https://api.github.com/users/RobinvdVleuten/received_events","type":"User","site_admin":false},"body":"Hi, \r\n\r\nMy PR for added a time_diff extension (#83) was way to messy with commits. I've recreated it in a single rebased commit. ","created_at":"2014-04-28T09:39:23Z","updated_at":"2014-07-24T05:30:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"148e8522830ef0bed64967d6738bf50e3da25671","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/fabpot/Twig-extensions/pulls/109/commits","review_comments_url":"https://api.github.com/repos/fabpot/Twig-extensions/pulls/109/comments","review_comment_url":"https://api.github.com/repos/fabpot/Twig-extensions/pulls/comments/{number}","comments_url":"https://api.github.com/repos/fabpot/Twig-extensions/issues/109/comments","statuses_url":"https://api.github.com/repos/fabpot/Twig-extensions/statuses/43076d94546fa0dd7b37b33b2735591d9b191bf2","head":{"label":"RobinvdVleuten:master","ref":"master","sha":"43076d94546fa0dd7b37b33b2735591d9b191bf2","user":{"login":"RobinvdVleuten","id":238295,"avatar_url":"https://avatars.githubusercontent.com/u/238295?","gravatar_id":"836ddb644e4551401f98d5c4a7d95b39","url":"https://api.github.com/users/RobinvdVleuten","html_url":"https://github.com/RobinvdVleuten","followers_url":"https://api.github.com/users/RobinvdVleuten/followers","following_url":"https://api.github.com/users/RobinvdVleuten/following{/other_user}","gists_url":"https://api.github.com/users/RobinvdVleuten/gists{/gist_id}","starred_url":"https://api.github.com/users/RobinvdVleuten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RobinvdVleuten/subscriptions","organizations_url":"https://api.github.com/users/RobinvdVleuten/orgs","repos_url":"https://api.github.com/users/RobinvdVleuten/repos","events_url":"https://api.github.com/users/RobinvdVleuten/events{/privacy}","received_events_url":"https://api.github.com/users/RobinvdVleuten/received_events","type":"User","site_admin":false},"repo":{"id":19233668,"name":"Twig-extensions","full_name":"RobinvdVleuten/Twig-extensions","owner":{"login":"RobinvdVleuten","id":238295,"avatar_url":"https://avatars.githubusercontent.com/u/238295?","gravatar_id":"836ddb644e4551401f98d5c4a7d95b39","url":"https://api.github.com/users/RobinvdVleuten","html_url":"https://github.com/RobinvdVleuten","followers_url":"https://api.github.com/users/RobinvdVleuten/followers","following_url":"https://api.github.com/users/RobinvdVleuten/following{/other_user}","gists_url":"https://api.github.com/users/RobinvdVleuten/gists{/gist_id}","starred_url":"https://api.github.com/users/RobinvdVleuten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RobinvdVleuten/subscriptions","organizations_url":"https://api.github.com/users/RobinvdVleuten/orgs","repos_url":"https://api.github.com/users/RobinvdVleuten/repos","events_url":"https://api.github.com/users/RobinvdVleuten/events{/privacy}","received_events_url":"https://api.github.com/users/RobinvdVleuten/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/RobinvdVleuten/Twig-extensions","description":"Twig extensions","fork":true,"url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions","forks_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/forks","keys_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/teams","hooks_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/hooks","issue_events_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/issues/events{/number}","events_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/events","assignees_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/assignees{/user}","branches_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/branches{/branch}","tags_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/tags","blobs_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/git/refs{/sha}","trees_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/statuses/{sha}","languages_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/languages","stargazers_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/stargazers","contributors_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/contributors","subscribers_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/subscribers","subscription_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/subscription","commits_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/commits{/sha}","git_commits_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/git/commits{/sha}","comments_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/comments{/number}","issue_comment_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/issues/comments/{number}","contents_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/contents/{+path}","compare_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/merges","archive_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/downloads","issues_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/issues{/number}","pulls_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/pulls{/number}","milestones_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/milestones{/number}","notifications_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/labels{/name}","releases_url":"https://api.github.com/repos/RobinvdVleuten/Twig-extensions/releases{/id}","created_at":"2014-04-28T09:33:04Z","updated_at":"2014-04-28T09:39:24Z","pushed_at":"2014-04-28T09:35:11Z","git_url":"git://github.com/RobinvdVleuten/Twig-extensions.git","ssh_url":"git@github.com:RobinvdVleuten/Twig-extensions.git","clone_url":"https://github.com/RobinvdVleuten/Twig-extensions.git","svn_url":"https://github.com/RobinvdVleuten/Twig-extensions","homepage":"http://www.twig-project.org/","size":197,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"fabpot:master","ref":"master","sha":"502303198afc1ec0bcc061c6f3a0926f7eb685e3","user":{"login":"fabpot","id":47313,"avatar_url":"https://avatars.githubusercontent.com/u/47313?","gravatar_id":"f1a2c5905e121d09feba5ad73898ffca","url":"https://api.github.com/users/fabpot","html_url":"https://github.com/fabpot","followers_url":"https://api.github.com/users/fabpot/followers","following_url":"https://api.github.com/users/fabpot/following{/other_user}","gists_url":"https://api.github.com/users/fabpot/gists{/gist_id}","starred_url":"https://api.github.com/users/fabpot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabpot/subscriptions","organizations_url":"https://api.github.com/users/fabpot/orgs","repos_url":"https://api.github.com/users/fabpot/repos","events_url":"https://api.github.com/users/fabpot/events{/privacy}","received_events_url":"https://api.github.com/users/fabpot/received_events","type":"User","site_admin":false},"repo":{"id":525836,"name":"Twig-extensions","full_name":"fabpot/Twig-extensions","owner":{"login":"fabpot","id":47313,"avatar_url":"https://avatars.githubusercontent.com/u/47313?","gravatar_id":"f1a2c5905e121d09feba5ad73898ffca","url":"https://api.github.com/users/fabpot","html_url":"https://github.com/fabpot","followers_url":"https://api.github.com/users/fabpot/followers","following_url":"https://api.github.com/users/fabpot/following{/other_user}","gists_url":"https://api.github.com/users/fabpot/gists{/gist_id}","starred_url":"https://api.github.com/users/fabpot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabpot/subscriptions","organizations_url":"https://api.github.com/users/fabpot/orgs","repos_url":"https://api.github.com/users/fabpot/repos","events_url":"https://api.github.com/users/fabpot/events{/privacy}","received_events_url":"https://api.github.com/users/fabpot/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fabpot/Twig-extensions","description":"Twig extensions","fork":false,"url":"https://api.github.com/repos/fabpot/Twig-extensions","forks_url":"https://api.github.com/repos/fabpot/Twig-extensions/forks","keys_url":"https://api.github.com/repos/fabpot/Twig-extensions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fabpot/Twig-extensions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fabpot/Twig-extensions/teams","hooks_url":"https://api.github.com/repos/fabpot/Twig-extensions/hooks","issue_events_url":"https://api.github.com/repos/fabpot/Twig-extensions/issues/events{/number}","events_url":"https://api.github.com/repos/fabpot/Twig-extensions/events","assignees_url":"https://api.github.com/repos/fabpot/Twig-extensions/assignees{/user}","branches_url":"https://api.github.com/repos/fabpot/Twig-extensions/branches{/branch}","tags_url":"https://api.github.com/repos/fabpot/Twig-extensions/tags","blobs_url":"https://api.github.com/repos/fabpot/Twig-extensions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fabpot/Twig-extensions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fabpot/Twig-extensions/git/refs{/sha}","trees_url":"https://api.github.com/repos/fabpot/Twig-extensions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fabpot/Twig-extensions/statuses/{sha}","languages_url":"https://api.github.com/repos/fabpot/Twig-extensions/languages","stargazers_url":"https://api.github.com/repos/fabpot/Twig-extensions/stargazers","contributors_url":"https://api.github.com/repos/fabpot/Twig-extensions/contributors","subscribers_url":"https://api.github.com/repos/fabpot/Twig-extensions/subscribers","subscription_url":"https://api.github.com/repos/fabpot/Twig-extensions/subscription","commits_url":"https://api.github.com/repos/fabpot/Twig-extensions/commits{/sha}","git_commits_url":"https://api.github.com/repos/fabpot/Twig-extensions/git/commits{/sha}","comments_url":"https://api.github.com/repos/fabpot/Twig-extensions/comments{/number}","issue_comment_url":"https://api.github.com/repos/fabpot/Twig-extensions/issues/comments/{number}","contents_url":"https://api.github.com/repos/fabpot/Twig-extensions/contents/{+path}","compare_url":"https://api.github.com/repos/fabpot/Twig-extensions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fabpot/Twig-extensions/merges","archive_url":"https://api.github.com/repos/fabpot/Twig-extensions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fabpot/Twig-extensions/downloads","issues_url":"https://api.github.com/repos/fabpot/Twig-extensions/issues{/number}","pulls_url":"https://api.github.com/repos/fabpot/Twig-extensions/pulls{/number}","milestones_url":"https://api.github.com/repos/fabpot/Twig-extensions/milestones{/number}","notifications_url":"https://api.github.com/repos/fabpot/Twig-extensions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fabpot/Twig-extensions/labels{/name}","releases_url":"https://api.github.com/repos/fabpot/Twig-extensions/releases{/id}","created_at":"2010-02-19T11:08:22Z","updated_at":"2014-07-11T15:54:37Z","pushed_at":"2014-07-14T05:04:43Z","git_url":"git://github.com/fabpot/Twig-extensions.git","ssh_url":"git@github.com:fabpot/Twig-extensions.git","clone_url":"https://github.com/fabpot/Twig-extensions.git","svn_url":"https://github.com/fabpot/Twig-extensions","homepage":"http://www.twig-project.org/","size":1003,"stargazers_count":372,"watchers_count":372,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"forks_count":173,"mirror_url":null,"open_issues_count":33,"forks":173,"open_issues":33,"watchers":372,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fabpot/Twig-extensions/pulls/109"},"html":{"href":"https://github.com/fabpot/Twig-extensions/pull/109"},"issue":{"href":"https://api.github.com/repos/fabpot/Twig-extensions/issues/109"},"comments":{"href":"https://api.github.com/repos/fabpot/Twig-extensions/issues/109/comments"},"review_comments":{"href":"https://api.github.com/repos/fabpot/Twig-extensions/pulls/109/comments"},"review_comment":{"href":"https://api.github.com/repos/fabpot/Twig-extensions/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/fabpot/Twig-extensions/pulls/109/commits"},"statuses":{"href":"https://api.github.com/repos/fabpot/Twig-extensions/statuses/43076d94546fa0dd7b37b33b2735591d9b191bf2"}}}}