Update format specifiers in readable_publish_date (#13660)

* Update format specifiers in readable_publish_date

* Trigger Travis manually

* Update format specifiers in readable_publish_date

* Update format specifiers in readable_publish_date

Co-authored-by: rhymes <rhymes@hey.com>
This commit is contained in:
arunkc 2021-05-07 12:21:49 +05:30 committed by GitHub
parent cf9f6094cd
commit 47908d7a87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 15 additions and 15 deletions

View file

@ -23,9 +23,9 @@ class CommentDecorator < ApplicationDecorator
def readable_publish_date
if created_at.year == Time.current.year
created_at.strftime("%b %e")
created_at.strftime("%b %-e")
else
created_at.strftime("%b %e '%y")
created_at.strftime("%b %-e '%y")
end
end
end

View file

@ -14,9 +14,9 @@ class PodcastEpisodeDecorator < ApplicationDecorator
return "" unless published_at
if published_at.year == Time.current.year
published_at.strftime("%b %e")
published_at.strftime("%b %-e")
else
published_at.strftime("%b %e '%y")
published_at.strftime("%b %-e '%y")
end
end

View file

@ -3,7 +3,7 @@ module DateHelper
datetime = Time.zone.parse(datetime) if datetime.is_a?(String)
tag.time(
datetime.strftime("%b %e#{', %Y' if show_year}"),
datetime.strftime("%b %-e#{', %Y' if show_year}"),
datetime: datetime.utc.iso8601,
class: "date#{'-no-year' unless show_year}",
)

View file

@ -407,9 +407,9 @@ class Article < ApplicationRecord
def readable_publish_date
relevant_date = displayable_published_at
if relevant_date && relevant_date.year == Time.current.year
relevant_date&.strftime("%b %e")
relevant_date&.strftime("%b %-e")
else
relevant_date&.strftime("%b %e '%y")
relevant_date&.strftime("%b %-e '%y")
end
end

View file

@ -134,9 +134,9 @@ class Comment < ApplicationRecord
def readable_publish_date
if created_at.year == Time.current.year
created_at.strftime("%b %e")
created_at.strftime("%b %-e")
else
created_at.strftime("%b %e '%y")
created_at.strftime("%b %-e '%y")
end
end

View file

@ -55,13 +55,13 @@ RSpec.describe PodcastEpisodeDecorator, type: :decorator do
it "returns the correct date for a same year publication" do
published_at = Time.current
pe = build(:podcast_episode, published_at: published_at)
expect(pe.decorate.readable_publish_date).to eq(published_at.strftime("%b %e"))
expect(pe.decorate.readable_publish_date).to eq(published_at.strftime("%b %-e"))
end
it "returns the correct date for a publication within a different year" do
published_at = 2.years.ago
pe = build(:podcast_episode, published_at: published_at)
expect(pe.decorate.readable_publish_date).to eq(published_at.strftime("%b %e '%y"))
expect(pe.decorate.readable_publish_date).to eq(published_at.strftime("%b %-e '%y"))
end
end

View file

@ -4,14 +4,14 @@ describe DateHelper do
describe ".local_date" do
it "renders date" do
time = Time.now.utc
date = time.strftime("%b %e, %Y")
date = time.strftime("%b %-e, %Y")
tag = helper.local_date(time)
expect(tag).to eq "<time datetime=\"#{time.iso8601}\" class=\"date\">#{date}</time>"
end
it "renders date without year" do
time = Time.now.utc
date = time.strftime("%b %e")
date = time.strftime("%b %-e")
tag = helper.local_date(time, show_year: false)
expect(tag).to eq "<time datetime=\"#{time.iso8601}\" class=\"date-no-year\">#{date}</time>"
end

View file

@ -600,7 +600,7 @@ RSpec.describe Article, type: :model do
it "does not show year in readable time if not current year" do
time_now = Time.current
article.published_at = time_now
expect(article.readable_publish_date).to eq(time_now.strftime("%b %e"))
expect(article.readable_publish_date).to eq(time_now.strftime("%b %-e"))
end
it "shows year in readable time if not current year" do

View file

@ -238,7 +238,7 @@ RSpec.describe Comment, type: :model do
describe "#readable_publish_date" do
it "does not show year in readable time if not current year" do
expect(comment.readable_publish_date).to eq(comment.created_at.strftime("%b %e"))
expect(comment.readable_publish_date).to eq(comment.created_at.strftime("%b %-e"))
end
it "shows year in readable time if not current year" do