Newer
Older
import { ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
// tailwindcss classnames generator from shadcn
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}

Yusuf Akgül
committed
// changes the default size of the image to be fetched
export function getImageURL(hashId: string, size: string): string {
return `${IGDB_IMG_BASE_URL}/t_${size}/${hashId}.jpg`

Yusuf Akgül
committed
}
// calculates the offset for the query
export function calculateOffset(page: number, limit: number): number {
return (page - 1) * limit
}
export function formatDate(data: number) {
const date = new Date(data)
return date.toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric'
})
}
export function formatTimeElapsed(createdAt: Date) {
const now = new Date();
const timeDiff = Math.abs(now.getTime() - new Date(createdAt).getTime()); // Difference in milliseconds
const seconds = Math.floor(timeDiff / 1000); // Convert to seconds
const minutes = Math.floor(seconds / 60); // Convert to minutes
const hours = Math.floor(minutes / 60); // Convert to hours
const days = Math.floor(hours / 24); // Convert to days
if (days > 0) {
return new Date(createdAt).toLocaleDateString(); // Show the date if days have passed
} else if (hours > 0) {
return hours + 'h'; // Show hours if hours have passed
} else if (minutes > 0) {
return minutes + 'm'; // Show minutes if minutes have passed
} else {
return seconds + 's'; // Show seconds if seconds have passed
}
}