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

Use common helper to derive date, time, offset from baseline

Oliver Günther7af3a4406bcd
diff --git a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-helpers.ts b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-helpers.ts
index 8a56003278e..254f655b454 100644
--- a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-helpers.ts
+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-helpers.ts
@@ -3,6 +3,12 @@ import * as moment from 'moment-timezone';
export type BaselineOption = 'oneDayAgo'|'lastWorkingDay'|'oneWeekAgo'|'oneMonthAgo'|'aSpecificDate'|'betweenTwoSpecificDates';
+export interface BaselineTimestamp {
+ date:string;
+ time:string;
+ offset:string;
+}
+
const BASELINE_OPTIONS = ['oneDayAgo', 'lastWorkingDay', 'oneWeekAgo', 'oneMonthAgo', 'aSpecificDate', 'betweenTwoSpecificDates'];
export function baselineFilterFromValue(selectedDates:string[]):BaselineOption|null {
@@ -22,16 +28,20 @@ export function baselineFilterFromValue(selectedDates:string[]):BaselineOption|n
return 'betweenTwoSpecificDates';
}
-export function getOffsetFromBaseline(value:string):string|null {
+export function getPartsFromTimestamp(value:string):BaselineTimestamp|null {
if (value.includes('@')) {
- const [, timeWithZone] = value.split(/[@]/);
- const [, offset] = timeWithZone.split(/\s+/)[0];
- return offset;
+ const [date, timeWithZone] = value.split(/[@]/);
+ const [time, offset] = timeWithZone.split(/(?=[+-])/);
+ return { date, time, offset };
}
if (value !== 'PT0S') {
- const date = moment(value);
- return date.format('Z');
+ const dateObj = moment(value);
+ const date = dateObj.format('YYYY-MM-DD');
+ const time = dateObj.format('HH:mm');
+ const offset = dateObj.format('Z');
+
+ return { date, time, offset };
}
return null;
diff --git a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.ts b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.ts
index a52048acba3..08e2f08355a 100644
--- a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.ts
@@ -44,7 +44,7 @@ import { ISchemaProxy } from 'core-app/features/hal/schemas/schema-proxy';
import { WorkPackageViewColumnsService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-columns.service';
import {
baselineFilterFromValue,
- getOffsetFromBaseline,
+ getPartsFromTimestamp,
} from 'core-app/features/work-packages/components/wp-baseline/baseline-helpers';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import * as moment from 'moment-timezone';
@@ -108,7 +108,11 @@ export class OpBaselineLegendsComponent extends UntilDestroyedMixin implements O
filter(() => this.wpTableBaseline.isActive())
)
.subscribe((timestamps) => {
- this.offset = getOffsetFromBaseline(timestamps[0]);
+ const parts = getPartsFromTimestamp(timestamps[0]);
+ if (parts) {
+ this.offset = parts.offset;
+ }
+
this.userTimezone = this.timezoneService.userTimezone();
this.userOffset = moment().tz(this.userTimezone).format('Z') as string;
diff --git a/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.ts b/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.ts
index 617befd61ff..08253233a0c 100644
--- a/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.ts
@@ -51,7 +51,10 @@ import {
WorkPackageViewBaselineService,
} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service';
import { validDate } from 'core-app/shared/components/datepicker/helpers/date-modal.helpers';
-import { baselineFilterFromValue } from 'core-app/features/work-packages/components/wp-baseline/baseline-helpers';
+import {
+ baselineFilterFromValue,
+ getPartsFromTimestamp,
+} from 'core-app/features/work-packages/components/wp-baseline/baseline-helpers';
import * as moment from 'moment-timezone';
@Component({
@@ -168,16 +171,11 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
if (this.wpTableBaseline.isActive()) {
this.filterChange(baselineFilterFromValue(this.wpTableBaseline.current));
this.wpTableBaseline.current.forEach((value, i) => {
- if (value.includes('@')) {
- const [, timeWithZone] = value.split(/[@]/);
- const [time, offset] = timeWithZone.split(/\s+/)[0];
- this.selectedTimes[i] = time || '00:00';
- this.selectedOffsets[i] = offset;
- } else if (value !== 'PT0S') {
- const date = moment(value);
- this.selectedDates[i] = date.format('YYYY-MM-DD');
- this.selectedTimes[i] = date.format('HH:mm');
- this.selectedOffsets[i] = date.format('Z');
+ const parts = getPartsFromTimestamp(value);
+ if (parts) {
+ this.selectedDates[i] = !!this.selectedDates[i] ? this.selectedDates[i] : parts.date;
+ this.selectedTimes[i] = parts.time;
+ this.selectedOffsets[i] = parts.offset;
}
});
}