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

Replace rendering with formatted dates in local timezone

Oliver Güntherc4d38b2564f7
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index bfb164cdd53..84985b3abb5 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -1351,7 +1351,7 @@ en:
header_description: 'View changes made to work packages in the current view within a time period.'
show_changes_since: 'Show changes since'
help_description: 'Default time zone of the instance set by the administrator.'
- time_description: 'In your time zone: %{time} %{days} day(s).'
+ time_description: 'In your local time: %{datetime}'
time: 'Time'
from: 'From'
to: 'To'
diff --git a/frontend/src/app/core/days/weekday.service.ts b/frontend/src/app/core/days/weekday.service.ts
index d0bb0997cb7..b3dce36a1a6 100644
--- a/frontend/src/app/core/days/weekday.service.ts
+++ b/frontend/src/app/core/days/weekday.service.ts
@@ -42,6 +42,7 @@ import {
Observable,
of,
} from 'rxjs';
+import {Moment} from 'moment';
@Injectable({ providedIn: 'root' })
export class WeekdayService {
@@ -57,7 +58,7 @@ export class WeekdayService {
* @param date The iso day number (1-7) or a date instance
* @return {boolean} whether the given iso day is working or not
*/
- public isNonWorkingDay(date:Date|number):boolean {
+ public isNonWorkingDay(date:Moment|Date|number):boolean {
const isoDayOfWeek = (typeof date === 'number') ? date : moment(date).isoWeekday();
return !!(this.weekdays || []).find((wd) => wd.day === isoDayOfWeek && !wd.working);
}
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 d2839494d58..a4c2b56b1f0 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
@@ -42,6 +42,9 @@ import { IWorkPackageTimestamp } from 'core-app/features/hal/resources/work-pack
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 } 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';
+import { ConfigurationService } from 'core-app/core/config/configuration.service';
@Component({
templateUrl: './baseline-legends.component.html',
@@ -72,6 +75,8 @@ export class OpBaselineLegendsComponent {
readonly querySpace:IsolatedQuerySpace,
readonly schemaCache:SchemaCacheService,
readonly wpTableColumns:WorkPackageViewColumnsService,
+ readonly timezoneService:TimezoneService,
+ readonly configuration:ConfigurationService,
readonly cdRef:ChangeDetectorRef,
) {
this.getBaselineDetails();
@@ -82,33 +87,32 @@ export class OpBaselineLegendsComponent {
const timestamps = this.wpTableBaseline.current.map((el) => el.split(/[@T]/));
const filter = baselineFilterFromValue(this.wpTableBaseline.current);
const changesSince = this.I18n.t('js.baseline.legends.changes_since');
- const time = timestamps[0][1].split(/[+-]/)[0];
let dateTime = '';
switch (filter) {
case 'oneDayAgo':
dateTime = this.I18n.t('js.baseline.drop_down.yesterday');
- dateTime += ` (${this.wpTableBaseline.yesterdayDate()[0]}, ${timestamps[0][1]})`;
+ dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.yesterdayDate(), timestamps[0][1])})`;
break;
case 'lastWorkingDay':
dateTime = this.I18n.t('js.baseline.drop_down.last_working_day');
- dateTime += ` (${this.wpTableBaseline.lastWorkingDate()[0]}, ${timestamps[0][1]})`;
+ dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.lastWorkingDate(), timestamps[0][1])})`;
break;
case 'oneWeekAgo':
dateTime = this.I18n.t('js.baseline.drop_down.last_week');
- dateTime += ` (${this.wpTableBaseline.lastweekDate()[0]}, ${timestamps[0][1]})`;
+ dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.lastweekDate(), timestamps[0][1])})`;
break;
case 'oneMonthAgo':
dateTime = this.I18n.t('js.baseline.drop_down.last_month');
- dateTime += ` (${this.wpTableBaseline.lastMonthDate()[0]}, ${timestamps[0][1]})`;
+ dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.lastMonthDate(), timestamps[0][1])})`;
break;
case 'aSpecificDate':
dateTime = this.I18n.t('js.baseline.drop_down.a_specific_date');
- dateTime += ` (${timestamps[0].join(', ')})`;
+ dateTime += ` (${this.getFormattedDate(timestamps[0][0], timestamps[0][1])})`;
break;
case 'betweenTwoSpecificDates':
dateTime = this.I18n.t('js.baseline.drop_down.between_two_specific_dates');
- dateTime += ` (${timestamps[0].join(', ')} - ${timestamps[1].join(', ')})`;
+ dateTime += ` (${this.getFormattedDate(timestamps[0][0], timestamps[0][1])} - ${this.getFormattedDate(timestamps[1][0], timestamps[1][1])})`;
break;
default:
dateTime = '';
@@ -132,11 +136,11 @@ export class OpBaselineLegendsComponent {
const base = timestamps[0];
const compare = timestamps[1];
if ((!base._meta.exists && compare._meta.exists) || (!base._meta.matchesFilters && compare._meta.matchesFilters)) {
- this.numAdded+=1;
+ this.numAdded += 1;
} else if ((base._meta.exists && !compare._meta.exists) || (base._meta.matchesFilters && !compare._meta.matchesFilters)) {
- this.numRemoved+=1;
+ this.numRemoved += 1;
} else if (this.visibleAttributeChanged(base, schema)) {
- this.numUpdated+=1;
+ this.numUpdated += 1;
}
}
});
@@ -146,6 +150,14 @@ export class OpBaselineLegendsComponent {
}
}
+ private getFormattedDate(date:string, time:string):string {
+ const combined = moment
+ .tz(`${date}T${time}`, this.configuration.defaultTimezone())
+ .tz(this.configuration.timezone());
+
+ return `${combined.format(this.timezoneService.getDateFormat())} ${combined.format(this.timezoneService.getTimeFormat())}`;
+ }
+
private visibleAttributeChanged(base:IWorkPackageTimestamp, schema:ISchemaProxy):boolean {
return !!this
.wpTableColumns
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 72f4a735f81..c5bcedf4a8d 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
@@ -26,7 +26,7 @@
</select>
</div>
- <span slot="description"> {{ dropDownDescription }} </span>
+ <span slot="description"> {{ mappedSelectedDate }} </span>
</spot-form-field>
<spot-form-field
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 f684f694228..449d9dd0418 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
@@ -69,7 +69,7 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
@Input() visible = true;
- public dropDownDescription = '';
+ public mappedSelectedDate:string|null;
public nonWorkingDays$:Observable<IDay[]> = this.wpTableBaseline.nonWorkingDays$;
@@ -81,8 +81,6 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
public selectedTimezoneFormattedTime:string[];
- public daysNumber = 0;
-
public tooltipPosition = SpotDropAlignmentOption.TopRight;
public text = {
@@ -98,10 +96,24 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
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) => this.I18n.t('js.baseline.time_description', {
- time: this.selectedTimezoneFormattedTime[i],
- days: this.daysNumber,
- }),
+ time_description: (i:number) => {
+ const date = this.selectedDates[i];
+ const time = this.selectedTimes[i];
+
+ if (!date || !time) {
+ return '';
+ }
+
+ const formatted = moment
+ .tz(`${date}T${time}`, this.configuration.defaultTimezone())
+ .tz(this.configuration.timezone());
+
+ const formattedDate = formatted.format(this.timezoneService.getDateFormat());
+ const formattedTime = formatted.format(this.timezoneService.getTimeFormat());
+ return this.I18n.t('js.baseline.time_description', {
+ datetime: `${formattedDate} ${formattedTime}`,
+ });
+ },
};
public baselineAvailableValues = [
@@ -172,7 +184,7 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
this.selectedTimezoneFormattedTime = this.selectedTimes.map((time) => `${time}+00:00`);
this.selectedDates = ['', ''];
this.selectedFilter = null;
- this.dropDownDescription = '';
+ this.mappedSelectedDate = null;
}
public onSubmit(e:Event):void {
@@ -204,20 +216,19 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
this.selectedFilter = value;
switch (value) {
case 'oneDayAgo':
- [this.dropDownDescription, this.daysNumber] = this.wpTableBaseline.yesterdayDate();
+ this.mappedSelectedDate = this.timezoneService.formattedDate(this.wpTableBaseline.yesterdayDate());
break;
case 'lastWorkingDay':
- [this.dropDownDescription, this.daysNumber] = this.wpTableBaseline.lastWorkingDate();
+ this.mappedSelectedDate = this.timezoneService.formattedDate(this.wpTableBaseline.lastWorkingDate());
break;
case 'oneWeekAgo':
- [this.dropDownDescription, this.daysNumber] = this.wpTableBaseline.lastweekDate();
+ this.mappedSelectedDate = this.timezoneService.formattedDate(this.wpTableBaseline.lastweekDate());
break;
case 'oneMonthAgo':
- [this.dropDownDescription, this.daysNumber] = this.wpTableBaseline.lastMonthDate();
+ this.mappedSelectedDate = this.timezoneService.formattedDate(this.wpTableBaseline.lastMonthDate());
break;
default:
- this.dropDownDescription = '';
- this.daysNumber = 0;
+ this.mappedSelectedDate = null;
break;
}
}
diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service.ts
index 1d0160333af..c2756f95e50 100644
--- a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service.ts
+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service.ts
@@ -41,6 +41,7 @@ import { DayResourceService } from 'core-app/core/state/days/day.service';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import { IWorkPackageTimestamp } from 'core-app/features/hal/resources/work-package-timestamp-resource';
import * as moment from 'moment-timezone';
+import { Moment } from 'moment';
export const DEFAULT_TIMESTAMP = 'PT0S';
@@ -62,33 +63,16 @@ export class WorkPackageViewBaselineService extends WorkPackageQueryStateService
public nonWorkingDays$:Observable<IDay[]> = this.requireNonWorkingDaysOfTwoYears();
- public yesterdayDate():[string, number] {
- const today = new Date();
- const daysNumber = -1;
-
- today.setDate(today.getDate() - 1);
- const selectedDate = this.timezoneService.formattedDate(today.toString());
- return [selectedDate, daysNumber];
+ public yesterdayDate():string {
+ return moment().subtract(1, 'days').format('YYYY-MM-DD');
}
- public lastMonthDate():[string, number] {
- const today = new Date();
- const lastMonthDate = new Date(today);
-
- lastMonthDate.setMonth(today.getMonth() - 1);
- const selectedDate = this.timezoneService.formattedDate(lastMonthDate.toString());
- const daysNumber = moment(lastMonthDate).diff(moment(today), 'days');
-
- return [selectedDate, daysNumber];
+ public lastMonthDate():string {
+ return moment().subtract(1, 'month').format('YYYY-MM-DD');
}
- public lastweekDate():[string, number] {
- const today = new Date();
- const daysNumber = -7;
- today.setDate(today.getDate() - 7);
- const selectedDate = this.timezoneService.formattedDate(today.toString());
-
- return [selectedDate, daysNumber];
+ public lastweekDate():string {
+ return moment().subtract(1, 'week').format('YYYY-MM-DD');
}
requireNonWorkingDaysOfTwoYears() {
@@ -106,29 +90,22 @@ export class WorkPackageViewBaselineService extends WorkPackageQueryStateService
return nonWorkingDays$;
}
- isNonWorkingDay(date:Date|string):boolean {
+ isNonWorkingDay(date:Moment|string):boolean {
const formatted = moment(date).format('YYYY-MM-DD');
return (this.nonWorkingDays.findIndex((el) => el.date === formatted) !== -1);
}
- public lastWorkingDate():[string, number] {
- const today = new Date();
- const yesterday = new Date(today);
-
- let selectedDate = '';
- let daysNumber = 0;
- yesterday.setDate(today.getDate() - 1);
- while (selectedDate === '') {
- if (this.isNonWorkingDay(yesterday) || this.weekdaysService.isNonWorkingDay(yesterday)) {
- yesterday.setDate(yesterday.getDate() - 1);
+ public lastWorkingDate():string {
+ const date = moment();
+
+ // eslint-disable-next-line no-constant-condition
+ while (true) {
+ if (this.isNonWorkingDay(date) || this.weekdaysService.isNonWorkingDay(date)) {
+ date.subtract(1, 'days');
} else {
- selectedDate = this.timezoneService.formattedDate(yesterday.toString());
- daysNumber = moment(yesterday).diff(moment(today), 'days');
- break;
+ return date.format('YYYY-MM-DD');
}
}
-
- return [selectedDate, daysNumber];
}
public isActive():boolean {