Skip to content

Commit

Permalink
fixed multiple cals and tz bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
domlet committed Aug 1, 2024
1 parent 2ace3b5 commit a7daa57
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions script/scriptEventLists.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Scripts specific to events, ie not dots
*/

// const { addDays } = require("date-fns");

const calendarIds = [
"[email protected]", // CCPA
"a71ff6b63e1709ae2bfbcada2b3b64ebeb1f7f5e30787b2bb059725fa17b7b2b@group.calendar.google.com", // Free museums - https://github.com/ccpa-ousd/opps-cal-hs
Expand Down Expand Up @@ -42,18 +44,6 @@ document.addEventListener("DOMContentLoaded", () => {
// in the same loop, fetch recurring instances
// and set eventType for calendars like 'opportunity'
for (let event of gCalevents) {
if (
calendarId ==
"a71ff6b63e1709ae2bfbcada2b3b64ebeb1f7f5e30787b2bb059725fa17b7b2b@group.calendar.google.com"
) {
gCalevents[i].eventType = "opportunity";
}
if (
calendarId ==
"e5c502978d4582e2e7b304e8197120672739ed245f730fc938e64c24949e000e@group.calendar.google.com"
) {
gCalevents[i].eventType = "studentActivity";
}
if (event.recurrence) {
let instancesUrl = `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events/${event.id}/instances?timeMin=${timeMin}&timeMax=${timeMax}&key=${gCalkey}&timeZone=${timezone}`;
let instancesResponse = await fetch(instancesUrl);
Expand All @@ -74,15 +64,33 @@ document.addEventListener("DOMContentLoaded", () => {
gCalActiveEvents = gCalevents.filter(
(item) => item.status !== "cancelled"
);

// Adjust for CCPA Public Calendar events which are missing timezones and dateTimes
// That missing data causes its events to show up 1 day early
for (item of combinedGCalEvents) {
if (
calendarId ==
"[email protected]" &&
item.start.timeZone != "America/Los_Angeles" &&
item.start.dateTime == undefined
) {
item.start.timeZone = "America/Los_Angeles";
item.start.dateTime = item.start.date + " 0:00:00";
}
}
// push each event (from each calendar) into the combinedGCalEvents array
for (let i = 0; i < gCalActiveEvents.length; i++) {
if (
calendarId ==
"a71ff6b63e1709ae2bfbcada2b3b64ebeb1f7f5e30787b2bb059725fa17b7b2b@group.calendar.google.com"
) {
gCalActiveEvents[i].eventType = "opportunity";
} else if (
calendarId ==
"e5c502978d4582e2e7b304e8197120672739ed245f730fc938e64c24949e000e@group.calendar.google.com"
) {
gCalevents[i].eventType = "studentActivity";
}

combinedGCalEvents.push(gCalActiveEvents[i]);
}
}
Expand Down Expand Up @@ -137,7 +145,6 @@ document.addEventListener("DOMContentLoaded", () => {
// then sort them by date
for (let event of currentSY.dates) {
combinedAllEvents.push(event);
console.log(event);
}
for (let event of combinedGCalEvents) {
combinedAllEvents.push(event);
Expand Down

0 comments on commit a7daa57

Please sign in to comment.