FIX: escapes localization for double quotes (#754)

- DRY date formatting for start/end datetimes
- escape double quotes for German locale
This commit is contained in:
Yuriy Kurant 2025-06-25 20:00:15 +08:00 committed by GitHub
parent 6c5b8ba2bb
commit d06761b6fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 19 deletions

View File

@ -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() {