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

Fix broken types after upgrade

Oliver Güntherb82d19f6dfdb
diff --git a/frontend/package-lock.json b/frontend/package-lock.json
index 5c3a6294230..80d7ccd0b59 100644
--- a/frontend/package-lock.json
+++ b/frontend/package-lock.json
@@ -4060,15 +4060,6 @@
"integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==",
"dev": true
},
- "@types/moment-timezone": {
- "version": "0.5.12",
- "resolved": "https://registry.npmjs.org/@types/moment-timezone/-/moment-timezone-0.5.12.tgz",
- "integrity": "sha512-hnHH2+Efg2vExr/dSz+IX860nSiyk9Sk4pJF2EmS11lRpMcNXeB4KBW5xcgw2QPsb9amTXdsVNEe5IoJXiT0uw==",
- "dev": true,
- "requires": {
- "moment": ">=2.14.0"
- }
- },
"@types/mousetrap": {
"version": "1.6.3",
"resolved": "https://registry.npmjs.org/@types/mousetrap/-/mousetrap-1.6.3.tgz",
@@ -12361,9 +12352,9 @@
"integrity": "sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg=="
},
"moment-timezone": {
- "version": "0.5.26",
- "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.26.tgz",
- "integrity": "sha512-sFP4cgEKTCymBBKgoxZjYzlSovC20Y6J7y3nanDc5RoBIXKlZhoYwBoZGe3flwU6A372AcRwScH8KiwV6zjy1g==",
+ "version": "0.5.34",
+ "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.34.tgz",
+ "integrity": "sha512-3zAEHh2hKUs3EXLESx/wsgw6IQdusOT8Bxm3D9UrHPQR7zlMmzwybC8zHEM1tQ4LJwP7fcxrWr8tuBg05fFCbg==",
"requires": {
"moment": ">= 2.9.0"
}
diff --git a/frontend/package.json b/frontend/package.json
index 714369e4276..9f9c323dccb 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -24,7 +24,6 @@
"@types/jqueryui": "^1.12.10",
"@types/lodash": "^4.14.149",
"@types/mime": "^2.0.3",
- "@types/moment-timezone": "^0.5.12",
"@types/mousetrap": "^1.6.3",
"@types/pako": "^1.0.1",
"@types/resize-observer-browser": "^0.1.4",
@@ -121,7 +120,7 @@
"mark.js": "^8.11.0",
"mime": "^2.5.2",
"moment": "^2.29.2",
- "moment-timezone": "^0.5.26",
+ "moment-timezone": "^0.5.34",
"mousetrap": "~1.6.3",
"ng-dynamic-component": "^6.0.0",
"ng2-charts": "^2.3.1",
diff --git a/frontend/src/app/core/datetime/timezone.service.ts b/frontend/src/app/core/datetime/timezone.service.ts
index 7a44312c419..607067ee07c 100644
--- a/frontend/src/app/core/datetime/timezone.service.ts
+++ b/frontend/src/app/core/datetime/timezone.service.ts
@@ -30,7 +30,21 @@ import { Injectable } from '@angular/core';
import { ConfigurationService } from 'core-app/core/config/configuration.service';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import * as moment from 'moment-timezone';
-import { Moment } from 'moment';
+import {
+ Moment,
+} from 'moment';
+
+declare module 'moment' {
+ interface Moment {
+ tz():string|undefined;
+
+ tz(timezone:string, keepLocalTime?:boolean):Moment;
+
+ zoneAbbr():string;
+
+ zoneName():string;
+ }
+}
@Injectable({ providedIn: 'root' })
export class TimezoneService {
@@ -41,7 +55,7 @@ export class TimezoneService {
this.setupLocale();
}
- public setupLocale() {
+ public setupLocale():void {
moment.locale(I18n.locale);
}
@@ -60,34 +74,10 @@ export class TimezoneService {
return d;
}
- public parseDate(date:Date|string, format?:string) {
+ public parseDate(date:Date|string, format?:string):Moment {
return moment(date, format);
}
- /**
- * Parses a string that is considered to be a local date and
- * turns it into a utc date time moment object.
- * 'Local' might mean the browsers default time zone or the one configured
- * in the Configuration Service.
- *
- * @param {String} date
- * @param {String} format
- * @returns {Moment}
- */
- public parseLocalDateTime(date:string, format?:string) {
- let result;
- const timeFormat = format || this.getTimeFormat();
-
- if (this.configurationService.isTimezoneSet()) {
- result = moment.tz(date, timeFormat, this.configurationService.timezone());
- } else {
- result = moment(date, timeFormat);
- }
- result.utc();
-
- return result;
- }
-
/**
* Parses the specified datetime and applies the user's configured timezone, if any.
*
@@ -96,15 +86,15 @@ export class TimezoneService {
* @param {String} datetime in 'YYYY-MM-DDTHH:mm:ssZ' format
* @returns {Moment}
*/
- public parseISODatetime(datetime:string) {
+ public parseISODatetime(datetime:string):Moment {
return this.parseDatetime(datetime, 'YYYY-MM-DDTHH:mm:ssZ');
}
- public parseISODate(date:string) {
+ public parseISODate(date:string):Moment {
return this.parseDate(date, 'YYYY-MM-DD');
}
- public formattedDate(date:string) {
+ public formattedDate(date:string):string {
const d = this.parseDate(date);
return d.format(this.getDateFormat());
}
@@ -129,11 +119,11 @@ export class TimezoneService {
return date.diff(today, 'days');
}
- public formattedTime(datetimeString:string) {
+ public formattedTime(datetimeString:string):string {
return this.parseDatetime(datetimeString).format(this.getTimeFormat());
}
- public formattedDatetime(datetimeString:string) {
+ public formattedDatetime(datetimeString:string):string {
const c = this.formattedDatetimeComponents(datetimeString);
return `${c[0]} ${c[1]}`;
}
@@ -143,7 +133,7 @@ export class TimezoneService {
return d.fromNow();
}
- public formattedDatetimeComponents(datetimeString:string) {
+ public formattedDatetimeComponents(datetimeString:string):string[] {
const d = this.parseDatetime(datetimeString);
return [
d.format(this.getDateFormat()),
@@ -151,40 +141,40 @@ export class TimezoneService {
];
}
- public toHours(durationString:string) {
+ public toHours(durationString:string):number {
return Number(moment.duration(durationString).asHours().toFixed(2));
}
- public formattedDuration(durationString:string) {
+ public formattedDuration(durationString:string):string {
return this.I18n.t('js.units.hour', { count: this.toHours(durationString) });
}
- public formattedISODate(date:any) {
+ public formattedISODate(date:any):string {
return this.parseDate(date).format('YYYY-MM-DD');
}
- public formattedISODateTime(datetime:any) {
+ public formattedISODateTime(datetime:any):string {
return datetime.format();
}
- public isValidISODate(date:any) {
+ public isValidISODate(date:any):boolean {
return this.isValid(date, 'YYYY-MM-DD');
}
- public isValidISODateTime(dateTime:string) {
+ public isValidISODateTime(dateTime:string):boolean {
return this.isValid(dateTime, 'YYYY-MM-DDTHH:mm:ssZ');
}
- public isValid(date:string, dateFormat:string) {
+ public isValid(date:string, dateFormat:string):boolean {
const format = dateFormat || this.getDateFormat();
return moment(date, [format], true).isValid();
}
- public getDateFormat() {
+ public getDateFormat():string {
return this.configurationService.dateFormatPresent() ? this.configurationService.dateFormat() : 'L';
}
- public getTimeFormat() {
+ public getTimeFormat():string {
return this.configurationService.timeFormatPresent() ? this.configurationService.timeFormat() : 'LT';
}
}