Skip to content

Commit

Permalink
clean up, check h1 and h2
Browse files Browse the repository at this point in the history
  • Loading branch information
dtemkin1 committed Dec 16, 2024
1 parent a341cd8 commit 000b35d
Showing 1 changed file with 18 additions and 68 deletions.
86 changes: 18 additions & 68 deletions src/lib/gapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,17 @@ function toGoogleCalendarEvents(
): Array<gapi.client.calendar.Event> {
return activity.events.flatMap((event) =>
event.slots.map((slot) => {
let startDate: Date;
let startDateEnd: Date;
let endDate: Date;
const rawClass =
"rawClass" in event.activity ? event.activity.rawClass : undefined;

if (
"rawClass" in event.activity &&
event.activity.rawClass.quarterInfo?.start
) {
startDate = term.startDateFor(
slot.startSlot,
undefined,
event.activity.rawClass.quarterInfo?.start,
);
startDateEnd = term.startDateFor(
slot.endSlot,
undefined,
event.activity.rawClass.quarterInfo?.start,
);
} else {
startDate = term.startDateFor(slot.startSlot);
startDateEnd = term.startDateFor(slot.endSlot);
}

if (
"rawClass" in event.activity &&
event.activity.rawClass.quarterInfo?.end
) {
endDate = term.endDateFor(
slot.startSlot,
undefined,
event.activity.rawClass.quarterInfo?.end,
);
} else {
endDate = term.endDateFor(slot.startSlot);
}
const start = rawClass?.quarterInfo?.start;
const end = rawClass?.quarterInfo?.end;
const h1 = rawClass?.half === 1;
const h2 = rawClass?.half === 2;

const startDate = term.startDateFor(slot.startSlot, h2, start);
const startDateEnd = term.startDateFor(slot.endSlot, h2, start);
const endDate = term.endDateFor(slot.startSlot, h1, end);
const exDates = term.exDatesFor(slot.startSlot);
const rDate = term.rDateFor(slot.startSlot);

Expand All @@ -117,42 +92,17 @@ function toGoogleCalendarEvents(
function toICalEvents(activity: Activity, term: Term): Array<ICalEventData> {
return activity.events.flatMap((event) =>
event.slots.map((slot) => {
let startDate: Date;
let startDateEnd: Date;
let endDate: Date;
const rawClass =
"rawClass" in event.activity ? event.activity.rawClass : undefined;

if (
"rawClass" in event.activity &&
event.activity.rawClass.quarterInfo?.start
) {
startDate = term.startDateFor(
slot.startSlot,
undefined,
event.activity.rawClass.quarterInfo?.start,
);
startDateEnd = term.startDateFor(
slot.endSlot,
undefined,
event.activity.rawClass.quarterInfo?.start,
);
} else {
startDate = term.startDateFor(slot.startSlot);
startDateEnd = term.startDateFor(slot.endSlot);
}

if (
"rawClass" in event.activity &&
event.activity.rawClass.quarterInfo?.end
) {
endDate = term.endDateFor(
slot.startSlot,
undefined,
event.activity.rawClass.quarterInfo?.end,
);
} else {
endDate = term.endDateFor(slot.startSlot);
}
const start = rawClass?.quarterInfo?.start;
const end = rawClass?.quarterInfo?.end;
const h1 = rawClass?.half === 1;
const h2 = rawClass?.half === 2;

const startDate = term.startDateFor(slot.startSlot, h2, start);
const startDateEnd = term.startDateFor(slot.endSlot, h2, start);
const endDate = term.endDateFor(slot.startSlot, h1, end);
const exDates = term.exDatesFor(slot.startSlot);
const rDate = term.rDateFor(slot.startSlot);

Expand Down

0 comments on commit 000b35d

Please sign in to comment.