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
4 changed files with 15 additions and 12 deletions

View File

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

View File

@@ -280,7 +280,7 @@ export class MinDateTimeFieldValidator implements FormFieldValidator {
if (isBefore(fieldValueDate, min)) { if (isBefore(fieldValueDate, min)) {
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_LESS_THAN`; 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; isValid = false;
} }
return isValid; return isValid;
@@ -322,7 +322,7 @@ export class MaxDateTimeFieldValidator implements FormFieldValidator {
if (isAfter(fieldValueDate, max)) { if (isAfter(fieldValueDate, max)) {
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_GREATER_THAN`; 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; isValid = false;
} }
return isValid; return isValid;

View File

@@ -299,7 +299,7 @@ export class FormFieldModel extends FormWidgetModel {
} }
parseValue(json: any): any { 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 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(); 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)) { if (isValidDate(dateValue)) {
const datePart = DateFnsUtils.formatDate(dateValue, 'yyyy-MM-dd'); 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) {
if (this.field.minValue) { 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) { 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) { 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); const newValue = this.dateTimeAdapter.parse(input.value, this.field.dateDisplayFormat);
if (isValid(newValue)) { if (isValid(newValue)) {
this.field.value = DateFnsUtils.utcToLocal(newValue).toISOString(); this.field.value = DateFnsUtils.localToUtc(newValue).toISOString();
} else { } else {
this.field.value = input.value; this.field.value = input.value;
} }
@@ -108,7 +108,7 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit {
const input = event.targetElement as HTMLInputElement; const input = event.targetElement as HTMLInputElement;
if (newValue && isValid(newValue)) { if (newValue && isValid(newValue)) {
this.field.value = DateFnsUtils.utcToLocal(newValue).toISOString(); this.field.value = DateFnsUtils.localToUtc(newValue).toISOString();
} else { } else {
this.field.value = input.value; this.field.value = input.value;
} }