Introducing a new way to review your PRs.

Read the announcement

nusmodifications / nusmods

🏫 Official course planning platform for National University of Singapore.

View on GitHub

20 documents · Updated Nov 6, 2026

docs / academic-calendar-utilities

Academic calendar utilities

Academic calendar utilities give NUSMods one shared way to interpret dates in an academic year. They combine term start data with rules for academic weeks, breaks, exams, and public holidays so planning, timetable display, Today, and calendar export use the same date model. See Academic planning for the wider planning area and Planner and module bank for the study-plan features that use this context.

Calendar model

The calendar model separates stored term dates from derived week meaning. The shared academic-calendar package stores the start of each term, while nusmoderator turns any date into an academic year, term, and week category.

Term start data

The nusmods-academic-calendar package is the shared source for academic-year term starts. An academic year uses a string such as 2025/2026, and its numeric terms map to Semester 1, Semester 2, Special Term I, and Special Term II. Each term start is a date tuple with a calendar year, month, and day. packages/…/academic-calendar.json• L1-70

The package exposes the raw calendar and a date form of a term start. It also marks terms 3 and 4 as special terms. The website re-exports these values through website/…/academic-calendar.ts, which keeps application code on the shared data contract instead of maintaining a second calendar. packages/…/index.js• L1-17 packages/…/index.d.ts• L1-16 website/…/academic-calendar.ts• L1-13

References: packages/…/academic-calendar.json• L1-70 packages/…/index.js• L1-17 packages/…/index.d.ts• L1-16 website/…/academic-calendar.ts• L1-13

Special-term transition

Special-term data has a transition period at the end of an academic year. After the application moves to the new academic year, the previous academic year can still supply Special Term I or II data until the new year’s Semester 1 starts. packages/…/index.js• L19-34

The utility selects the previous year during this overlap when no explicit special-term year is set. A configured special-term year takes priority. This rule applies only to special terms, so normal semesters remain tied to the selected academic year. packages/…/index.js• L36-73

References: packages/…/index.js• L19-73 packages/…/index.d.ts• L18-37 packages/…/index.test.js• L12-81

Date interpretation

nusmoderator provides the calendar view used when application behavior depends on a date. It treats Monday as the start of an academic week and returns a compact AcadWeekInfo value with the academic year, term, week category, and optional week number. packages/…/types.ts• L1-25

This flow shows how stored term dates and derived date meaning support downstream behavior.

flowchart LR
    D[Calendar date] --> Y[Academic year]
    Y --> W[Academic week and term category]
    S[Term start data] --> E[Calendar export dates]
    H[Public holiday dates] --> T[Today and lesson visibility]
    W --> T
    W --> L[User-facing week labels]
    W --> E

Academic year mapping

The academic-year helper assigns a date to the academic year that begins around August. It returns both the year label and the Monday used as that year’s week-zero anchor. This anchor is distinct from the exact Semester 1 start stored in the shared data package. packages/…/academicCalendar.ts• L7-24 packages/…/academicCalendar.ts• L33-53

The derived semester ranges follow the annual week pattern. Semester 1 covers academic weeks 1–23, Semester 2 covers weeks 24–40, and Special Terms I and II cover weeks 41–46 and 47–52. Unsupported week numbers return no term rather than creating a misleading classification. packages/…/academicCalendar.ts• L56-89

References: packages/…/academicCalendar.ts• L7-24 packages/…/academicCalendar.ts• L33-53 packages/…/academicCalendar.ts• L56-89 packages/…/types.ts• L9-25

Academic week categories

An academic week is not always an instructional week. The derived result identifies orientation, instructional, recess, reading, examination, and vacation periods. It omits a normal week number for categories such as recess and reading, and it uses examination week numbers for the two examination weeks. packages/…/academicCalendar.ts• L92-135

The date classifier also handles the weekend that leads into a recess, reading, or examination period. This keeps a date’s category aligned with the academic event shown to students rather than relying only on a Monday-to-Sunday label. packages/…/academicCalendar.ts• L148-231

References: packages/…/academicCalendar.ts• L92-135 packages/…/academicCalendar.ts• L148-231 packages/…/types.ts• L1-25 packages/…/academicCalendar.test.ts• L80-295

Examination dates

The exam helper maps a term number to the first day of its examination week. It supports the two normal semesters and both special terms, and it returns no date for an unknown term or unsupported academic year. packages/…/academicCalendar.ts• L234-264

This date is used as a calendar event anchor when module data provides an exam. The helper therefore connects the academic-week model to student-facing exam information without making each consumer repeat the term-week offsets. website/…/ical.ts• L113-128

References: packages/…/academicCalendar.ts• L234-264 packages/…/academicCalendar.test.ts• L298-310 website/…/ical.ts• L113-128

Date-aware application behavior

Application features use calendar meaning to decide whether lessons are active, how dates are described, and which dates calendar exports should exclude. The same AcadWeekInfo result is passed into these features so a break or holiday has a consistent effect across views.

Lesson visibility

The Today view checks the academic week category and the configured holiday list before it presents a day as a lesson day. It also checks each lesson’s week rule against the date, so a lesson can be hidden on a break or on a date outside its selected weeks. website/…/TodayContainer.tsx• L93-110 website/…/TodayContainer.tsx• L234-261 website/…/index.ts• L103-120

When no lesson is shown, the view groups dates by their reason for being empty. Students can therefore distinguish a holiday, weekend, vacation, recess, reading period, examination period, or orientation period instead of seeing one generic empty state. website/…/TodayContainer.tsx• L84-110

References: website/…/TodayContainer.tsx• L84-110 website/…/TodayContainer.tsx• L234-261 website/…/index.ts• L103-120 website/…/holidays.json• L1-97

Week labels

The application turns AcadWeekInfo into a short label that combines the academic year, term, and week category. Instructional weeks show a plain week number, while special categories keep their names so the current academic context remains clear. website/…/weekText.ts• L4-18

The same category is used in timetable lesson details. Numeric lesson weeks remain tied to the timetable data, while the calendar helper supplies the meaning of dates listed in a week range. website/…/TimetableCell.tsx• L39-42 website/…/TimetableCell.tsx• L67-109

References: website/…/weekText.ts• L4-25 website/…/weekText.test.ts• L11-37 website/…/TimetableCell.tsx• L39-42 website/…/TimetableCell.tsx• L67-109

Calendar export dates

Calendar export builds recurring lesson events from the stored start date for the selected academic year and term. It then removes weeks that are not in a lesson’s week rule and removes public holidays, so a weekly event does not imply a class on every calendar week. website/…/ical.ts• L146-185

Holiday values are maintained as date strings and loaded into application configuration as Date values. Export converts them back to the Singapore calendar date at the lesson time before adding them as exclusions. This preserves the intended local holiday when the event is sent to an external calendar. website/…/index.ts• L1-7 website/…/index.ts• L72-95 website/…/ical.ts• L131-143

References: website/…/ical.ts• L131-185 website/…/ical.ts• L254-287 website/…/index.ts• L1-7 website/…/index.ts• L72-95 website/…/holidays.json• L1-97

Change checklist

When these files or sections are changed, remember to consider these:

  • When term starts or supported academic years change in academic-calendar.json, check both exact export start dates and the special-term overlap boundary.
  • When the academic-week pattern changes, review week classification, lesson availability, Today empty-day grouping, timetable labels, and exam-week dates as one contract.
  • When holiday date storage changes, check the configuration conversion and the Singapore-date handling in calendar export together.
  • When special-term selection changes, preserve the distinction between previous-year special-term data and current-year Semester 1 or 2 data.

Important failure modes

TriggerConsequenceGuard
A term is missing from the shared calendar dataThe selected term has no start date, so date-based consumers cannot build its schedule or export anchorKeep the academic-year and term entries complete and use the shared getSemesterStart lookup
The academic-year transition is treated as an immediate switch for every termSpecial Term lessons can point to the new year before that term has endedApply previous-year fallback only during the overlap and only for special terms
A holiday is compared as a raw instant instead of as a Singapore calendar dateA recurring lesson can remain on a holiday or be excluded on the wrong local dayPreserve the date conversion used by the holiday loader and export path
A date is classified only by its calendar weekThe weekend before recess, reading, or exams can receive the wrong student-facing categoryUse the academic week classifier for date-level decisions
An unsupported academic week or term is forced into a normal valueThe UI or export can show a plausible but false term or weekTreat unsupported results as null and keep callers able to handle the missing value

Key files

FileWhy to read it
packages/…/academic-calendar.jsonShared term start dates for supported academic years
packages/…/index.jsRules for term lookup and special-term year selection during the academic-year transition
packages/…/academicCalendar.tsDate-to-academic-year, term, week-category, and exam-week behavior
packages/…/types.tsMeaning of week categories and the AcadWeekInfo contract
website/…/academic-calendar.tsWebsite boundary for the shared calendar package
website/…/holidays.jsonPublic holiday dates used by date-aware behavior
website/…/TodayContainer.tsxStudent-facing use of week categories and holidays to group the next seven days
website/…/ical.tsConversion of term starts, lesson weeks, and holidays into calendar events