From 54bc2bdba78e8d1a602f564a8a2acab202cb8940 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 17 Oct 2019 16:18:06 +0200 Subject: [PATCH] UX: emphasizes on local-dates being UTC in excerpts (#8208) --- plugins/discourse-local-dates/plugin.rb | 6 ++++++ .../discourse-local-dates/spec/lib/pretty_text_spec.rb | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/plugins/discourse-local-dates/plugin.rb b/plugins/discourse-local-dates/plugin.rb index 2adf23dca08..5ee9fefad73 100644 --- a/plugins/discourse-local-dates/plugin.rb +++ b/plugins/discourse-local-dates/plugin.rb @@ -53,6 +53,12 @@ after_initialize do custom_fields[DiscourseLocalDates::POST_CUSTOM_FIELD] || [] end + on(:reduce_excerpt) do |fragment, post| + fragment.css('.discourse-local-date').each do |container| + container.content = "#{container.content} (UTC)" + end + end + on(:reduce_cooked) do |fragment| fragment.css('.discourse-local-date').each do |container| if container.attributes['data-email-preview'] diff --git a/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb b/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb index 476dd54f3da..6a1a4ec76f7 100644 --- a/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb +++ b/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb @@ -71,4 +71,13 @@ describe PrettyText do end end end + + context 'excerpt simplified rendering' do + let(:post) { Fabricate(:post, raw: '[date=2019-10-16 time=14:00:00 format="LLLL" timezone="America/New_York"]') } + + it 'adds UTC' do + excerpt = PrettyText.excerpt(post.cooked, 200) + expect(excerpt).to eq("Wednesday, October 16, 2019 6:00 PM (UTC)") + end + end end