Skip to content

Commit 50865bf

Browse files
Merge pull request #721 from appwrite/fix-trial-date
Fixes issue where a negative number would prevent the TRIAL pill from…
2 parents 92e7f47 + 82f27c7 commit 50865bf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/lib/stores/billing.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { cachedStore } from '$lib/helpers/cache';
88
import { Query, type Models } from '@appwrite.io/console';
99
import { headerAlert } from './headerAlert';
1010
import PaymentAuthRequired from '$lib/components/billing/alerts/paymentAuthRequired.svelte';
11-
import { diffDays } from '$lib/helpers/date';
1211
import { addNotification, notifications } from './notifications';
1312
import { goto } from '$app/navigation';
1413
import { base } from '$app/paths';
@@ -161,7 +160,12 @@ export function calculateTrialDay(org: Organization) {
161160
if (org?.billingPlan === BillingPlan.STARTER) return false;
162161
const endDate = new Date(org?.billingStartDate);
163162
const today = new Date();
164-
const days = diffDays(today, endDate);
163+
164+
let diffTime = endDate.getTime() - today.getTime();
165+
diffTime = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1;
166+
167+
const days = diffTime < 1 ? 0 : diffTime;
168+
165169
daysLeftInTrial.set(days);
166170
return days;
167171
}

0 commit comments

Comments
 (0)