mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 12:40:40 +08:00
Rename timezone attribute and add it to local date details field
This commit is contained in:
parent
8d06731484
commit
2c8c1bf188
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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}`);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user