index-scripts.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
  2. function getMeetingDateText(startDate) {
  3. let nextMeeting = new Date(startDate);
  4. if(nextMeeting.getMonth() == 0) {
  5. // No meeting in January
  6. nextMeeting.setDate(1);
  7. nextMeeting.setMonth(nextMeeting.getMonth() + 1);
  8. return getMeetingDateText(nextMeeting);
  9. }
  10. const currentWeekday = nextMeeting.getDay();
  11. if(currentWeekday != 2) {
  12. nextMeeting.setDate(nextMeeting.getDate() + (currentWeekday > 2 ? 9 - currentWeekday : 2 - currentWeekday));
  13. }
  14. if(nextMeeting.getDate() <= 7) {
  15. nextMeeting.setDate(nextMeeting.getDate() + 7);
  16. }
  17. if(nextMeeting.getDate() > 14) {
  18. // We have passed the meeting for this month
  19. nextMeeting.setDate(1);
  20. nextMeeting.setMonth(nextMeeting.getMonth() + 1);
  21. return getMeetingDateText(nextMeeting);
  22. }
  23. return nextMeeting.toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
  24. }
  25. function setNextMeetingText() {
  26. const text = getMeetingDateText(new Date());
  27. document.getElementById("nextMeeting").innerHTML = text;
  28. }
  29. window.addEventListener("load", () => {
  30. setNextMeetingText();
  31. });
  32. // @license-end