diff --git a/lib/content-services/src/lib/search/components/search-datetime-range/search-datetime-range.component.spec.ts b/lib/content-services/src/lib/search/components/search-datetime-range/search-datetime-range.component.spec.ts index 544f00dac4d..5c6d70a1198 100644 --- a/lib/content-services/src/lib/search/components/search-datetime-range/search-datetime-range.component.spec.ts +++ b/lib/content-services/src/lib/search/components/search-datetime-range/search-datetime-range.component.spec.ts @@ -25,9 +25,9 @@ import { DateFnsUtils } from '@alfresco/adf-core'; describe('SearchDatetimeRangeComponent', () => { let fixture: ComponentFixture; let component: SearchDatetimeRangeComponent; - const fromDatetime = '2016-10-16 12:30'; - const toDatetime = '2017-10-16 20:00'; - const maxDatetime = '10-Mar-20 20:00'; + const fromDatetime = '2016-10-16 12:30 GMT'; + const toDatetime = '2017-10-16 20:00 GMT'; + const maxDatetime = '10-Mar-20 20:00 GMT'; const datetimeFormatFixture = 'DD-MMM-YY HH:mm'; beforeEach(() => { @@ -59,7 +59,7 @@ describe('SearchDatetimeRangeComponent', () => { await fixture.whenStable(); const inputString = '20-feb-18 20:00'; - + const dateFromInput = DateFnsUtils.parseDate(inputString, datetimeFormatFixture); expect(isValid(dateFromInput)).toBeTruthy(); @@ -76,7 +76,7 @@ describe('SearchDatetimeRangeComponent', () => { await fixture.whenStable(); const inputString = '2017-10-16 20:f:00'; - + const dateFromInput = DateFnsUtils.parseDate(inputString, datetimeFormatFixture); expect(isValid(dateFromInput)).toBeFalsy(); @@ -154,7 +154,7 @@ describe('SearchDatetimeRangeComponent', () => { to: toDatetime }, true); - const expectedQuery = `cm:created:['2016-10-16T12:30:00Z' TO '2017-10-16T20:00:59Z']`; + const expectedQuery = `cm:created:['2016-10-16T12:30:00.000Z' TO '2017-10-16T20:00:59.999Z']`; expect(context.queryFragments[component.id]).toEqual(expectedQuery); expect(context.update).toHaveBeenCalled(); @@ -182,7 +182,7 @@ describe('SearchDatetimeRangeComponent', () => { to: toInGmt }, true); - const expectedQuery = `cm:created:['2021-02-24T15:00:00Z' TO '2021-02-28T13:00:59Z']`; + const expectedQuery = `cm:created:['2021-02-24T15:00:00.000Z' TO '2021-02-28T13:00:59.999Z']`; expect(context.queryFragments[component.id]).toEqual(expectedQuery); expect(context.update).toHaveBeenCalled(); diff --git a/lib/content-services/src/lib/search/components/search-datetime-range/search-datetime-range.component.ts b/lib/content-services/src/lib/search/components/search-datetime-range/search-datetime-range.component.ts index a496fe8611e..f14e986bf7a 100644 --- a/lib/content-services/src/lib/search/components/search-datetime-range/search-datetime-range.component.ts +++ b/lib/content-services/src/lib/search/components/search-datetime-range/search-datetime-range.component.ts @@ -27,7 +27,6 @@ import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { DatetimeAdapter, MAT_DATETIME_FORMATS } from '@mat-datetimepicker/core'; import { MAT_MOMENT_DATETIME_FORMATS } from '@mat-datetimepicker/moment'; -import { DateFnsAdapter } from '@angular/material-date-fns-adapter'; import { startOfMinute, isBefore, isValid, endOfMinute } from 'date-fns'; export interface DatetimeRangeValue { @@ -65,7 +64,7 @@ export class SearchDatetimeRangeComponent implements SearchWidget, OnInit, OnDes private onDestroy$ = new Subject(); - constructor(private dateAdapter: DatetimeAdapter, private userPreferencesService: UserPreferencesService) {} + constructor(private dateAdapter: DatetimeAdapter, private userPreferencesService: UserPreferencesService) {} getFromValidationMessage(): string { return this.from.hasError('invalidOnChange') || this.hasParseError(this.from) @@ -128,12 +127,12 @@ export class SearchDatetimeRangeComponent implements SearchWidget, OnInit, OnDes this.onDestroy$.complete(); } - apply(model: { from: string; to: string }, isValid: boolean) { - if (isValid && this.id && this.context && this.settings && this.settings.field) { + apply(model: { from: string; to: string }, isFieldValid: boolean) { + if (isFieldValid && this.id && this.context && this.settings && this.settings.field) { this.isActive = true; - const start = DateFnsUtils.formatDate(startOfMinute(new Date(model.from)), `yyyy-MM-dd'T'HH:mm:ss'Z'`); - const end = DateFnsUtils.formatDate(endOfMinute(new Date(model.to)), `yyyy-MM-dd'T'HH:mm:ss'Z'`); + const start = startOfMinute(new Date(model.from)).toISOString(); + const end = endOfMinute(new Date(model.to)).toISOString(); this.context.queryFragments[this.id] = `${this.settings.field}:['${start}' TO '${end}']`; this.updateDisplayValue();