-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.ts
42 lines (34 loc) · 1.13 KB
/
lib.ts
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
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context"
export function headToURL(URL: string, CurrentURL: string, setValue: React.Dispatch<React.SetStateAction<string[]>>, router: AppRouterInstance) {
if (CurrentURL === URL)
return
setValue(p => {
if (p[p.length - 1] !== URL)
return [...p, URL]
else
return [...p]
})
router.push(URL)
}
export function formatTime(time: number) {
const minutes = Math.floor(time / 60)
const seconds = Math.floor(time % 60)
if (isNaN(minutes) || isNaN(seconds))
return "00:00"
return (minutes < 10 ? "0" : "") + minutes + ":" + (seconds < 10 ? "0" : "") + seconds
}
export function formatDuration(time: number) {
const minutes = Math.floor(time / 60)
const seconds = Math.floor(time % 60)
return `${minutes > 0 ? minutes + " min" : ""} ${seconds} sec`
}
export function getGreeting() {
const currentDate = new Date()
const currentHour = currentDate.getHours()
if (currentHour >= 5 && currentHour < 12)
return "Good morning"
else if (currentHour >= 12 && currentHour < 18)
return "Good afternoon"
else
return "Good evening"
}