Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysVuika committed Oct 9, 2023
1 parent fc14707 commit fe9300c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import { DateFnsUtils } from '@alfresco/adf-core';
describe('SearchDatetimeRangeComponent', () => {
let fixture: ComponentFixture<SearchDatetimeRangeComponent>;
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(() => {
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -65,7 +64,7 @@ export class SearchDatetimeRangeComponent implements SearchWidget, OnInit, OnDes

private onDestroy$ = new Subject<boolean>();

constructor(private dateAdapter: DatetimeAdapter<DateFnsAdapter>, private userPreferencesService: UserPreferencesService) {}
constructor(private dateAdapter: DatetimeAdapter<string>, private userPreferencesService: UserPreferencesService) {}

getFromValidationMessage(): string {
return this.from.hasError('invalidOnChange') || this.hasParseError(this.from)
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit fe9300c

Please sign in to comment.