diff --git a/date.php b/date.php index 41ff87e..68fd811 100755 --- a/date.php +++ b/date.php @@ -17,16 +17,27 @@ class Date 60 => 'minute', 1 => 'second'); - foreach ($condition as $secs => $str) + foreach ($condition as $secs => $secs_as_str) { - $d = $estimate_time / $secs; + $time_ago = $estimate_time / $secs; - if ($d >= 1) + if ($time_ago >= 1) { - $r = round ($d); - return $r . ' ' . $str . ($r > 1 ? 's' : '') . ' ago'; + $rounded_time = round ($time_ago); + return $rounded_time . ' ' . $secs_as_str . ($rounded_time > 1 ? 's' : '') . ' ago'; } } } + + public static function datetime ($datetime) + { + return date("Y-m-d\TH:i:s", $datetime); + } + + public static function title ($datetime) + { + return date("M\\ j,\\ Y,\\ g:s\\ A\\ e", $datetime); + } + } diff --git a/template/comment.twig b/template/comment.twig index 4914c26..477e8c7 100755 --- a/template/comment.twig +++ b/template/comment.twig @@ -22,7 +22,7 @@ %} {# DateTime #} - {{ comment.created|ago }} + {% if user %} — diff --git a/template/edit_comment.twig b/template/edit_comment.twig index 703c772..1b9d17e 100755 --- a/template/edit_comment.twig +++ b/template/edit_comment.twig @@ -7,7 +7,7 @@
by {{ item.data.username }} - {{ item.data.created|ago }} +
diff --git a/template/edit_post.twig b/template/edit_post.twig index e88954e..4bd3a28 100755 --- a/template/edit_post.twig +++ b/template/edit_post.twig @@ -13,7 +13,7 @@
by {{ item.data.username }} - {{ item.data.created|ago }} +

Link

diff --git a/template/index.twig b/template/index.twig index 359a019..45fb764 100755 --- a/template/index.twig +++ b/template/index.twig @@ -52,7 +52,7 @@ _\(/_ .:.*_\/_* : /\ : } only %} - {{ post.created|ago }} + by {{ post.username }}{{ post.commentsCount ? post.commentsCount }} comments diff --git a/template/post.twig b/template/post.twig index 6e60c4f..9c18577 100755 --- a/template/post.twig +++ b/template/post.twig @@ -23,7 +23,7 @@ } only %} - by {{ post.username }} {{ post.created|ago }} + by {{ post.username }} — {{ post.vote }} votes, {{ post.commentsCount }} comments {% if user and post.userId == user.id %} diff --git a/template/reply.twig b/template/reply.twig index 7ff15fe..46cc10c 100755 --- a/template/reply.twig +++ b/template/reply.twig @@ -4,7 +4,7 @@

Reply to {{ comment.username }}

- posted {{ comment.created|ago }} + posted on {{ comment.postTitle }}
diff --git a/template/search.twig b/template/search.twig index 99ac99c..bb8a093 100755 --- a/template/search.twig +++ b/template/search.twig @@ -18,7 +18,7 @@
- {{ post.created|ago }} + by {{ post.username }}{{ post.commentsCount ? post.commentsCount }} comments diff --git a/template/user_comments.twig b/template/user_comments.twig index bf8097c..96e9d4c 100755 --- a/template/user_comments.twig +++ b/template/user_comments.twig @@ -11,7 +11,7 @@
read — - {{ comment.created|ago }} on {{ comment.postTitle }} + on {{ comment.postTitle }}
diff --git a/template/user_posts.twig b/template/user_posts.twig index ed7184a..b5967db 100755 --- a/template/user_posts.twig +++ b/template/user_posts.twig @@ -19,7 +19,7 @@ {# Post info #}
{{ post.vote }} votes, - {{ post.created|ago }} + {{ post.commentsCount }} comments
diff --git a/template/user_replies.twig b/template/user_replies.twig index 71a252a..aabafe9 100755 --- a/template/user_replies.twig +++ b/template/user_replies.twig @@ -12,7 +12,7 @@ read reply — - by {{ comment.username }} {{ comment.created|ago }} on {{ comment.postTitle }} + by {{ comment.username }} on {{ comment.postTitle }} diff --git a/twig.php b/twig.php index f69390d..9ea3f83 100755 --- a/twig.php +++ b/twig.php @@ -31,6 +31,15 @@ $twig->addFilter ('ago', new Twig_Filter_Function (function ($datetime) { return Date::ago (strtotime ($datetime)); })); +$twig->addFilter ('datetime', new Twig_Filter_Function (function ($datetime) { + return Date::datetime (strtotime ($datetime)); +})); + +$twig->addFilter ('title', new Twig_Filter_Function (function ($datetime) { + return Date::title (strtotime ($datetime)); +})); + + // Format Markdown to HTML $twig->addFilter ('markdown', new Twig_Filter_Function(function ($markdown) { $parsedown = new Parsedown ();