mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ACS-5857] fixed paths and minDate maxDate logic in date-time-widget
This commit is contained in:
@@ -62,9 +62,12 @@ describe('DateTimeWidgetComponent', () => {
|
|||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
minValue = DateFnsUtils.addSeconds(minValue);
|
if (!minValue.includes('00.')) {
|
||||||
|
minValue = DateFnsUtils.addSeconds(minValue);
|
||||||
|
}
|
||||||
|
|
||||||
const expected = DateFnsUtils.formatDate(new Date(minValue), 'YYYY-MM-DDTHH:mm:ssZ');
|
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();
|
||||||
expect(widget.minDate).toBe(expected);
|
expect(widget.minDate).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -87,9 +90,12 @@ describe('DateTimeWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
maxValue = DateFnsUtils.addSeconds(maxValue);
|
if (!maxValue.includes('00.')) {
|
||||||
|
maxValue = DateFnsUtils.addSeconds(maxValue);
|
||||||
|
}
|
||||||
|
|
||||||
const expected = DateFnsUtils.formatDate(new Date(maxValue), 'YYYY-MM-DDTHH:mm:ssZ');
|
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();
|
||||||
expect(widget.maxDate).toBe(expected);
|
expect(widget.maxDate).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import { WidgetComponent } from '../widget.component';
|
|||||||
import { Subject } from 'rxjs';
|
import { Subject } from 'rxjs';
|
||||||
import { takeUntil } from 'rxjs/operators';
|
import { takeUntil } from 'rxjs/operators';
|
||||||
import { DateFnsUtils } from '../../../../common';
|
import { DateFnsUtils } from '../../../../common';
|
||||||
import { TranslationService } from '../../../../../../../core/src/lib/translation';
|
import { TranslationService } from '../../../../../lib/translation/translation.service';
|
||||||
import { FormFieldModel } from '../core';
|
import { FormFieldModel } from '../core';
|
||||||
import { isValid } from 'date-fns';
|
import { isValid } from 'date-fns';
|
||||||
import { DateFnsAdapter } from '@angular/material-date-fns-adapter';
|
import { DateFnsAdapter } from '@angular/material-date-fns-adapter';
|
||||||
@@ -63,20 +63,28 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit,
|
|||||||
|
|
||||||
if (this.field) {
|
if (this.field) {
|
||||||
if (this.field.minValue) {
|
if (this.field.minValue) {
|
||||||
this.field.minValue = DateFnsUtils.addSeconds(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));
|
||||||
|
|
||||||
const minDate = new Date(this.field.minValue);
|
|
||||||
if (isValid(minDate)) {
|
if (isValid(minDate)) {
|
||||||
this.minDate = DateFnsUtils.formatDate(minDate, 'YYYY-MM-DDTHH:mm:ssZ');
|
this.minDate = minDate.toISOString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.field.maxValue) {
|
if (this.field.maxValue) {
|
||||||
this.field.maxValue = DateFnsUtils.addSeconds(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));
|
||||||
|
|
||||||
const maxDate = new Date(this.field.maxValue);
|
|
||||||
if (isValid(maxDate)) {
|
if (isValid(maxDate)) {
|
||||||
this.maxDate = DateFnsUtils.formatDate(maxDate, 'YYYY-MM-DDTHH:mm:ssZ');
|
this.maxDate = maxDate.toISOString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import { DateFnsAdapter, MAT_DATE_FNS_FORMATS } from '@angular/material-date-fns
|
|||||||
import { DateFnsUtils } from '../../../../common';
|
import { DateFnsUtils } from '../../../../common';
|
||||||
import { isValid } from 'date-fns';
|
import { isValid } from 'date-fns';
|
||||||
import { FormFieldModel } from '../core';
|
import { FormFieldModel } from '../core';
|
||||||
import { TranslationService } from '../../../../../../../core/src/lib/translation';
|
import { TranslationService } from '../../../../../lib/translation/translation.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'date-widget',
|
selector: 'date-widget',
|
||||||
|
|||||||
Reference in New Issue
Block a user