-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
33 lines (32 loc) · 1.18 KB
/
test.js
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
"use strict";
const yellow = ["#FFFFB7", "#FFF192", "#FFEA61", "#FFDD3C", "#FFD400"];
const Colours = { darkBlue: "colour" };
const dateToYMD = (date) => date.toISOString().slice(0, 10);
const increaseDate = (date) => new Date(date.setDate(date.getDate() + 1));
const createDateRange = (start, end) => {
const dateArr = [];
for (
let startCp = increaseDate(new Date(start));
startCp < end;
startCp = increaseDate(startCp)
) {
dateArr.push(new Date(startCp));
}
return dateArr;
};
const createMarkedDates = (start, end) => {
const startStr = dateToYMD(start);
const endStr = dateToYMD(end);
const selectedStr = createDateRange(start, end).map((d) => dateToYMD(d));
const markedDates = {
[startStr]: { startingDay: true, color: yellow[4], textColor: Colours.darkBlue },
};
selectedStr.forEach((dateStr) => {
markedDates[dateStr] = { selected: true, color: yellow[4], textColor: Colours.darkBlue };
});
markedDates[endStr] = { endingDay: true, color: yellow[4], textColor: Colours.darkBlue };
return markedDates;
};
let date = new Date();
let in14days = new Date(new Date(date).setDate(date.getDate() + 14));
console.log(createMarkedDates(date, in14days));