From bfa25487eb36185b427e83fb3a7c5c7ddf76b6d3 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Tue, 16 Oct 2018 16:19:43 +0530 Subject: [PATCH] FIX: Support for local-date email preview without time attribute --- .../lib/discourse-markdown/discourse-local-dates.js.es6 | 7 ++++--- .../discourse-local-dates/spec/lib/pretty_text_spec.rb | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/discourse-local-dates/assets/javascripts/lib/discourse-markdown/discourse-local-dates.js.es6 b/plugins/discourse-local-dates/assets/javascripts/lib/discourse-markdown/discourse-local-dates.js.es6 index ab4386f622f..5b63766e1ae 100644 --- a/plugins/discourse-local-dates/assets/javascripts/lib/discourse-markdown/discourse-local-dates.js.es6 +++ b/plugins/discourse-local-dates/assets/javascripts/lib/discourse-markdown/discourse-local-dates.js.es6 @@ -32,19 +32,20 @@ function addLocalDate(buffer, matches, state) { ["data-timezones", state.md.utils.escapeHtml(config.timezones)] ]; + let dateTime = config.date; if (config.time) { token.attrs.push(["data-time", state.md.utils.escapeHtml(config.time)]); + dateTime = `${dateTime} ${config.time}`; } - let dateTime; if (config.timezone) { token.attrs.push([ "data-timezone", state.md.utils.escapeHtml(config.timezone) ]); - dateTime = moment.tz(`${config.date} ${config.time}`, config.timezone); + dateTime = moment.tz(dateTime, config.timezone); } else { - dateTime = moment.utc(`${config.date} ${config.time}`); + dateTime = moment.utc(dateTime); } if (config.recurring) { 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 617753415f5..216ac55d258 100644 --- a/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb +++ b/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb @@ -11,5 +11,14 @@ describe PrettyText do HTML expect(PrettyText.format_for_email(cooked)).to match_html(cooked_mail) + + cooked = PrettyText.cook <<~MD + [date=2018-05-08 format=LLL timezone="Europe/Berlin" timezones="Europe/Paris|America/Los_Angeles"] + MD + cooked_mail = <<~HTML +

May 8, 2018 12:00 AM (Europe: Paris)

+ HTML + + expect(PrettyText.format_for_email(cooked)).to match_html(cooked_mail) end end