Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Dedupe date time formats

Benjamin Bädorf33ebc2d269f8
diff --git a/frontend/src/app/features/work-packages/components/wp-card-view/wp-single-card/wp-single-card.component.ts b/frontend/src/app/features/work-packages/components/wp-card-view/wp-single-card/wp-single-card.component.ts
index 7e4fed61d60..a69b1082dd8 100644
--- a/frontend/src/app/features/work-packages/components/wp-card-view/wp-single-card/wp-single-card.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-card-view/wp-single-card/wp-single-card.component.ts
@@ -81,7 +81,18 @@ export class WorkPackageSingleCardComponent extends UntilDestroyedMixin implemen
detailsView: this.I18n.t('js.button_open_details'),
};
- isNewResource = isNewResource;
+ public isNewResource = isNewResource;
+
+ private dateTimeFormatYear = new Intl.DateTimeFormat(this.I18n.locale, {
+ year: 'numeric',
+ month: 'short',
+ day: 'numeric',
+ });
+
+ private dateTimeFormat = new Intl.DateTimeFormat(this.I18n.locale, {
+ month: 'short',
+ day: 'numeric',
+ });
constructor(
readonly pathHelper:PathHelperService,
@@ -174,24 +185,20 @@ export class WorkPackageSingleCardComponent extends UntilDestroyedMixin implemen
public wpDates(wp:WorkPackageResource):string {
const { startDate, dueDate } = wp;
- const dateTimeFormat = new Intl.DateTimeFormat(this.I18n.locale, {
- year: 'numeric',
- month: 'short',
- day: 'numeric',
- });
if (startDate && dueDate) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore see https://github.com/microsoft/TypeScript/issues/46905
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
- return String(dateTimeFormat.formatRange(new Date(startDate), new Date(dueDate)));
+ return String(this.dateTimeFormatYear.formatRange(new Date(startDate), new Date(dueDate)));
}
+
if (!startDate && dueDate) {
- return `– ${dateTimeFormat.format(new Date(dueDate))}`;
+ return `– ${this.dateTimeFormatYear.format(new Date(dueDate))}`;
}
if (startDate && !dueDate) {
- return `${dateTimeFormat.format(new Date(startDate))} –`;
+ return `${this.dateTimeFormatYear.format(new Date(startDate))} –`;
}
return '';
@@ -203,12 +210,7 @@ export class WorkPackageSingleCardComponent extends UntilDestroyedMixin implemen
return '';
}
- const dateTimeFormat = new Intl.DateTimeFormat(this.I18n.locale, {
- month: 'short',
- day: 'numeric',
- });
-
- return dateTimeFormat.format(new Date(startDate));
+ return this.dateTimeFormat.format(new Date(startDate));
}
endDate(wp:WorkPackageResource):string {
@@ -217,12 +219,7 @@ export class WorkPackageSingleCardComponent extends UntilDestroyedMixin implemen
return '';
}
- const dateTimeFormat = new Intl.DateTimeFormat(this.I18n.locale, {
- month: 'short',
- day: 'numeric',
- });
-
- return dateTimeFormat.format(new Date(dueDate));
+ return this.dateTimeFormat.format(new Date(dueDate));
}
wpOverDueHighlighting(wp:WorkPackageResource):string {