diff --git a/plugins/discourse-local-dates/assets/javascripts/discourse-local-dates.js b/plugins/discourse-local-dates/assets/javascripts/discourse-local-dates.js index abced1835d5..a043ec3ea7d 100644 --- a/plugins/discourse-local-dates/assets/javascripts/discourse-local-dates.js +++ b/plugins/discourse-local-dates/assets/javascripts/discourse-local-dates.js @@ -12,9 +12,9 @@ } var relativeTime; - if (options.forceTimezone) { + if (options.timezone) { relativeTime = moment - .tz(options.date + " " + options.time, options.forceTimezone) + .tz(options.date + " " + options.time, options.timezone) .utc(); } else { relativeTime = moment.utc(options.date + " " + options.time); @@ -104,7 +104,7 @@ options.time = $this.attr("data-time") || "00:00:00"; options.recurring = $this.attr("data-recurring"); options.timezones = $this.attr("data-timezones"); - options.forceTimezone = $this.attr("data-force-timezone"); + options.timezone = $this.attr("data-timezone"); processElement($this, options); }); 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 83bd99c903c..ab4386f622f 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 @@ -6,7 +6,7 @@ function addLocalDate(buffer, matches, state) { let config = { date: null, time: null, - forceTimezone: null, + timezone: null, format: "YYYY-MM-DD HH:mm:ss", timezones: "Etc/UTC" }; @@ -19,7 +19,7 @@ function addLocalDate(buffer, matches, state) { config.date = parsed.attrs.date; config.time = parsed.attrs.time; - config.forceTimezone = parsed.attrs.forceTimezone || parsed.attrs.timezone; + config.timezone = parsed.attrs.timezone; config.recurring = parsed.attrs.recurring; config.format = parsed.attrs.format || config.format; config.timezones = parsed.attrs.timezones || config.timezones; @@ -37,12 +37,12 @@ function addLocalDate(buffer, matches, state) { } let dateTime; - if (config.forceTimezone) { + if (config.timezone) { token.attrs.push([ - "data-force-timezone", - state.md.utils.escapeHtml(config.forceTimezone) + "data-timezone", + state.md.utils.escapeHtml(config.timezone) ]); - dateTime = moment.tz(`${config.date} ${config.time}`, config.forceTimezone); + dateTime = moment.tz(`${config.date} ${config.time}`, config.timezone); } else { dateTime = moment.utc(`${config.date} ${config.time}`); } diff --git a/plugins/discourse-local-dates/plugin.rb b/plugins/discourse-local-dates/plugin.rb index c2b299b521e..54fe359ff00 100644 --- a/plugins/discourse-local-dates/plugin.rb +++ b/plugins/discourse-local-dates/plugin.rb @@ -27,9 +27,10 @@ after_initialize do dates = doc.css('span.discourse-local-date').map do |cooked_date| date = {} cooked_date.attributes.values.each do |attribute| - if attribute.name && ['data-date', 'data-time'].include?(attribute.name) + data_name = attribute.name&.gsub('data-', '') + if data_name && ['date', 'time', 'timezone'].include?(data_name) unless attribute.value == 'undefined' - date[attribute.name.gsub('data-', '')] = CGI.escapeHTML(attribute.value || "") + date[data_name] = CGI.escapeHTML(attribute.value || "") end end end diff --git a/plugins/discourse-local-dates/spec/integration/local_dates_spec.rb b/plugins/discourse-local-dates/spec/integration/local_dates_spec.rb index 2fed2e2dc0a..738eb8f332b 100644 --- a/plugins/discourse-local-dates/spec/integration/local_dates_spec.rb +++ b/plugins/discourse-local-dates/spec/integration/local_dates_spec.rb @@ -15,7 +15,7 @@ RSpec.describe "Local Dates" do expect(cooked).to include('class="discourse-local-date"') expect(cooked).to include('data-date="2018-05-08"') expect(cooked).to include('data-format="L LTS"') - expect(cooked).not_to include('data-force-timezone=') + expect(cooked).not_to include('data-timezone=') expect(cooked).to include( 'data-timezones="Europe/Paris|America/Los_Angeles"' @@ -32,7 +32,7 @@ RSpec.describe "Local Dates" do cooked = post.cooked - expect(cooked).to include('data-force-timezone="Asia/Calcutta"') + expect(cooked).to include('data-timezone="Asia/Calcutta"') expect(cooked).to include('05/08/2018 4:30:00 PM') end diff --git a/plugins/discourse-local-dates/spec/models/post_spec.rb b/plugins/discourse-local-dates/spec/models/post_spec.rb index 29793fb5410..13e7e9a5ac2 100644 --- a/plugins/discourse-local-dates/spec/models/post_spec.rb +++ b/plugins/discourse-local-dates/spec/models/post_spec.rb @@ -9,13 +9,14 @@ describe Post do describe '#local_dates' do it "should have correct custom fields" do post = Fabricate(:post, raw: <<~SQL) - [date=2018-09-17 time=01:39:00 format="LLL" timezones="Europe/Paris|America/Los_Angeles"] + [date=2018-09-17 time=01:39:00 format="LLL" timezone="Europe/Paris" timezones="Europe/Paris|America/Los_Angeles"] SQL CookedPostProcessor.new(post).post_process expect(post.local_dates.count).to eq(1) expect(post.local_dates[0]["date"]).to eq("2018-09-17") expect(post.local_dates[0]["time"]).to eq("01:39:00") + expect(post.local_dates[0]["timezone"]).to eq("Europe/Paris") post.raw = "Text removed" post.save