-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelper.js
More file actions
26 lines (22 loc) · 765 Bytes
/
helper.js
File metadata and controls
26 lines (22 loc) · 765 Bytes
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
export function dateString(date) {
return `${date.getFullYear()}-${(date.getMonth() + 1)
.toString()
.padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`;
}
export function getDayIndex(date) {
const falseIndex = date.getDay();
return falseIndex == 0 ? 6 : falseIndex - 1;
}
const dayInMillis = 1000 * 60 * 60 * 24;
export function addDays(date, number) {
return new Date(date.getTime() + number * dayInMillis);
}
export function generateId(length = 20) {
const chars = "ABCDEFGHIHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let id = "";
for (let i = 0; i < length; i++) {
const rand = Math.floor(Math.random() * chars.length);
id += chars.charAt(rand);
}
return id;
}