Skip to content

Commit

Permalink
fix: opposite date comparison (#114)
Browse files Browse the repository at this point in the history
* fix: opposite date comparison

* chore: add changeset
  • Loading branch information
thundermiracle authored Aug 14, 2023
1 parent dd0f5dd commit 8378069
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-turkeys-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"filter-data": patch
---

fix: opposite date comparison
4 changes: 2 additions & 2 deletions __test__/filters/greater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions __test__/filters/greaterOrEqual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe('test searchCondition', () => {
{
key: 'birthday',
value: new Date('2012-03-24'),
type: SearchType.GT,
type: SearchType.GTE,
},
false,
searchDataDate,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions __test__/filters/less.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe('test searchCondition', () => {
{
key: 'birthday',
value: new Date('2012-03-24'),
type: SearchType.GT,
type: SearchType.LT,
},
false,
searchDataDate,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
28 changes: 14 additions & 14 deletions __test__/filters/lessOrEqual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('test caseSensitive flag', () => {
{
key: 'fullName',
value: 'abcdEfg',
type: SearchType.LT,
type: SearchType.LTE,
},
true,
searchDataString,
Expand All @@ -37,7 +37,7 @@ describe('test caseSensitive flag', () => {
{
key: 'fullName',
value: 'ABcdEfg',
type: SearchType.LT,
type: SearchType.LTE,
},
true,
searchDataString,
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('test searchCondition', () => {
{
key: 'fullName',
value: 'ABcdEfg',
type: SearchType.LT,
type: SearchType.LTE,
},
false,
searchDataString,
Expand All @@ -81,7 +81,7 @@ describe('test searchCondition', () => {
{
key: 'fullName',
value: 'ACcdEfg',
type: SearchType.LT,
type: SearchType.LTE,
},
false,
searchDataString,
Expand All @@ -95,7 +95,7 @@ describe('test searchCondition', () => {
{
key: 'fullName',
value: 'Abcdeff',
type: SearchType.LT,
type: SearchType.LTE,
},
false,
searchDataString,
Expand All @@ -109,7 +109,7 @@ describe('test searchCondition', () => {
{
key: 'fullName',
value: 'AbcdCfg',
type: SearchType.LT,
type: SearchType.LTE,
},
false,
searchDataArray,
Expand All @@ -123,7 +123,7 @@ describe('test searchCondition', () => {
{
key: 'fullName',
value: 34223,
type: SearchType.LT,
type: SearchType.LTE,
},
false,
searchDataNumber,
Expand All @@ -137,7 +137,7 @@ describe('test searchCondition', () => {
{
key: 'fullName',
value: 34023,
type: SearchType.LT,
type: SearchType.LTE,
},
false,
searchDataNumber,
Expand All @@ -151,7 +151,7 @@ describe('test searchCondition', () => {
{
key: 'fullName',
value: 34123,
type: SearchType.LT,
type: SearchType.LTE,
},
false,
searchDataNumber,
Expand All @@ -165,7 +165,7 @@ describe('test searchCondition', () => {
{
key: 'birthday',
value: new Date('2012-03-24'),
type: SearchType.GT,
type: SearchType.LTE,
},
false,
searchDataDate,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions __test__/filters/notEqual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe('test searchCondition', () => {
{
key: 'married',
value: true,
type: SearchType.EQ,
type: SearchType.NE,
},
false,
searchDataBoolean,
Expand All @@ -223,7 +223,7 @@ describe('test searchCondition', () => {
{
key: 'married',
value: true,
type: SearchType.EQ,
type: SearchType.NE,
},
false,
searchDataArrayBoolean,
Expand All @@ -237,7 +237,7 @@ describe('test searchCondition', () => {
{
key: 'married',
value: false,
type: SearchType.EQ,
type: SearchType.NE,
},
false,
searchDataBoolean,
Expand All @@ -251,7 +251,7 @@ describe('test searchCondition', () => {
{
key: 'married',
value: false,
type: SearchType.EQ,
type: SearchType.NE,
},
false,
searchDataArrayBoolean,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/filters/greater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8378069

Please sign in to comment.