diff --git a/website/src/utils/timetables.ts b/website/src/utils/timetables.ts index 12e79aa2cd..55c0993987 100644 --- a/website/src/utils/timetables.ts +++ b/website/src/utils/timetables.ts @@ -349,14 +349,43 @@ export function findExamClashes(modules: Module[], semester: Semester): ExamClas return clashes; } +// export function isLessonAvailable( +// lesson: Lesson, +// date: Date, +// weekInfo: Readonly, +// ): boolean { +// return consumeWeeks( +// lesson.weeks, +// (weeks) => weeks.includes(weekInfo.num as number), +// (weekRange) => { +// const end = minDate([parseISO(weekRange.end), date]); +// for (let current = parseISO(weekRange.start); current <= end; current = addDays(current, 7)) { +// if (isEqual(current, date)) return true; +// } + +// return false; +// }, +// ); +// } + export function isLessonAvailable( lesson: Lesson, date: Date, weekInfo: Readonly, ): boolean { + // console.log("weekInfo:", weekInfo); + // console.log("date:", date.toISOString()); + // console.log("lesson:", lesson) + return consumeWeeks( lesson.weeks, - (weeks) => weeks.includes(weekInfo.num as number), + (weeks) => { + // console.log("Lesson weeks (list):", weeks); + const isWeekIncluded = weeks.includes(weekInfo.num as number); + + // console.log("Is weekInfo.num included in weeks:", isWeekIncluded); + return isWeekIncluded; + }, (weekRange) => { const end = minDate([parseISO(weekRange.end), date]); for (let current = parseISO(weekRange.start); current <= end; current = addDays(current, 7)) { @@ -368,6 +397,7 @@ export function isLessonAvailable( ); } + export function isLessonOngoing(lesson: Lesson, currentTime: number): boolean { return ( parseInt(lesson.startTime, 10) <= currentTime && currentTime < parseInt(lesson.endTime, 10) diff --git a/website/src/views/today/TodayContainer/TodayContainer.tsx b/website/src/views/today/TodayContainer/TodayContainer.tsx index ee03e6ec9c..f0f0abd7e1 100644 --- a/website/src/views/today/TodayContainer/TodayContainer.tsx +++ b/website/src/views/today/TodayContainer/TodayContainer.tsx @@ -347,8 +347,19 @@ export class TodayContainerComponent extends React.PureComponent { export const mapStateToProps = (state: StoreState, ownProps: OwnProps) => { const { modules } = state.moduleBank; - const lastDay = addDays(ownProps.currentTime, DAYS); - const weekInfo = NUSModerator.academicCalendar.getAcadWeekInfo(lastDay); + + const lastDay = addDays(ownProps.currentTime, DAYS); // current date plus 7 days + const todayWeekInfo = NUSModerator.academicCalendar.getAcadWeekInfo(new Date()); + const nextWeekInfo = NUSModerator.academicCalendar.getAcadWeekInfo(lastDay); + + var todaySemester = semesterNameMap[todayWeekInfo.sem]; + var nextWeekSemester = semesterNameMap[nextWeekInfo.sem]; + + // On week -1 of semester 2, the semester should be 2, not 1 + const weekBeforeSem2 = (todaySemester === 1 && nextWeekSemester === 2); + // If it's the week before semester 2, use sem2's week info, otherwise use current date's week info + const weekInfo = weekBeforeSem2 ? nextWeekInfo : todayWeekInfo; + const semester = semesterNameMap[weekInfo.sem]; const timetable = getSemesterTimetableLessons(state)(semester); const colors = getSemesterTimetableColors(state)(semester);