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();
|
fixture.detectChanges();
|
||||||
|
|
||||||
if (!minValue.includes('00.')) {
|
widget.parseDateAndSetMinMaxValue(minValue, 'minDate');
|
||||||
minValue = DateFnsUtils.addSeconds(minValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
const [year, month, day, hours, minutes, seconds] = minValue.split(/[-T:.Z]/).map(Number);
|
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();
|
const expected = new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds)).toISOString();
|
||||||
@@ -90,9 +88,7 @@ describe('DateTimeWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
if (!maxValue.includes('00.')) {
|
widget.parseDateAndSetMinMaxValue(maxValue, 'minDate');
|
||||||
maxValue = DateFnsUtils.addSeconds(maxValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
const [year, month, day, hours, minutes, seconds] = maxValue.split(/[-T:.Z]/).map(Number);
|
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();
|
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) {
|
||||||
if (this.field.minValue) {
|
if (this.field.minValue) {
|
||||||
if (!this.field.minValue.includes('00.')) {
|
this.parseDateAndSetMinMaxValue(this.field.minValue, 'minDate');
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.field.maxValue) {
|
if (this.field.maxValue) {
|
||||||
if (!this.field.maxValue.includes('00.')) {
|
this.parseDateAndSetMinMaxValue(this.field.maxValue, 'maxDate');
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
ngOnDestroy() {
|
||||||
this.onDestroy$.next(true);
|
this.onDestroy$.next(true);
|
||||||
this.onDestroy$.complete();
|
this.onDestroy$.complete();
|
||||||
|
|||||||
Reference in New Issue
Block a user