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 offset to display and identify timezone differences

Oliver Günther9156bb2f3ece
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 a4c2b56b1f0..261f36a9dfe 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
@@ -84,7 +84,8 @@ export class OpBaselineLegendsComponent {
}
public getFilterName() {
- const timestamps = this.wpTableBaseline.current.map((el) => el.split(/[@T]/));
+ const timestamps = this.wpTableBaseline.current;
+ const datesAndTimes = this.wpTableBaseline.current.map((el) => el.split(/[@T]/));
const filter = baselineFilterFromValue(this.wpTableBaseline.current);
const changesSince = this.I18n.t('js.baseline.legends.changes_since');
let dateTime = '';
@@ -92,27 +93,27 @@ export class OpBaselineLegendsComponent {
switch (filter) {
case 'oneDayAgo':
dateTime = this.I18n.t('js.baseline.drop_down.yesterday');
- dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.yesterdayDate(), timestamps[0][1])})`;
+ dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.yesterdayDate(), datesAndTimes[0][1])})`;
break;
case 'lastWorkingDay':
dateTime = this.I18n.t('js.baseline.drop_down.last_working_day');
- dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.lastWorkingDate(), timestamps[0][1])})`;
+ dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.lastWorkingDate(), datesAndTimes[0][1])})`;
break;
case 'oneWeekAgo':
dateTime = this.I18n.t('js.baseline.drop_down.last_week');
- dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.lastweekDate(), timestamps[0][1])})`;
+ dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.lastweekDate(), datesAndTimes[0][1])})`;
break;
case 'oneMonthAgo':
dateTime = this.I18n.t('js.baseline.drop_down.last_month');
- dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.lastMonthDate(), timestamps[0][1])})`;
+ dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.lastMonthDate(), datesAndTimes[0][1])})`;
break;
case 'aSpecificDate':
dateTime = this.I18n.t('js.baseline.drop_down.a_specific_date');
- dateTime += ` (${this.getFormattedDate(timestamps[0][0], timestamps[0][1])})`;
+ dateTime += ` (${this.timezoneService.formattedDatetime(timestamps[0])})`;
break;
case 'betweenTwoSpecificDates':
dateTime = this.I18n.t('js.baseline.drop_down.between_two_specific_dates');
- dateTime += ` (${this.getFormattedDate(timestamps[0][0], timestamps[0][1])} - ${this.getFormattedDate(timestamps[1][0], timestamps[1][1])})`;
+ dateTime += ` (${this.timezoneService.formattedDatetime(timestamps[0])} - ${this.timezoneService.formattedDatetime(timestamps[1])})`;
break;
default:
dateTime = '';
@@ -152,8 +153,7 @@ export class OpBaselineLegendsComponent {
private getFormattedDate(date:string, time:string):string {
const combined = moment
- .tz(`${date}T${time}`, this.configuration.defaultTimezone())
- .tz(this.configuration.timezone());
+ .tz(`${date}T${time}`, this.timezoneService.userTimezone());
return `${combined.format(this.timezoneService.getDateFormat())} ${combined.format(this.timezoneService.getTimeFormat())}`;
}
diff --git a/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.html b/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.html
index fd419bbd80e..7eda260df6f 100644
--- a/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.html
+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.html
@@ -62,12 +62,15 @@
[alignment]="tooltipPosition"
[disabled]="false"
[light]="true">
- <span slot="trigger" class="op-baseline--time-zone">{{text.timeZone}}</span>
+ <span slot="trigger" class="op-baseline--time-zone" [textContent]="selectedOffsets[0]"></span>
<span slot="body" class="spot-body-small op-baseline--time-tooltip-body">{{ text.help_description }}</span>
</spot-tooltip>
- <span slot="description" [textContent]="text.time_description(0)"></span>
+ <span
+ *ngIf="userOffset !== selectedOffsets[0]"
+ slot="description"
+ [textContent]="text.time_description(0)"></span>
</spot-form-field>
<div
diff --git a/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.sass b/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.sass
index e7493f46c2b..ee41911317e 100644
--- a/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.sass
+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.sass
@@ -25,7 +25,7 @@
background-color: $spot-color-basic-gray-6
border: 1px solid $spot-color-basic-gray-3
border-left: none !important
- padding: $spot-spacing-0_5 $spot-spacing-1
+ padding: $spot-spacing-0_5 $spot-spacing-0_25
line-height: unset
&-zone
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 8b12120f18b..617befd61ff 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
@@ -77,6 +77,12 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
public selectedTimes:string[];
+ public selectedOffsets:string[];
+
+ public userTimezone:string;
+
+ public userOffset:string;
+
public selectedFilter:string|null;
public selectedTimezoneFormattedTime:string[];
@@ -95,18 +101,17 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
date: this.I18n.t('js.label_date'),
time: this.I18n.t('js.baseline.time'),
help_description: this.I18n.t('js.baseline.help_description'),
- timeZone: this.configuration.isDefaultTimezoneSet() ? moment().tz(this.configuration.defaultTimezone()).zoneAbbr() : 'local',
time_description: (i:number) => {
const date = this.selectedDates[i];
const time = this.selectedTimes[i];
+ const offset = this.selectedOffsets[i];
if (!date || !time) {
return '';
}
- const formatted = moment
- .tz(`${date}T${time}`, this.configuration.defaultTimezone())
- .tz(this.configuration.timezone());
+ const formatted = moment(`${date}T${time}${offset}`)
+ .tz(this.userTimezone);
const formattedDate = formatted.format(this.timezoneService.getDateFormat());
const formattedTime = formatted.format(this.timezoneService.getTimeFormat());
@@ -156,6 +161,8 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
}
public ngOnInit():void {
+ this.userTimezone = this.timezoneService.userTimezone();
+ this.userOffset = moment().tz(this.userTimezone).format('Z');
this.resetSelection();
if (this.wpTableBaseline.isActive()) {
@@ -163,13 +170,14 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
this.wpTableBaseline.current.forEach((value, i) => {
if (value.includes('@')) {
const [, timeWithZone] = value.split(/[@]/);
- const time = timeWithZone.split(/[+-]/)[0];
+ const [time, offset] = timeWithZone.split(/\s+/)[0];
this.selectedTimes[i] = time || '00:00';
+ this.selectedOffsets[i] = offset;
} else if (value !== 'PT0S') {
- const date = moment.tz(value, this.configuration.defaultTimezone());
-
+ 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');
}
});
}
@@ -180,6 +188,7 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
this.selectedDates = ['', ''];
this.selectedFilter = null;
this.mappedSelectedDate = null;
+ this.selectedOffsets = [this.userOffset, this.userOffset];
}
public onSubmit(e:Event):void {
@@ -235,7 +244,7 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
case 'oneWeekAgo':
case 'oneMonthAgo':
case 'lastWorkingDay':
- return [this.buildFilterString(0)];
+ return [this.buildFilterString(0), DEFAULT_TIMESTAMP];
case 'aSpecificDate':
return [this.buildISOString(0), DEFAULT_TIMESTAMP];
case 'betweenTwoSpecificDates':
@@ -249,12 +258,11 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
}
private buildISOString(i:number):string {
- const date = moment.tz(`${this.selectedDates[i]}T${this.selectedTimes[i]}`, this.configuration.defaultTimezone());
- return date.toISOString();
+ return `${this.selectedDates[i]}T${this.selectedTimes[i]}${this.selectedOffsets[i]}`;
}
private buildFilterString(i:number):string {
- const dateTime= `${this.selectedDates[i]} ${this.selectedTimes[i]}`;
- return `${this.selectedFilter}@${this.timezoneService.formattedTime(dateTime, 'HH:mmZ')}`;
+ const timeWithOffset = `${this.selectedTimes[i]}${this.selectedOffsets[i]}`;
+ return `${this.selectedFilter}@${timeWithOffset}`;
}
}