-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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)); |