From d06761b6fecb1be64c8445a828c81f47eac813a5 Mon Sep 17 00:00:00 2001 From: Yuriy Kurant Date: Wed, 25 Jun 2025 20:00:15 +0800 Subject: [PATCH] FIX: escapes localization for double quotes (#754) - DRY date formatting for start/end datetimes - escape double quotes for German locale --- .../components/discourse-post-event/dates.gjs | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/assets/javascripts/discourse/components/discourse-post-event/dates.gjs b/assets/javascripts/discourse/components/discourse-post-event/dates.gjs index a9a96987..48f2e911 100644 --- a/assets/javascripts/discourse/components/discourse-post-event/dates.gjs +++ b/assets/javascripts/discourse/components/discourse-post-event/dates.gjs @@ -29,17 +29,10 @@ export default class DiscoursePostEventDates extends Component { } get startsAtFormat() { - const formatParts = ["ddd, MMM D"]; - - if (!this.isSameYear(this.startsAt)) { - formatParts.push("YYYY"); - } - - const dateString = formatParts.join(", "); - const timeString = - this.hasTime(this.startsAt) || this.isSingleDayEvent ? " LT" : ""; - - return `\u0022${dateString}${timeString}\u0022`; + return this._buildFormat(this.startsAt, { + includeYear: !this.isSameYear(this.startsAt), + includeTime: this.hasTime(this.startsAt) || this.isSingleDayEvent, + }); } get endsAtFormat() { @@ -47,20 +40,24 @@ export default class DiscoursePostEventDates extends Component { return "LT"; } + return this._buildFormat(this.endsAt, { + includeYear: + !this.isSameYear(this.endsAt) || + !this.isSameYear(this.endsAt, this.startsAt), + includeTime: this.hasTime(this.endsAt), + }); + } + + _buildFormat(date, { includeYear, includeTime }) { const formatParts = ["ddd, MMM D"]; - - const showYear = - !this.isSameYear(this.endsAt) || - !this.isSameYear(this.endsAt, this.startsAt); - - if (showYear) { + if (includeYear) { formatParts.push("YYYY"); } const dateString = formatParts.join(", "); - const timeString = this.hasTime(this.endsAt) ? " LT" : ""; + const timeString = includeTime ? " LT" : ""; - return `'${dateString}${timeString}'`; + return `\u0022${dateString}${timeString}\u0022`; } get isSingleDayEvent() {