Skip to content

Commit

Permalink
use sem2 weekInfo considering week before sem2
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyuwang-nus committed Sep 12, 2024
1 parent a143a4f commit b17dcae
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
32 changes: 31 additions & 1 deletion website/src/utils/timetables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,43 @@ export function findExamClashes(modules: Module[], semester: Semester): ExamClas
return clashes;
}

// export function isLessonAvailable(
// lesson: Lesson,
// date: Date,
// weekInfo: Readonly<AcadWeekInfo>,
// ): 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<AcadWeekInfo>,
): 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)) {
Expand All @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions website/src/views/today/TodayContainer/TodayContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,19 @@ export class TodayContainerComponent extends React.PureComponent<Props, State> {

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);
Expand Down

0 comments on commit b17dcae

Please sign in to comment.