forked from buidanhhuong/can-co
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
54 lines (44 loc) · 1.34 KB
/
Copy pathutils.ts
File metadata and controls
54 lines (44 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
export function formatDistanceToNow(date: string | Date): string {
const now = new Date()
const then = new Date(date)
const diffInSeconds = Math.floor((now.getTime() - then.getTime()) / 1000)
if (diffInSeconds < 60) {
return 'Vừa xong'
}
const diffInMinutes = Math.floor(diffInSeconds / 60)
if (diffInMinutes < 60) {
return `${diffInMinutes} phút trước`
}
const diffInHours = Math.floor(diffInMinutes / 60)
if (diffInHours < 24) {
return `${diffInHours} giờ trước`
}
const diffInDays = Math.floor(diffInHours / 24)
if (diffInDays < 7) {
return `${diffInDays} ngày trước`
}
const diffInWeeks = Math.floor(diffInDays / 7)
if (diffInWeeks < 4) {
return `${diffInWeeks} tuần trước`
}
const diffInMonths = Math.floor(diffInDays / 30)
if (diffInMonths < 12) {
return `${diffInMonths} tháng trước`
}
const diffInYears = Math.floor(diffInDays / 365)
return `${diffInYears} năm trước`
}
export function formatDate(date: string | Date): string {
return new Date(date).toLocaleDateString('vi-VN', {
day: 'numeric',
month: 'long',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
})
}