Your music, beautifully tracked. All yours. (coming soon)
teal.fm
teal-fm
atproto
1import { clsx, type ClassValue } from "clsx";
2import { twMerge } from "tailwind-merge";
3
4export function cn(...inputs: ClassValue[]) {
5 return twMerge(clsx(inputs));
6}
7
8export function capFirstLetter(str: string) {
9 let arr = str.split("");
10 let first = arr.shift()?.toUpperCase();
11 return (first || "") + arr.join("");
12}
13
14export function timeAgo(date: Date) {
15 const seconds = Math.floor((new Date().getTime() - date.getTime()) / 1000);
16 let interval = Math.floor(seconds / 31536000);
17
18 // return date.toLocaleDateString("en-US");
19 if (interval > 1) {
20 const formatter = new Intl.DateTimeFormat("en-US", {
21 year: "numeric",
22 month: "short",
23 day: "numeric",
24 hour: "numeric",
25 minute: "numeric",
26 });
27 return "on " + formatter.format(date);
28 }
29 interval = Math.floor(seconds / 86400);
30 // return date without years
31 if (interval > 1) {
32 const formatter = new Intl.DateTimeFormat("en-US", {
33 month: "short",
34 day: "numeric",
35 hour: "numeric",
36 minute: "numeric",
37 });
38 return "on " + formatter.format(date);
39 }
40 interval = Math.floor(seconds / 3600);
41 if (interval > 1) {
42 return interval + " hours ago";
43 }
44 interval = Math.floor(seconds / 60);
45 if (interval > 1) {
46 return interval + " minutes ago";
47 }
48 return Math.floor(seconds) + " seconds ago";
49}