From 69ab1ce44f4e9b0320582d11524facf2c1adad24 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 13 Jun 2024 12:30:36 +0100 Subject: [PATCH] Down to 66 failures. --- packages/shared-core/src/filters.ts | 32 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index a773524ae4..43c99c8374 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -324,9 +324,11 @@ export const runQuery = ( if (docValue == null || docValue === "") { return false } + if (testValue.low == null && testValue.high == null) { return false } + if (!isNaN(+docValue)) { if (!isNaN(+testValue.low) && !isNaN(+testValue.high)) { return +docValue >= testValue.low && +docValue <= testValue.high @@ -336,18 +338,32 @@ export const runQuery = ( return +docValue <= testValue.high } } - if (dayjs(docValue).isValid()) { - if (dayjs(testValue.low).isValid() && dayjs(testValue.high).isValid()) { + + const docDate = dayjs(docValue) + if (docDate.isValid()) { + const lowDate = dayjs(testValue.low) + const highDate = dayjs(testValue.high) + if (lowDate.isValid() && highDate.isValid()) { return ( - dayjs(docValue).isAfter(testValue.low) && - dayjs(docValue).isBefore(testValue.high) + (docDate.isAfter(lowDate) && docDate.isBefore(highDate)) || + docDate.isSame(lowDate) || + docDate.isSame(highDate) ) - } else if (dayjs(testValue.low).isValid()) { - return dayjs(docValue).isAfter(testValue.low) - } else if (dayjs(testValue.high).isValid()) { - return dayjs(docValue).isBefore(testValue.high) + } else if (lowDate.isValid()) { + return docDate.isAfter(lowDate) || docDate.isSame(lowDate) + } else if (highDate.isValid()) { + return docDate.isBefore(highDate) || docDate.isSame(highDate) } } + + if (testValue.low && testValue.high) { + return docValue >= testValue.low && docValue <= testValue.high + } else if (testValue.low) { + return docValue >= testValue.low + } else if (testValue.high) { + return docValue <= testValue.high + } + return false } )