Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ describe('dateIsoFilterCondition method', () => {
expect(output).toBe(true);
});

it('should return True when input value provided is equal to the searchTerms, even when passing Date+Time in cell value, and is called by "executeMappedCondition"', () => {
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateIso, cellValue: new Date('1993-12-25T14:02:02.103Z'), searchTerms: ['1993-12-25'] } as FilterConditionOption;
const output = executeMappedCondition(options);
expect(output).toBe(true);
});

it('should return True when input value provided is equal to the searchTerms, even when passing Date+Time in search value, and is called by "executeMappedCondition"', () => {
// @ts-ignore
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateIso, cellValue: '1993-12-25', searchTerms: [new Date('1993-12-25T14:02:02.103Z')] } as FilterConditionOption;
const output = executeMappedCondition(options);
expect(output).toBe(true);
});

it('should return False when cell value is not the same value as the searchTerm', () => {
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateIso, cellValue: '1993-12-25', searchTerms: ['2003-03-14'] } as FilterConditionOption;
const output = executeMappedCondition(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function executeAssociatedDateCondition(options: FilterConditionOption): boolean
// cell value in moment format
const dateCell = moment(options.cellValue, FORMAT, true);

if (searchTerms.length === 2 || ((searchTerms[0] as string).indexOf('..') > 0)) {
if (searchTerms.length === 2 || (typeof searchTerms[0] === 'string' && (searchTerms[0] as string).indexOf('..') > 0)) {
isRangeSearch = true;
const searchValues = (searchTerms.length === 2) ? searchTerms : (searchTerms[0] as string).split('..');
const searchValue1 = (Array.isArray(searchValues) && searchValues[0] || '') as Date | string;
Expand All @@ -107,12 +107,18 @@ function executeAssociatedDateCondition(options: FilterConditionOption): boolean
dateSearch1 = moment(searchTerms[0] as Date | string, FORMAT, true);
}

// when comparing with Dates only (without time), we need to disregard the time portion, we can do so by setting our time to start at midnight
// ref, see https://stackoverflow.com/a/19699447/1212166
const dateCellTimestamp = FORMAT.toLowerCase().includes('h') ? parseInt(dateCell.format('X'), 10) : parseInt(dateCell.clone().startOf('day').format('X'), 10);

// run the filter condition with date in Unix Timestamp format
if (isRangeSearch) {
const isInclusive = options.operator && options.operator === OperatorType.rangeInclusive;
const resultCondition1 = testFilterCondition((isInclusive ? '>=' : '>'), parseInt(dateCell.format('X'), 10), parseInt(dateSearch1.format('X'), 10));
const resultCondition2 = testFilterCondition((isInclusive ? '<=' : '<'), parseInt(dateCell.format('X'), 10), parseInt(dateSearch2.format('X'), 10));
const resultCondition1 = testFilterCondition((isInclusive ? '>=' : '>'), dateCellTimestamp, parseInt(dateSearch1.format('X'), 10));
const resultCondition2 = testFilterCondition((isInclusive ? '<=' : '<'), dateCellTimestamp, parseInt(dateSearch2.format('X'), 10));
return (resultCondition1 && resultCondition2);
}
return testFilterCondition(options.operator || '==', parseInt(dateCell.format('X'), 10), parseInt(dateSearch1.format('X'), 10));

const dateSearchTimestamp1 = FORMAT.toLowerCase().includes('h') ? parseInt(dateSearch1.format('X'), 10) : parseInt(dateSearch1.clone().startOf('day').format('X'), 10);
return testFilterCondition(options.operator || '==', dateCellTimestamp, dateSearchTimestamp1);
};
1 change: 0 additions & 1 deletion test/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"baseUrl": "./",
Expand Down