(eventsToday, eventsTomorrow, maxEvents, calendarColors, isWork)
| 1067 | FUNCTION formatEvents |
| 1068 | ------------------------------------------------------------------*/ |
| 1069 | function formatEvents(eventsToday, eventsTomorrow, maxEvents, calendarColors, isWork){ |
| 1070 | let formatLine = []; |
| 1071 | let eventsToShow = 0; |
| 1072 | const today = new Date(); |
| 1073 | let tomorrow = new Date(); |
| 1074 | tomorrow.setDate(tomorrow.getDate() + 1); |
| 1075 | const todayText = "T O D A Y"; |
| 1076 | const tomorrowText = "T O M O R R O W"; |
| 1077 | |
| 1078 | if (isWork && CALENDAR_WORK_CALENDARS.length == 0) { |
| 1079 | return formatLine; |
| 1080 | } |
| 1081 | |
| 1082 | formatLine.push({rsize: HEADER_RSIZE, title: todayText}); |
| 1083 | eventsToShow = 0; |
| 1084 | for (const e of eventsToday) { |
| 1085 | if (eventsToShow < maxEvents) { |
| 1086 | let prefix = null; |
| 1087 | let prefixColor = null; |
| 1088 | let bold = false; |
| 1089 | // Mark ongoing events |
| 1090 | if ((new Date(e.endDate)).getTime() >= today.getTime() && (new Date(e.startDate)).getTime() <= today.getTime() && !e.isAllDay) { |
| 1091 | prefix = "SFSymbol|circlebadge.fill"; |
| 1092 | prefixColor = red0; |
| 1093 | bold = false; |
| 1094 | } else { |
| 1095 | if (e.isAllDay) prefix = "SFSymbol|app"; |
| 1096 | else prefix = "SFSymbol|app.fill"; |
| 1097 | prefixColor = calendarColors[e.calendar.title]; |
| 1098 | } |
| 1099 | // Array of [Relative size, event title, calendar color] |
| 1100 | if (CALENDAR_SHOW_COLORS) formatLine.push({rsize: DETAIL_RSIZE, title: e.title, prefix: prefix, prefixColor: prefixColor, bold: bold}); |
| 1101 | // if (CALENDAR_SHOW_COLORS) formatLine.push({rsize: DETAIL_RSIZE, title: e.title, bold: bold}); |
| 1102 | else formatLine.push({rsize: DETAIL_RSIZE, title: e.title}); |
| 1103 | if (e.isAllDay) formatLine.push({rsize: FOOTER_RSIZE,title: "[ALL DAY]", bold: true}); |
| 1104 | else { |
| 1105 | if (!isSameDay(e.startDate,e.endDate)){ |
| 1106 | if (isSameDay(e.startDate,today)) // Starts today but ends on a later date, show only start time |
| 1107 | formatLine.push({rsize: FOOTER_RSIZE, title: `[${formatTime(e.startDate)}]`, bold: true}); |
| 1108 | else formatLine.push({rsize: FOOTER_RSIZE, title: `[Ends ${formatTime(e.endDate)}]`, bold: true}) // Starts earlier but ends today |
| 1109 | } else { |
| 1110 | formatLine.push({rsize: FOOTER_RSIZE, title: `[${formatTime(e.startDate)} - ${formatTime(e.endDate)}]`, bold: true}); |
| 1111 | } |
| 1112 | } |
| 1113 | eventsToShow++; |
| 1114 | } |
| 1115 | } |
| 1116 | if (eventsToShow == 0 && maxEvents > 0) formatLine.push({rsize: FOOTER_RSIZE, title: CALENDAR_NO_EVENTS_TEXT}); |
| 1117 | if (eventsToShow < eventsToday.length) formatLine.push({rsize: FOOTER_RSIZE, title: `${eventsToday.length - eventsToShow} more event(s)`}); |
| 1118 | |
| 1119 | if (!CALENDAR_SHOW_TOMORROW_EVENTS) return formatLine; |
| 1120 | |
| 1121 | formatLine.push({rsize: HEADER_RSIZE, title: tomorrowText}); |
| 1122 | eventsToShow = 0; |
| 1123 | for (const e of eventsTomorrow) { |
| 1124 | if (eventsToShow < maxEvents) { |
| 1125 | // Color calendars |
| 1126 | if (e.isAllDay) prefix = "SFSymbol|app"; |
no test coverage detected