AAE-23520 Fix date parse with invalid display format (#9891)

* AAE-23520 Fix date parse with invalid display format

* [ci:force]
This commit is contained in:
Pablo Martinez 2024-07-01 16:10:06 +02:00 committed by GitHub
parent 8009d31829
commit bb8db9838b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 12 deletions

View File

@ -33,11 +33,9 @@ export class ErrorMessageModel {
getAttributesAsJsonObj() {
let result = {};
if (this.attributes.size > 0) {
const obj = Object.create(null);
this.attributes.forEach((value, key) => {
obj[key] = value;
result[key] = typeof value === 'string' ? value : JSON.stringify(value);
});
result = JSON.stringify(obj);
}
return result;
}

View File

@ -280,7 +280,7 @@ export class MinDateTimeFieldValidator implements FormFieldValidator {
if (isBefore(fieldValueDate, min)) {
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_LESS_THAN`;
field.validationSummary.attributes.set('minValue', DateFnsUtils.formatDate(min, field.dateDisplayFormat).replace(':', '-'));
field.validationSummary.attributes.set('minValue', DateFnsUtils.formatDate(DateFnsUtils.utcToLocal(min), field.dateDisplayFormat));
isValid = false;
}
return isValid;
@ -322,7 +322,7 @@ export class MaxDateTimeFieldValidator implements FormFieldValidator {
if (isAfter(fieldValueDate, max)) {
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_GREATER_THAN`;
field.validationSummary.attributes.set('maxValue', DateFnsUtils.formatDate(max, field.dateDisplayFormat).replace(':', '-'));
field.validationSummary.attributes.set('maxValue', DateFnsUtils.formatDate(DateFnsUtils.utcToLocal(max), field.dateDisplayFormat));
isValid = false;
}
return isValid;

View File

@ -299,7 +299,7 @@ export class FormFieldModel extends FormWidgetModel {
}
parseValue(json: any): any {
let value = Object.prototype.hasOwnProperty.call(json, 'value') && json.value !== undefined ? json.value : null;
const value = Object.prototype.hasOwnProperty.call(json, 'value') && json.value !== undefined ? json.value : null;
/*
This is needed due to Activiti issue related to reading dropdown values as value string
@ -440,7 +440,12 @@ export class FormFieldModel extends FormWidgetModel {
this.value = new Date();
}
const dateValue = DateFnsUtils.parseDate(this.value, this.dateDisplayFormat);
let dateValue;
try {
dateValue = DateFnsUtils.parseDate(this.value, this.dateDisplayFormat);
} catch (e) {
dateValue = new Date('error');
}
if (isValidDate(dateValue)) {
const datePart = DateFnsUtils.formatDate(dateValue, 'yyyy-MM-dd');

View File

@ -77,15 +77,15 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit {
if (this.field) {
if (this.field.minValue) {
this.minDate = DateFnsUtils.localToUtc(new Date(this.field.minValue));
this.minDate = DateFnsUtils.utcToLocal(new Date(this.field.minValue));
}
if (this.field.maxValue) {
this.maxDate = DateFnsUtils.localToUtc(new Date(this.field.maxValue));
this.maxDate = DateFnsUtils.utcToLocal(new Date(this.field.maxValue));
}
if (this.field.value) {
this.value = DateFnsUtils.localToUtc(new Date(this.field.value));
this.value = new Date(this.field.value);
}
}
}
@ -95,7 +95,7 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit {
const newValue = this.dateTimeAdapter.parse(input.value, this.field.dateDisplayFormat);
if (isValid(newValue)) {
this.field.value = DateFnsUtils.utcToLocal(newValue).toISOString();
this.field.value = DateFnsUtils.localToUtc(newValue).toISOString();
} else {
this.field.value = input.value;
}
@ -108,7 +108,7 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit {
const input = event.targetElement as HTMLInputElement;
if (newValue && isValid(newValue)) {
this.field.value = DateFnsUtils.utcToLocal(newValue).toISOString();
this.field.value = DateFnsUtils.localToUtc(newValue).toISOString();
} else {
this.field.value = input.value;
}