From 66f0c2f2bdad74989731b85ed11396cbd28e4000 Mon Sep 17 00:00:00 2001 From: wess Date: Fri, 12 Jan 2024 16:16:02 -0500 Subject: [PATCH 1/5] Fixes issue where a negative number would prevent the TRIAL pill from being removed Fixes issue where time remaining was off by 2 due to flooring --- src/lib/stores/billing.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 190db12348..49aff7c889 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -161,7 +161,13 @@ export function calculateTrialDay(org: Organization) { if (org?.billingPlan === BillingPlan.STARTER) return false; const endDate = new Date(org?.billingStartDate); const today = new Date(); - const days = diffDays(today, endDate); + + let diffTime = Math.abs(endDate.getTime() - today.getTime()); + diffTime = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1; + diffTime = -9; + + let days = diffTime < 1 ? 0 : diffTime; + daysLeftInTrial.set(days); return days; } From 72b3f033b2d554956c5ba0e4e8a56de20aee5880 Mon Sep 17 00:00:00 2001 From: wess Date: Fri, 12 Jan 2024 16:29:07 -0500 Subject: [PATCH 2/5] Fixes issue where -9 was hardcoded --- src/lib/stores/billing.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 49aff7c889..0ad64d2582 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -162,9 +162,8 @@ export function calculateTrialDay(org: Organization) { const endDate = new Date(org?.billingStartDate); const today = new Date(); - let diffTime = Math.abs(endDate.getTime() - today.getTime()); + let diffTime = endDate.getTime() - today.getTime(); diffTime = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1; - diffTime = -9; let days = diffTime < 1 ? 0 : diffTime; From 5566d3a31e1a8ed780f4bf262bbb6bf5086d7fb2 Mon Sep 17 00:00:00 2001 From: wess Date: Fri, 12 Jan 2024 16:32:48 -0500 Subject: [PATCH 3/5] Removes unused import --- src/lib/stores/billing.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 0ad64d2582..d441f3b16c 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -8,7 +8,6 @@ import { cachedStore } from '$lib/helpers/cache'; import { Query, type Models } from '@appwrite.io/console'; import { headerAlert } from './headerAlert'; import PaymentAuthRequired from '$lib/components/billing/alerts/paymentAuthRequired.svelte'; -import { diffDays } from '$lib/helpers/date'; import { addNotification, notifications } from './notifications'; import { goto } from '$app/navigation'; import { base } from '$app/paths'; From 41d539369698a494c6ce99599a90f076bafec020 Mon Sep 17 00:00:00 2001 From: wess Date: Fri, 12 Jan 2024 16:35:21 -0500 Subject: [PATCH 4/5] Formatting --- src/lib/stores/billing.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index d441f3b16c..5fd8eb927a 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -160,10 +160,10 @@ export function calculateTrialDay(org: Organization) { if (org?.billingPlan === BillingPlan.STARTER) return false; const endDate = new Date(org?.billingStartDate); const today = new Date(); - + let diffTime = endDate.getTime() - today.getTime(); diffTime = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1; - + let days = diffTime < 1 ? 0 : diffTime; daysLeftInTrial.set(days); From 82f27c73d82ae9f75063a903537803ac2fd5d414 Mon Sep 17 00:00:00 2001 From: wess Date: Fri, 12 Jan 2024 16:39:58 -0500 Subject: [PATCH 5/5] Formatting --- src/lib/stores/billing.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 5fd8eb927a..a86f8c8ae3 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -164,7 +164,7 @@ export function calculateTrialDay(org: Organization) { let diffTime = endDate.getTime() - today.getTime(); diffTime = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1; - let days = diffTime < 1 ? 0 : diffTime; + const days = diffTime < 1 ? 0 : diffTime; daysLeftInTrial.set(days); return days;