mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ACS-5857] fixed code smell by creating a method
This commit is contained in:
@@ -62,9 +62,7 @@ describe('DateTimeWidgetComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
if (!minValue.includes('00.')) {
|
||||
minValue = DateFnsUtils.addSeconds(minValue);
|
||||
}
|
||||
widget.parseDateAndSetMinMaxValue(minValue, 'minDate');
|
||||
|
||||
const [year, month, day, hours, minutes, seconds] = minValue.split(/[-T:.Z]/).map(Number);
|
||||
const expected = new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds)).toISOString();
|
||||
@@ -90,9 +88,7 @@ describe('DateTimeWidgetComponent', () => {
|
||||
});
|
||||
fixture.detectChanges();
|
||||
|
||||
if (!maxValue.includes('00.')) {
|
||||
maxValue = DateFnsUtils.addSeconds(maxValue);
|
||||
}
|
||||
widget.parseDateAndSetMinMaxValue(maxValue, 'minDate');
|
||||
|
||||
const [year, month, day, hours, minutes, seconds] = maxValue.split(/[-T:.Z]/).map(Number);
|
||||
const expected = new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds)).toISOString();
|
||||
|
||||
@@ -63,33 +63,28 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit,
|
||||
|
||||
if (this.field) {
|
||||
if (this.field.minValue) {
|
||||
if (!this.field.minValue.includes('00.')) {
|
||||
this.field.minValue = DateFnsUtils.addSeconds(this.field.minValue);
|
||||
}
|
||||
|
||||
const [year, month, day, hours, minutes, seconds] = this.field.minValue.split(/[-T:.Z]/).map(Number);
|
||||
const minDate = new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds));
|
||||
|
||||
if (isValid(minDate)) {
|
||||
this.minDate = minDate.toISOString();
|
||||
}
|
||||
this.parseDateAndSetMinMaxValue(this.field.minValue, 'minDate');
|
||||
}
|
||||
|
||||
if (this.field.maxValue) {
|
||||
if (!this.field.maxValue.includes('00.')) {
|
||||
this.field.maxValue = DateFnsUtils.addSeconds(this.field.maxValue);
|
||||
}
|
||||
|
||||
const [year, month, day, hours, minutes, seconds] = this.field.maxValue.split(/[-T:.Z]/).map(Number);
|
||||
const maxDate = new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds));
|
||||
|
||||
if (isValid(maxDate)) {
|
||||
this.maxDate = maxDate.toISOString();
|
||||
}
|
||||
this.parseDateAndSetMinMaxValue(this.field.maxValue, 'maxDate');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parseDateAndSetMinMaxValue = (dateString, targetProperty) => {
|
||||
if (dateString && !dateString.includes('00.')) {
|
||||
this.field[targetProperty] = DateFnsUtils.addSeconds(dateString);
|
||||
}
|
||||
|
||||
const [year, month, day, hours, minutes, seconds] = dateString.split(/[-T:.Z]/).map(Number);
|
||||
const parsedDate = new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds));
|
||||
|
||||
if (isValid(parsedDate)) {
|
||||
this[targetProperty] = parsedDate.toISOString();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.onDestroy$.next(true);
|
||||
this.onDestroy$.complete();
|
||||
|
||||
Reference in New Issue
Block a user