From 8378069c3f794614c298e05a2f01cc2796b93473 Mon Sep 17 00:00:00 2001 From: ThunderMiracle Date: Mon, 14 Aug 2023 15:25:35 +0900 Subject: [PATCH] fix: opposite date comparison (#114) * fix: opposite date comparison * chore: add changeset --- .changeset/orange-turkeys-bake.md | 5 +++++ __test__/filters/greater.test.ts | 4 ++-- __test__/filters/greaterOrEqual.test.ts | 10 ++++----- __test__/filters/less.test.ts | 10 ++++----- __test__/filters/lessOrEqual.test.ts | 28 ++++++++++++------------- __test__/filters/notEqual.test.ts | 16 +++++++------- src/filters/greater.ts | 2 +- 7 files changed, 40 insertions(+), 35 deletions(-) create mode 100644 .changeset/orange-turkeys-bake.md diff --git a/.changeset/orange-turkeys-bake.md b/.changeset/orange-turkeys-bake.md new file mode 100644 index 0000000..d007025 --- /dev/null +++ b/.changeset/orange-turkeys-bake.md @@ -0,0 +1,5 @@ +--- +"filter-data": patch +--- + +fix: opposite date comparison diff --git a/__test__/filters/greater.test.ts b/__test__/filters/greater.test.ts index 2353851..6c18333 100644 --- a/__test__/filters/greater.test.ts +++ b/__test__/filters/greater.test.ts @@ -178,7 +178,7 @@ describe('test searchCondition', () => { const result = greater( { key: 'birthday', - value: new Date('2015-05-15'), + value: new Date('2011-05-15'), type: SearchType.GT, }, false, @@ -192,7 +192,7 @@ describe('test searchCondition', () => { const result = greater( { key: 'birthday', - value: new Date('2011-05-15'), + value: new Date('2015-05-15'), type: SearchType.GT, }, false, diff --git a/__test__/filters/greaterOrEqual.test.ts b/__test__/filters/greaterOrEqual.test.ts index 0811027..8cfc2ed 100644 --- a/__test__/filters/greaterOrEqual.test.ts +++ b/__test__/filters/greaterOrEqual.test.ts @@ -165,7 +165,7 @@ describe('test searchCondition', () => { { key: 'birthday', value: new Date('2012-03-24'), - type: SearchType.GT, + type: SearchType.GTE, }, false, searchDataDate, @@ -178,8 +178,8 @@ describe('test searchCondition', () => { const result = greaterOrEqual( { key: 'birthday', - value: new Date('2015-05-15'), - type: SearchType.GT, + value: new Date('2011-05-15'), + type: SearchType.GTE, }, false, searchDataDate, @@ -192,8 +192,8 @@ describe('test searchCondition', () => { const result = greaterOrEqual( { key: 'birthday', - value: new Date('2011-05-15'), - type: SearchType.GT, + value: new Date('2015-05-15'), + type: SearchType.GTE, }, false, searchDataDate, diff --git a/__test__/filters/less.test.ts b/__test__/filters/less.test.ts index 363e001..2f268bc 100644 --- a/__test__/filters/less.test.ts +++ b/__test__/filters/less.test.ts @@ -151,7 +151,7 @@ describe('test searchCondition', () => { { key: 'birthday', value: new Date('2012-03-24'), - type: SearchType.GT, + type: SearchType.LT, }, false, searchDataDate, @@ -164,8 +164,8 @@ describe('test searchCondition', () => { const result = less( { key: 'birthday', - value: new Date('2015-05-15'), - type: SearchType.GT, + value: new Date('2011-05-15'), + type: SearchType.LT, }, false, searchDataDate, @@ -178,8 +178,8 @@ describe('test searchCondition', () => { const result = less( { key: 'birthday', - value: new Date('2011-05-15'), - type: SearchType.GT, + value: new Date('2015-05-15'), + type: SearchType.LT, }, false, searchDataDate, diff --git a/__test__/filters/lessOrEqual.test.ts b/__test__/filters/lessOrEqual.test.ts index d069c51..3da5566 100644 --- a/__test__/filters/lessOrEqual.test.ts +++ b/__test__/filters/lessOrEqual.test.ts @@ -23,7 +23,7 @@ describe('test caseSensitive flag', () => { { key: 'fullName', value: 'abcdEfg', - type: SearchType.LT, + type: SearchType.LTE, }, true, searchDataString, @@ -37,7 +37,7 @@ describe('test caseSensitive flag', () => { { key: 'fullName', value: 'ABcdEfg', - type: SearchType.LT, + type: SearchType.LTE, }, true, searchDataString, @@ -67,7 +67,7 @@ describe('test searchCondition', () => { { key: 'fullName', value: 'ABcdEfg', - type: SearchType.LT, + type: SearchType.LTE, }, false, searchDataString, @@ -81,7 +81,7 @@ describe('test searchCondition', () => { { key: 'fullName', value: 'ACcdEfg', - type: SearchType.LT, + type: SearchType.LTE, }, false, searchDataString, @@ -95,7 +95,7 @@ describe('test searchCondition', () => { { key: 'fullName', value: 'Abcdeff', - type: SearchType.LT, + type: SearchType.LTE, }, false, searchDataString, @@ -109,7 +109,7 @@ describe('test searchCondition', () => { { key: 'fullName', value: 'AbcdCfg', - type: SearchType.LT, + type: SearchType.LTE, }, false, searchDataArray, @@ -123,7 +123,7 @@ describe('test searchCondition', () => { { key: 'fullName', value: 34223, - type: SearchType.LT, + type: SearchType.LTE, }, false, searchDataNumber, @@ -137,7 +137,7 @@ describe('test searchCondition', () => { { key: 'fullName', value: 34023, - type: SearchType.LT, + type: SearchType.LTE, }, false, searchDataNumber, @@ -151,7 +151,7 @@ describe('test searchCondition', () => { { key: 'fullName', value: 34123, - type: SearchType.LT, + type: SearchType.LTE, }, false, searchDataNumber, @@ -165,7 +165,7 @@ describe('test searchCondition', () => { { key: 'birthday', value: new Date('2012-03-24'), - type: SearchType.GT, + type: SearchType.LTE, }, false, searchDataDate, @@ -178,8 +178,8 @@ describe('test searchCondition', () => { const result = lessOrEqual( { key: 'birthday', - value: new Date('2015-05-15'), - type: SearchType.GT, + value: new Date('2011-05-15'), + type: SearchType.LTE, }, false, searchDataDate, @@ -192,8 +192,8 @@ describe('test searchCondition', () => { const result = lessOrEqual( { key: 'birthday', - value: new Date('2011-05-15'), - type: SearchType.GT, + value: new Date('2015-05-15'), + type: SearchType.LTE, }, false, searchDataDate, diff --git a/__test__/filters/notEqual.test.ts b/__test__/filters/notEqual.test.ts index 490ae61..4630d58 100644 --- a/__test__/filters/notEqual.test.ts +++ b/__test__/filters/notEqual.test.ts @@ -209,7 +209,7 @@ describe('test searchCondition', () => { { key: 'married', value: true, - type: SearchType.EQ, + type: SearchType.NE, }, false, searchDataBoolean, @@ -223,7 +223,7 @@ describe('test searchCondition', () => { { key: 'married', value: true, - type: SearchType.EQ, + type: SearchType.NE, }, false, searchDataArrayBoolean, @@ -237,7 +237,7 @@ describe('test searchCondition', () => { { key: 'married', value: false, - type: SearchType.EQ, + type: SearchType.NE, }, false, searchDataBoolean, @@ -251,7 +251,7 @@ describe('test searchCondition', () => { { key: 'married', value: false, - type: SearchType.EQ, + type: SearchType.NE, }, false, searchDataArrayBoolean, @@ -265,7 +265,7 @@ describe('test searchCondition', () => { { key: 'registered', value: new Date('2023-08-14T10:00:00.000Z'), - type: SearchType.EQ, + type: SearchType.NE, }, false, searchDataDate, @@ -279,7 +279,7 @@ describe('test searchCondition', () => { { key: 'registered', value: new Date('2023-08-15T21:00:00.000Z'), - type: SearchType.EQ, + type: SearchType.NE, }, false, searchDataArrayDate, @@ -293,7 +293,7 @@ describe('test searchCondition', () => { { key: 'registered', value: new Date('2023-08-14T09:00:00.000Z'), - type: SearchType.EQ, + type: SearchType.NE, }, false, searchDataDate, @@ -307,7 +307,7 @@ describe('test searchCondition', () => { { key: 'registered', value: new Date('2023-08-15T10:00:00.000Z'), - type: SearchType.EQ, + type: SearchType.NE, }, false, searchDataArrayDate, diff --git a/src/filters/greater.ts b/src/filters/greater.ts index 730fe75..4afd00c 100644 --- a/src/filters/greater.ts +++ b/src/filters/greater.ts @@ -27,7 +27,7 @@ const greater: FilterFunction = ({ key, value }, caseSensitive, data) => { // value is date if (value instanceof Date) { - return timeDiff(value, targetValue) > 0; + return timeDiff(value, targetValue) < 0; } if (caseSensitive) {