Skip to content

Commit f9f99cf

Browse files
committed
incorporate reading start and end day if available
1 parent 626d3e0 commit f9f99cf

File tree

2 files changed

+95
-8
lines changed

2 files changed

+95
-8
lines changed

src/lib/dates.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,37 @@ export class Term {
244244
}
245245

246246
/** The date a slot starts on. */
247-
startDateFor(slot: Slot, secondHalf: boolean = false): Date {
247+
startDateFor(
248+
slot: Slot,
249+
secondHalf: boolean = false,
250+
startDay?: [number, number],
251+
): Date {
248252
const date = new Date((secondHalf ? this.h2Start : this.start).getTime());
253+
254+
if (startDay !== undefined) {
255+
date.setMonth(startDay[0] - 1);
256+
date.setDate(startDay[1]);
257+
}
258+
249259
while (date.getDay() !== slot.weekday) {
250260
date.setDate(date.getDate() + 1);
251261
}
252262
return slot.onDate(date);
253263
}
254264

255265
/** The date a slot ends on, plus an extra day. */
256-
endDateFor(slot: Slot, firstHalf: boolean = false): Date {
266+
endDateFor(
267+
slot: Slot,
268+
firstHalf: boolean = false,
269+
endDay?: [number, number],
270+
): Date {
257271
const date = new Date((firstHalf ? this.h1End : this.end).getTime());
272+
273+
if (endDay !== undefined) {
274+
date.setMonth(endDay[0] - 1);
275+
date.setDate(endDay[1]);
276+
}
277+
258278
while (date.getDay() !== slot.weekday) {
259279
date.setDate(date.getDate() - 1);
260280
}

src/lib/gapi.ts

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,45 @@ function toGoogleCalendarEvents(
5959
): Array<gapi.client.calendar.Event> {
6060
return activity.events.flatMap((event) =>
6161
event.slots.map((slot) => {
62-
const startDate = term.startDateFor(slot.startSlot);
63-
const startDateEnd = term.startDateFor(slot.endSlot);
64-
const endDate = term.endDateFor(slot.startSlot);
62+
let startDate: Date;
63+
let startDateEnd: Date;
64+
let endDate: Date;
65+
66+
if (
67+
"rawClass" in event.activity &&
68+
event.activity.rawClass.quarterInfo?.start
69+
) {
70+
startDate = term.startDateFor(
71+
slot.startSlot,
72+
undefined,
73+
event.activity.rawClass.quarterInfo?.start,
74+
);
75+
startDateEnd = term.startDateFor(
76+
slot.endSlot,
77+
undefined,
78+
event.activity.rawClass.quarterInfo?.start,
79+
);
80+
} else {
81+
startDate = term.startDateFor(slot.startSlot);
82+
startDateEnd = term.startDateFor(slot.endSlot);
83+
}
84+
85+
if (
86+
"rawClass" in event.activity &&
87+
event.activity.rawClass.quarterInfo?.end
88+
) {
89+
endDate = term.endDateFor(
90+
slot.startSlot,
91+
undefined,
92+
event.activity.rawClass.quarterInfo?.end,
93+
);
94+
} else {
95+
endDate = term.endDateFor(slot.startSlot);
96+
}
97+
6598
const exDates = term.exDatesFor(slot.startSlot);
6699
const rDate = term.rDateFor(slot.startSlot);
100+
67101
return {
68102
summary: event.name,
69103
location: event.room,
@@ -83,9 +117,42 @@ function toGoogleCalendarEvents(
83117
function toICalEvents(activity: Activity, term: Term): Array<ICalEventData> {
84118
return activity.events.flatMap((event) =>
85119
event.slots.map((slot) => {
86-
const startDate = term.startDateFor(slot.startSlot);
87-
const startDateEnd = term.startDateFor(slot.endSlot);
88-
const endDate = term.endDateFor(slot.startSlot);
120+
let startDate: Date;
121+
let startDateEnd: Date;
122+
let endDate: Date;
123+
124+
if (
125+
"rawClass" in event.activity &&
126+
event.activity.rawClass.quarterInfo?.start
127+
) {
128+
startDate = term.startDateFor(
129+
slot.startSlot,
130+
undefined,
131+
event.activity.rawClass.quarterInfo?.start,
132+
);
133+
startDateEnd = term.startDateFor(
134+
slot.endSlot,
135+
undefined,
136+
event.activity.rawClass.quarterInfo?.start,
137+
);
138+
} else {
139+
startDate = term.startDateFor(slot.startSlot);
140+
startDateEnd = term.startDateFor(slot.endSlot);
141+
}
142+
143+
if (
144+
"rawClass" in event.activity &&
145+
event.activity.rawClass.quarterInfo?.end
146+
) {
147+
endDate = term.endDateFor(
148+
slot.startSlot,
149+
undefined,
150+
event.activity.rawClass.quarterInfo?.end,
151+
);
152+
} else {
153+
endDate = term.endDateFor(slot.startSlot);
154+
}
155+
89156
const exDates = term.exDatesFor(slot.startSlot);
90157
const rDate = term.rDateFor(slot.startSlot);
91158

0 commit comments

Comments
 (0)