-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
51 lines (45 loc) · 1.27 KB
/
utils.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
43
44
45
46
47
48
49
50
51
export const toISOStringWithOffset = (date: Date): string => {
if (!date) return
const timezoneOffset = date.getTimezoneOffset() * 60000 // offset in milliseconds
const adjustedDate = new Date(date.getTime() - timezoneOffset)
return adjustedDate.toISOString()
}
export const formattedDate = (date: Date | string): string => {
if (typeof date === 'string') {
date = new Date(date)
}
return date.toLocaleDateString('fr-FR', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
})
}
export const formattedDateWithoutTime = (date: Date | string): string => {
if (typeof date === 'string') {
date = new Date(date)
}
return date.toLocaleDateString('fr-FR', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
})
}
export const formattedTime = (date: Date | string): string => {
if (typeof date === 'string') {
date = new Date(date)
}
return date.toLocaleTimeString('fr-FR', {
hour: '2-digit',
minute: '2-digit',
})
}
export const msToTime = (duration: number): string => {
const minutes = Math.floor((duration / (1000 * 60)) % 60)
const hours = Math.floor((duration / (1000 * 60 * 60)) % 24)
if (hours === 0) {
return `${minutes}m`
}
return `${hours}h ${minutes}m`
}