From 8a9a9a6fdc2b1b34cde22d9421da689a0a102c73 Mon Sep 17 00:00:00 2001 From: Vito Date: Wed, 26 Jan 2022 15:24:53 +0000 Subject: [PATCH] =?UTF-8?q?[AAE-7072]=20-=20added=20utc=20time=20for=20dat?= =?UTF-8?q?e=20time=20widget=20to=20avoid=20changing=20ti=E2=80=A6=20(#746?= =?UTF-8?q?9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [AAE-7072] - added utc time for date time widget to avoid changing time on different timezones * [AAE-7072] - fixed parsing when override is not added --- .../components/widgets/core/form-field.model.spec.ts | 2 +- .../form/components/widgets/core/form-field.model.ts | 10 +++++----- .../components/widgets/date-time/date-time.widget.ts | 6 +++--- lib/core/utils/moment-date-adapter.ts | 2 +- .../components/start-task-cloud.component.html | 1 - 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/core/form/components/widgets/core/form-field.model.spec.ts b/lib/core/form/components/widgets/core/form-field.model.spec.ts index 32cac3f847..be14e2c465 100644 --- a/lib/core/form/components/widgets/core/form-field.model.spec.ts +++ b/lib/core/form/components/widgets/core/form-field.model.spec.ts @@ -305,7 +305,7 @@ describe('FormFieldModel', () => { }); const currentDateTime = moment(new Date()); - const expectedDateTime = moment(currentDateTime).format('YYYY-MM-DD HH:mm'); + const expectedDateTime = moment.utc(currentDateTime).format('YYYY-MM-DD HH:mm'); const expectedDateTimeFormat = `${currentDateTime.utc().format('YYYY-MM-DDTHH:mm:00')}.000Z`; expect(field.value).toBe(expectedDateTime); diff --git a/lib/core/form/components/widgets/core/form-field.model.ts b/lib/core/form/components/widgets/core/form-field.model.ts index f91448343c..e498e6defc 100644 --- a/lib/core/form/components/widgets/core/form-field.model.ts +++ b/lib/core/form/components/widgets/core/form-field.model.ts @@ -335,10 +335,10 @@ export class FormFieldModel extends FormWidgetModel { if (NumberFieldValidator.isNumber(value)) { dateValue = moment(value); } else { - dateValue = this.isDateTimeField(json) ? moment(value, 'YYYY-MM-DD hh:mm A') : moment(value.split('T')[0], 'YYYY-M-D'); + dateValue = this.isDateTimeField(json) ? moment.utc(value, 'YYYY-MM-DD hh:mm A') : moment.utc(value.split('T')[0], 'YYYY-M-D'); } if (dateValue && dateValue.isValid()) { - value = dateValue.format(this.dateDisplayFormat); + value = dateValue.utc().format(this.dateDisplayFormat); } } } @@ -415,13 +415,13 @@ export class FormFieldModel extends FormWidgetModel { break; case FormFieldTypes.DATETIME: if (typeof this.value === 'string' && this.value === 'now') { - this.value = moment(new Date()).format(this.dateDisplayFormat); + this.value = moment(new Date()).utc().format(this.dateDisplayFormat); } - const dateTimeValue = moment(this.value, this.dateDisplayFormat, true).utc(); + const dateTimeValue = moment.utc(this.value, this.dateDisplayFormat, true); if (dateTimeValue && dateTimeValue.isValid()) { /* cspell:disable-next-line */ - this.form.values[this.id] = `${dateTimeValue.format('YYYY-MM-DDTHH:mm:ss')}.000Z`; + this.form.values[this.id] = `${dateTimeValue.utc().format('YYYY-MM-DDTHH:mm:ss')}.000Z`; } else { this.form.values[this.id] = null; this._value = this.value; diff --git a/lib/core/form/components/widgets/date-time/date-time.widget.ts b/lib/core/form/components/widgets/date-time/date-time.widget.ts index c1ec6068f9..a3a4259519 100644 --- a/lib/core/form/components/widgets/date-time/date-time.widget.ts +++ b/lib/core/form/components/widgets/date-time/date-time.widget.ts @@ -67,11 +67,11 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit, if (this.field) { if (this.field.minValue) { - this.minDate = moment(this.field.minValue, 'YYYY-MM-DDTHH:mm:ssZ'); + this.minDate = moment.utc(this.field.minValue, 'YYYY-MM-DDTHH:mm:ssZ'); } if (this.field.maxValue) { - this.maxDate = moment(this.field.maxValue, 'YYYY-MM-DDTHH:mm:ssZ'); + this.maxDate = moment.utc(this.field.maxValue, 'YYYY-MM-DDTHH:mm:ssZ'); } } } @@ -84,7 +84,7 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit, onDateChanged(newDateValue) { const date = moment(newDateValue, this.field.dateDisplayFormat, true); if (date.isValid()) { - this.field.value = date.format(this.field.dateDisplayFormat); + this.field.value = moment(date).utc().local().format(this.field.dateDisplayFormat); } else { this.field.value = newDateValue; } diff --git a/lib/core/utils/moment-date-adapter.ts b/lib/core/utils/moment-date-adapter.ts index 7779c68c0a..9b3306610c 100644 --- a/lib/core/utils/moment-date-adapter.ts +++ b/lib/core/utils/moment-date-adapter.ts @@ -136,7 +136,7 @@ export class MomentDateAdapter extends DateAdapter { displayFormat = this.overrideDisplayFormat ? this.overrideDisplayFormat : displayFormat; if (date && date.format) { - return date.format(displayFormat); + return date.utc().local().format(displayFormat); } else { return ''; } diff --git a/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.html b/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.html index 346f384021..60e0c245c5 100644 --- a/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.html +++ b/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.html @@ -44,7 +44,6 @@