Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. function montlyCalendar ([day,month,year]) {
  2. let days = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
  3. let result = '<table>\n<tr>';
  4. for (x of days){
  5. result += `<th>${x}</th>`
  6. }
  7. result+='</tr>\n';
  8. let daysInWeek = 1;
  9. let inputDate = new Date(year,month-1,day);
  10. let firstDay = new Date(year,month-1,1);
  11. let firstDate = firstDay.setDate(firstDay.getDate() - firstDay.getDay());
  12. let lastDay = new Date(year, month,0);
  13. let lastDate = lastDay.setDate(lastDay.getDate() + (7-(lastDay.getDay()+1)%7));
  14. for (let dm = new Date(firstDate); dm <=new Date(lastDate); dm.setDate(dm.getDate()+1)){
  15. if ((dm.getDay()+1)%7==1)
  16. result+=' <tr>';
  17. if (dm.getMonth()<inputDate.getMonth())
  18. result+=`<td class="prev-month">${dm.getDate()}</td>`;
  19. else if (dm.getMonth()>inputDate.getMonth())
  20. result+=`<td class="next-month">${dm.getDate()}</td>`;
  21. else if (dm.getDate()==inputDate.getDate())
  22. result+=`<td class="today">${dm.getDate()}</td>`
  23. else
  24. result+=`<td>${dm.getDate()}</td>`;
  25. if ((dm.getDay()+1)%7==0)
  26. result+='</tr>\n'
  27. }
  28. return result;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement