// class Calendar { // constructor() { // // } // // nextMonth() { // // } // // previousMonth() { // // } // // addEvent() { // // } // // removeEvent() { // // } // } const moment = require("moment"); const calendar = document.getElementById("calendar"); const title = document.getElementById("month"); const days = [ "Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "Lørdag", "Søndag" ]; // // const months = [ // "January", // "February", // "March", // "April", // "May", // "June", // "July", // "August", // "September", // "October", // "November", // "December", // ] // const month = document.getElementById("month"); // // const year = 2020; // // let currentMonth = 0; // // let firstDay = (new Date(year, month)).getDay(); // // function createCalendar() { // // calendar.innerHTML = ""; // // // HEADER // let header = document.createElement("div"); // header.classList.add("calendar-table__header", "calendar-table__row"); // // days.forEach((value) =>{ // let head = document.createElement("div"); // head.classList.add("calendar-table__col"); // // head.innerText = value; // // header.appendChild(head); // }); // // calendar.appendChild(header); // // // // BODY // // let date = new Date(Date.now()); // // months.forEach((value, index) => { // if(index === date.getMonth()) { // // } // }); // // // //
// //
// // 2 // //
// //
// // // let intDay = 1; // // for(let columns = 0; columns < 5; columns++) // // { // // let row = document.createElement("div"); // // row.classList.add("calendar-table__row"); // // // // for (let i = 0; i < 7; i++) // // { // // let day = document.createElement("div"); // // day.classList.add("calendar-table__col", "calendar-table__item"); // // day.innerText = intDay; // // // let // // // // row.appendChild(day); // // // // intDay++; // // } // // calendar.appendChild(row); // // } // drawMonth(6); // } // // function drawMonth(monthId) { // // // let dateObject = new Date() // // let date = 1; // for(let columns = 0; columns < 6; columns++) // { // let row = document.createElement("div"); // row.classList.add("calendar-table__row"); // // for (let i = 0; i < 7; i++) // { // if(columns === 0 && i < firstDay) { // let day = document.createElement("div"); // day.classList.add("calendar-table__col", "calendar-table__item"); // // day.innerText = date; // // row.appendChild(day); // } // else if(date > countDays(year, 6)) { // break; // } // // else { // let day = document.createElement("div"); // day.classList.add("calendar-table__col", "calendar-table__item"); // day.innerText = date; // // row.appendChild(day); // date++; // } // // // let day = document.createElement("div"); // // day.classList.add("calendar-table__col", "calendar-table__item"); // // day.innerText = date; // // // let // // // // row.appendChild(day); // // // // date++; // } // calendar.appendChild(row); // } // } // // function nextMonth() { // currentMonth++; // // if(currentMonth > 11) // currentMonth = 0; // // months.forEach((value, index) => { // if(index === currentMonth) // month.innerText = value; // }); // // drawMonth(currentMonth); // } // // function previousMonth() { // currentMonth--; // // if(currentMonth < 0) // currentMonth = 11; // // months.forEach((value, index) => { // if(index === currentMonth) // month.innerText = value; // }); // // drawMonth(currentMonth); // } // // // function countDays(year, month) { // return 32 - new Date(year, month, 32).getDate(); // } // // // Monday // // Tuesday // // Wednesday // // Thursday // // Friday // // Saturday // // Sunday // // // // mon tue wed thu fri sat sun // // // module.exports = { // createCalendar, // countDays, // nextMonth, // previousMonth, // calendar, // days, // months, // currentMonth, // month, // }; calendar.innerHTML = ""; // // cal.forEach(value => { // let elem = document.createElement("div"); // elem.innerText = value; // console.log(value); // calendar.appendChild(elem); // }); // // title.innerText = moment().format("DD/MM/YYYY"); function generateCalendar() { const startWeek = moment().startOf("month").week(); const endWeek = moment().endOf("month").week(); let cal = []; for (let week = startWeek; week < endWeek; week++) { cal.push({ week : week, days : Array(7).fill(0).map((n, i) => moment().week(week).startOf("week").clone().add(n + i, "day")) }); } } module.exports = { generateCalendar };