From 318ee9f8010c9464792a37029b26b9ca2796dceb Mon Sep 17 00:00:00 2001
From: Matthieu Petit
Date: Fri, 26 Apr 2024 14:18:14 +0200
Subject: [PATCH] fix(members): properly check for ongoing subscription
---
lib/calc.js | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/lib/calc.js b/lib/calc.js
index 69b2191..004577c 100644
--- a/lib/calc.js
+++ b/lib/calc.js
@@ -1,4 +1,4 @@
-import {add, sub} from 'date-fns'
+import {add, isBefore, sub} from 'date-fns'
import {chain, sumBy, minBy} from 'lodash-es'
/**
@@ -13,11 +13,13 @@ export function computeSubcriptionEndDate(startDate) {
/* Legacy model functions */
export function isPresenceDuringAbo(presenceDate, abos) {
- const oneMonthBefore = getDateOneMonthBefore(presenceDate)
+ const oneMonthBefore = new Date(getDateOneMonthBefore(presenceDate))
+ const presence = new Date(presenceDate)
- return abos.some(
- abo => oneMonthBefore < abo.aboStart && abo.aboStart <= presenceDate
- )
+ return abos.some(abo => {
+ const started = new Date(abo.aboStart)
+ return isBefore(oneMonthBefore, started) && isBefore(started, presence)
+ })
}
export function computeBalance(user, memberActivity) {