gitscope
← marzneshin / v0.6.4 / dashboard/src/modules/users/domain/is-online.ts
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/modules/users/domain/is-online.ts · TypeScript
Blame Raw
 1import { UserType } from "@marzneshin/modules/users";
 2
 3/**
 4 * Checks whether the user has been online recently.
 5 * 
 6 * This function compares the provided user's last online time with the current time
 7 * to determine if the user has been online within a certain threshold.
 8 * 
 9 * @param user - The user entity containing information about the user.
10 * @returns A boolean value indicating whether the user has been online recently.
11 */
12export const isUserOnline = (user: UserType): boolean => {
13    const utcUserOnlineTime = new Date(user.online_at + 'Z');
14    const currentTime = new Date();
15    const timeDifference = Math.abs(currentTime.getTime() - utcUserOnlineTime.getTime());
16    return timeDifference < 30000;
17};