mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1const ONE_DAY = 1000 * 60 * 60 * 24
2
3export function isDaysOld(days: number, createdAt?: string) {
4 /*
5 * Should never happen because we gate NUXs to only accounts with a valid
6 * profile and a `createdAt` (see `nuxs/index.tsx`). But if it ever did, the
7 * account is either old enough to be pre-onboarding, or some failure happened
8 * during account creation. Fail closed. - esb
9 */
10 if (!createdAt) return false
11
12 const now = Date.now()
13 const then = new Date(createdAt).getTime()
14 const isOldEnough = then + ONE_DAY * days < now
15
16 if (isOldEnough) return true
17 return false
18}
19
20export function isExistingUserAsOf(date: string, createdAt?: string) {
21 /*
22 * Should never happen because we gate NUXs to only accounts with a valid
23 * profile and a `createdAt` (see `nuxs/index.tsx`). But if it ever did, the
24 * account is either old enough to be pre-onboarding, or some failure happened
25 * during account creation. Fail closed. - esb
26 */
27 if (!createdAt) return false
28
29 const threshold = Date.parse(date)
30 const then = new Date(createdAt).getTime()
31
32 return then < threshold
33}