JSFiddle - React, Tailwind, and code Playground
by lemon kazi
HTML
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/moment.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment-range/4.0.1/moment-range.js"></script>
<script>
var indexOf = [].indexOf || function (item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
</script>
<script type="text/javascript">
window['moment-range'].extendMoment(moment);
var dateApril = new Date("2021-03-18");
// year and month are variables
year = 2021
month = 2 // August (0 indexed)
startDate = moment([year, month])
document.write("<br/>inputDate : "+dateApril+"<br/>")
console.log("inputDate : ", startDate.format("dddd, MMMM Do YYYY, h:mm:ss a"));
// // Get the first and last day of the month
firstDay = moment(startDate).startOf('month')
endDay = moment(startDate).endOf('month')
//console.log("firstDay : ", firstDay.format("dddd, MMMM Do YYYY, h:mm:ss a"));
//console.log("endDay : ", endDay.format("dddd, MMMM Do YYYY, h:mm:ss a"));
// // Create a range for the month we can iterate through
monthRange = moment.range(firstDay, endDay);
//console.log("monthRange : ", monthRange);
// // Get all the weeks during the current month
weeks = []
for (let mday of monthRange.by('days')) {
// console.log("mday", mday.week());
if (weeks.indexOf(mday.week()) === -1) {
weeks.push(mday.week());
}
}
//console.log("weeks : ", weeks);
// // Create a range for each week
calendar = []
for (let index = 0; index < weeks.length+1; index++) {
var weeknumber = weeks[index];
firstWeekDay = moment(firstDay).week(weeknumber).day(0);
if...