[AAE-7072] - added utc time for date time widget to avoid changing ti… (#7469)

* [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
This commit is contained in:
Vito
2022-01-26 15:24:53 +00:00
committed by GitHub
parent 3d544beff3
commit 8a9a9a6fdc
5 changed files with 10 additions and 11 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -136,7 +136,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
displayFormat = this.overrideDisplayFormat ? this.overrideDisplayFormat : displayFormat;
if (date && date.format) {
return date.format(displayFormat);
return date.utc().local().format(displayFormat);
} else {
return '';
}