From bfca495d0db02e899eef4fc25c070e730c60fabf Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 3 Jan 2025 10:42:04 -0700 Subject: [PATCH 1/3] Fix datebetween formula --- packages/react-notion-x/src/third-party/eval-formula.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-notion-x/src/third-party/eval-formula.ts b/packages/react-notion-x/src/third-party/eval-formula.ts index 6658ae7f8..661e7f71a 100644 --- a/packages/react-notion-x/src/third-party/eval-formula.ts +++ b/packages/react-notion-x/src/third-party/eval-formula.ts @@ -361,26 +361,26 @@ function evalFunctionFormula( case 'dateAdd': { const date = evalFormula(args[0]!, ctx) as Date const number = evalFormula(args[1]!, ctx) as number - const unit = evalFormula(args[1]!, ctx) as string + const unit = evalFormula(args[2]!, ctx) as string return add(date, { [unit]: number }) } case 'dateBetween': { const date1 = evalFormula(args[0]!, ctx) as Date const date2 = evalFormula(args[1]!, ctx) as Date - const unit = evalFormula(args[1]!, ctx) as string + const unit = evalFormula(args[2]!, ctx) as string return ( intervalToDuration({ start: date2, end: date1 }) as any - )[unit] as number + )[unit] ?? 0 as number } case 'dateSubtract': { const date = evalFormula(args[0]!, ctx) as Date const number = evalFormula(args[1]!, ctx) as number - const unit = evalFormula(args[1]!, ctx) as string + const unit = evalFormula(args[2]!, ctx) as string return sub(date, { [unit]: number }) } From 0c5d2faf1fdd5c3e4213b59deddfc93207dd5ae3 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 12 Jan 2025 19:25:07 -0700 Subject: [PATCH 2/3] Prettier --- .../react-notion-x/src/third-party/eval-formula.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/react-notion-x/src/third-party/eval-formula.ts b/packages/react-notion-x/src/third-party/eval-formula.ts index 661e7f71a..e6ff8bce4 100644 --- a/packages/react-notion-x/src/third-party/eval-formula.ts +++ b/packages/react-notion-x/src/third-party/eval-formula.ts @@ -370,11 +370,13 @@ function evalFunctionFormula( const date2 = evalFormula(args[1]!, ctx) as Date const unit = evalFormula(args[2]!, ctx) as string return ( - intervalToDuration({ - start: date2, - end: date1 - }) as any - )[unit] ?? 0 as number + ( + intervalToDuration({ + start: date2, + end: date1 + }) as any + )[unit] ?? (0 as number) + ) } case 'dateSubtract': { From 3ade524f82c1113293f3d3dd549ee81efe690882 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 12 Jan 2025 19:53:27 -0700 Subject: [PATCH 3/3] Remove reundant type assertion --- packages/react-notion-x/src/third-party/eval-formula.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-notion-x/src/third-party/eval-formula.ts b/packages/react-notion-x/src/third-party/eval-formula.ts index e6ff8bce4..2ffee6599 100644 --- a/packages/react-notion-x/src/third-party/eval-formula.ts +++ b/packages/react-notion-x/src/third-party/eval-formula.ts @@ -375,7 +375,7 @@ function evalFunctionFormula( start: date2, end: date1 }) as any - )[unit] ?? (0 as number) + )[unit] ?? 0 ) }