course conflict highlighting and calculations
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable max-classes-per-file */
|
||||
import { Serialized } from 'chrome-extension-toolkit';
|
||||
import { capitalize } from '../util/string';
|
||||
import { CourseMeeting } from './CourseMeeting';
|
||||
import { CourseSchedule } from './CourseSchedule';
|
||||
import Instructor from './Instructor';
|
||||
|
||||
@@ -74,6 +74,24 @@ export class Course {
|
||||
this.schedule = new CourseSchedule(course.schedule);
|
||||
this.instructors = course.instructors.map(i => new Instructor(i));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all the conflicts between this course and another course (i.e. if they have a meeting at the same time)
|
||||
* @param other another course to compare this course to
|
||||
* @returns a list of all the conflicts between this course and the other course as a tuple of the two conflicting meetings
|
||||
*/
|
||||
getConflicts(other: Course): [CourseMeeting, CourseMeeting][] {
|
||||
const conflicts: [CourseMeeting, CourseMeeting][] = [];
|
||||
for (const meeting of this.schedule.meetings) {
|
||||
for (const otherMeeting of other.schedule.meetings) {
|
||||
if (meeting.isConflicting(otherMeeting)) {
|
||||
conflicts.push([meeting, otherMeeting]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return conflicts;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,22 @@ export class CourseMeeting {
|
||||
Object.assign(this, meeting);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this meeting conflicts with another meeting
|
||||
* MWF 10:00 am - 11:00 am conflicts with a F 10:00 am - 10:30 am
|
||||
* @param meeting the meeting to check for conflicts with
|
||||
* @returns true if the given meeting conflicts with this meeting, false otherwise
|
||||
*/
|
||||
isConflicting(meeting: CourseMeeting): boolean {
|
||||
const { days, startTime, endTime } = this;
|
||||
const { days: otherDays, startTime: otherStartTime, endTime: otherEndTime } = meeting;
|
||||
|
||||
const hasDayConflict = days.some(day => otherDays.includes(day));
|
||||
const hasTimeConflict = startTime < otherEndTime && endTime > otherStartTime;
|
||||
|
||||
return hasDayConflict && hasTimeConflict;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the string representation of the days of the week that this meeting is taught
|
||||
* @param options options for the string representation
|
||||
|
||||
Reference in New Issue
Block a user