Skip to content

Commit

Permalink
fix(table-service): primefaces#15009 add unit tests and fix
Browse files Browse the repository at this point in the history
- Especially the fixing the global filter `notContains`
which is the main scope of this issue.
- Improve signature
  • Loading branch information
juri-sinitson committed Dec 20, 2024
1 parent 20daf2a commit d645a2a
Show file tree
Hide file tree
Showing 4 changed files with 1,147 additions and 80 deletions.
37 changes: 32 additions & 5 deletions packages/primeng/src/api/filterservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ export class FilterService {
return false;
}

return value.toDateString() === filter.toDateString();
const valueDate = this.getDate(value);
const filterDate = this.getDate(filter);

return valueDate.toDateString() === filterDate.toDateString();
},

dateIsNot: (value: any, filter: any): boolean => {
Expand All @@ -227,7 +230,14 @@ export class FilterService {
return false;
}

return value.toDateString() !== filter.toDateString();
const valueDate = this.getDate(value);
const filterDate = this.getDate(filter);

if (isNaN(valueDate.getDate()) || isNaN(filterDate.getDate())) {
return true;
}

return valueDate.toDateString() !== filterDate.toDateString();
},

dateBefore: (value: any, filter: any): boolean => {
Expand All @@ -239,7 +249,10 @@ export class FilterService {
return false;
}

return value.getTime() < filter.getTime();
const valueDate = this.getDate(value);
const filterDate = this.getDate(filter);

return valueDate.getTime() < filterDate.getTime();
},

dateAfter: (value: any, filter: any): boolean => {
Expand All @@ -250,13 +263,27 @@ export class FilterService {
if (value === undefined || value === null) {
return false;
}
value.setHours(0, 0, 0, 0);

return value.getTime() > filter.getTime();
const valueDate = this.getDate(value);
const filterDate = this.getDate(filter);

valueDate.setHours(0, 0, 0, 0);

return valueDate.getTime() > filterDate.getTime();
}
};

register(rule: string, fn: Function) {
this.filters[rule] = fn;
}

private getDate(value: any): Date {
if (value instanceof Date) {
return value;
} else {
// Prevent creating a date from an integer e.g. from
// an age. In this case in invalid date should be returned.
return new Date(`${value}`);
}
}
}
3 changes: 3 additions & 0 deletions packages/primeng/src/api/fitlersarg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { FilterMetadata } from './filtermetadata';

export type FiltersArg = { [key: string]: FilterMetadata | FilterMetadata[] | string };
Loading

0 comments on commit d645a2a

Please sign in to comment.