var validdates = [ { "Date": "2024-04-24", "Month": 4, "Day": 24, "ProductCount": "3件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240424/comiket_deadline_to:20240424" }, { "Date": "2024-04-26", "Month": 4, "Day": 26, "ProductCount": "2件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240426/comiket_deadline_to:20240426" }, { "Date": "2024-05-02", "Month": 5, "Day": 2, "ProductCount": "5件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240502/comiket_deadline_to:20240502" }, { "Date": "2024-05-10", "Month": 5, "Day": 10, "ProductCount": "12件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240510/comiket_deadline_to:20240510" }, { "Date": "2024-05-13", "Month": 5, "Day": 13, "ProductCount": "10件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240513/comiket_deadline_to:20240513" }, { "Date": "2024-05-17", "Month": 5, "Day": 17, "ProductCount": "4件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240517/comiket_deadline_to:20240517" }, { "Date": "2024-05-20", "Month": 5, "Day": 20, "ProductCount": "11件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240520/comiket_deadline_to:20240520" }, { "Date": "2024-05-22", "Month": 5, "Day": 22, "ProductCount": "2件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240522/comiket_deadline_to:20240522" }, { "Date": "2024-05-24", "Month": 5, "Day": 24, "ProductCount": "16件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240524/comiket_deadline_to:20240524" }, { "Date": "2024-05-27", "Month": 5, "Day": 27, "ProductCount": "51件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240527/comiket_deadline_to:20240527" }, { "Date": "2024-05-28", "Month": 5, "Day": 28, "ProductCount": "1件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240528/comiket_deadline_to:20240528" }, { "Date": "2024-05-29", "Month": 5, "Day": 29, "ProductCount": "5件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240529/comiket_deadline_to:20240529" }, { "Date": "2024-05-30", "Month": 5, "Day": 30, "ProductCount": "16件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240530/comiket_deadline_to:20240530" }, { "Date": "2024-05-31", "Month": 5, "Day": 31, "ProductCount": "23件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240531/comiket_deadline_to:20240531" }, { "Date": "2024-06-03", "Month": 6, "Day": 3, "ProductCount": "188件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240603/comiket_deadline_to:20240603" }, { "Date": "2024-06-04", "Month": 6, "Day": 4, "ProductCount": "49件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240604/comiket_deadline_to:20240604" }, { "Date": "2024-06-05", "Month": 6, "Day": 5, "ProductCount": "16件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240605/comiket_deadline_to:20240605" }, { "Date": "2024-06-06", "Month": 6, "Day": 6, "ProductCount": "12件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240606/comiket_deadline_to:20240606" }, { "Date": "2024-06-07", "Month": 6, "Day": 7, "ProductCount": "16件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240607/comiket_deadline_to:20240607" }, { "Date": "2024-06-10", "Month": 6, "Day": 10, "ProductCount": "31件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240610/comiket_deadline_to:20240610" }, { "Date": "2024-06-11", "Month": 6, "Day": 11, "ProductCount": "78件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240611/comiket_deadline_to:20240611" }, { "Date": "2024-06-12", "Month": 6, "Day": 12, "ProductCount": "10件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240612/comiket_deadline_to:20240612" }, { "Date": "2024-06-13", "Month": 6, "Day": 13, "ProductCount": "3件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240613/comiket_deadline_to:20240613" }, { "Date": "2024-06-17", "Month": 6, "Day": 17, "ProductCount": "15件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240617/comiket_deadline_to:20240617" }, { "Date": "2024-06-18", "Month": 6, "Day": 18, "ProductCount": "14件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240618/comiket_deadline_to:20240618" } ] $(document).ready(function () { var event1 = "Sun Jun 30 2024"; var event2 = "Sun Jun 30 2024"; var eventname1 = "JUNE BRIDE FES 2024"; var eventname2 = "JUNE BRIDE FES 2024"; function createMonth(month, year) { var monthElement = document.createElement("div"); monthElement.className = "dp-month"; monthElement.innerHTML = "

" + year + "年" + getMonthName(month) + "

"; // Add row for day names var dayNamesRow = document.createElement("div"); dayNamesRow.className = "dp-day-names"; var dayNames = ["日", "月", "火", "水", "木", "金", "土"]; for (var i = 0; i < 7; i++) { var dayNameElement = document.createElement("div"); dayNameElement.className = "dp-day-name"; dayNameElement.textContent = dayNames[i]; dayNamesRow.appendChild(dayNameElement); } monthElement.appendChild(dayNamesRow); var daysInMonth = getDaysInMonth(month, year); var firstDay = new Date(year, month, 1).getDay(); for (var i = 0; i < firstDay; i++) { monthElement.innerHTML += "
"; } for (var i = 1; i <= daysInMonth; i++) { var dayElement = document.createElement("div"); dayElement.className = "dp-day"; dayElement.setAttribute("data-date", new Date(year, month, i).toDateString()); // Check Saturday or Sunday if (new Date(year, month, i).getDay() === 6 || new Date(year, month, i).getDay() === 0) { dayElement.classList.add("dp-wknd"); } var dateValue = dayElement.getAttribute("data-date"); // Set event day if (dateValue === event1 || dateValue === event2) { // if (dateValue === event1) { dayElement.classList.remove("dp-wknd"); dayElement.classList.add("dp-event"); // Set the event name based on the matching date if (dateValue === event1) { dayElement.title = eventname1; } else { dayElement.title = eventname2; } } var holidays = ["Wed Jan 01 2025", "Mon Apr 29 2024", "Fri May 03 2024", "Mon May 06 2024"]; if (holidays.includes(dayElement.getAttribute("data-date"))) { dayElement.classList.add("dp-wknd"); } var currentDate = dayElement.getAttribute("data-date"); var matchingDate = validdates.find(function (item) { return item.Month - 1 === new Date(currentDate).getMonth() && item.Day === new Date(currentDate).getDate(); }); validdates.forEach(function(item, index) { var productDate = item.Date; var productDateObj = new Date(productDate); // Convert productDate string to a Date object if (isNaN(productDateObj.getTime())) { console.error("Invalid date format: " + productDate); return; } var today = new Date(); var todayDate = new Date(today.getFullYear(), today.getMonth(), today.getDate()); var isDateValid = productDateObj > todayDate; // console.log("Is date valid for item " + index + ": " + isDateValid); if (isDateValid) { var element = document.querySelector(".dp-day.highlight:nth-child(" + (index + 1) + ")"); if (element) { element.style.opacity = 0.4; } } }); // console.log("matchingDate: " + matchingDate); if (matchingDate) { dayElement.classList.add("highlight"); var linkElement = document.createElement("a"); linkElement.href = matchingDate.URL; linkElement.textContent = i; dayElement.innerHTML = ""; dayElement.appendChild(linkElement); } else { dayElement.textContent = i; } // console.log("matchingDate: ", matchingDate); monthElement.appendChild(dayElement); } // Add empty days for the remaining cells in the last row var lastDay = new Date(year, month, daysInMonth).getDay(); for (var i = lastDay + 1; i < 7; i++) { monthElement.innerHTML += "
"; } return monthElement; } function getDayName(day) { var dayNames = [ "日", "月", "火", "水", "木", "金", "土"]; return dayNames[day]; } function getMonthName(month) { var monthNames = [ "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]; return monthNames[month]; } function getDaysInMonth(month, year) { return new Date(year, month + 1, 0).getDate(); } var calendar = document.getElementById("dp-calendar"); var currentDate = new Date(); var currentMonth = currentDate.getMonth(); var currentYear = currentDate.getFullYear(); var months = []; function createCalendar() { for (var i = 0; i < monthsahead; i++) { var month = currentMonth + i; var year = currentYear; if (month >= 12) { month -= 12; year += 1; } var monthElement = createMonth(month, year); months.push(monthElement); } months.forEach(function (month) { calendar.appendChild(month); }); } createCalendar(); var today = new Date(); var deadline = new Date(); var deadline = deadline.setHours(12,0,0,0); console.log("today: " + today); console.log("deadline: " + new Date(deadline).toString()); var dateElements = document.querySelectorAll(".dp-day.highlight"); for (var i = 0; i < validdates.length; i++) { var arrayDate = new Date(validdates[i].Date); arrayDate.setHours(arrayDate.getHours() + 9); //UTC+9 var dateElement = dateElements[i]; if (dateElement) { if (arrayDate >= deadline) { dateElement.style.opacity = "1"; // console.log(validdates[i].Date + " is today or in the future."); } else { dateElement.style.opacity = "0.4"; console.log(validdates[i].Date + " is in the past."); } } } });