From 3fbb2cd728f9658d2ef36734232e18f60aef80e0 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 20 Mar 2014 13:25:17 -0400 Subject: [PATCH] Improve date displaying on embedded comments --- app/helpers/embed_helper.rb | 18 ++++++++++++++++++ app/views/embed/comments.html.erb | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 app/helpers/embed_helper.rb diff --git a/app/helpers/embed_helper.rb b/app/helpers/embed_helper.rb new file mode 100644 index 00000000000..d3f04cd59bf --- /dev/null +++ b/app/helpers/embed_helper.rb @@ -0,0 +1,18 @@ +module EmbedHelper + + def embed_post_date(dt) + current = Time.now + + if dt >= 1.day.ago + distance_of_time_in_words(dt, current) + else + if dt.year == current.year + dt.strftime("%e %b") + else + dt.strftime("%e %b %Y") + end + end + end + +end + diff --git a/app/views/embed/comments.html.erb b/app/views/embed/comments.html.erb index ed39f5d49fd..edb6319c4d8 100644 --- a/app/views/embed/comments.html.erb +++ b/app/views/embed/comments.html.erb @@ -10,7 +10,7 @@ <%- if @topic_view.posts.present? %> <%- @topic_view.posts.each do |post| %>
- <%= link_to post.created_at.strftime("%e %b %Y"), post.url, class: 'post-date', target: "_blank" %> + <%= link_to embed_post_date(post.created_at), post.url, class: 'post-date', target: "_blank" %> <%- if post.reply_to_post.present? %> <%= link_to I18n.t('embed.in_reply_to', username: post.reply_to_post.username), post.reply_to_post.url, 'data-link-to-post' => post.reply_to_post.id.to_s, :class => 'in-reply-to' %> <%- end %>