Description
We'll need to be able to interact with different terms in the app. This story is to create some common functionality we can use.
Technical Details
- Create a file in
apps/applicant-tracking/src/utils called term.ts
- First, inside this file put the following code in to generate the type for terms;
type TermSemester = 'Spring' | 'Fall';
export type Term = `${TermSemester} ${number}`;
- Inside of this file create three functions:
getCurrentTerm, getNextTerm, getPreviousTerm
- The details of each of these functions is below.
Before we get into the technical details let's talk about what a term is.
There are two parts to a term: the semester (Spring and Fall) and the year. The term is then just these two parts concatenated, i.e. Fall 2024
getCurrentTerm
- The prototype of this function should be
export function getCurrentTerm(): Term
- This function should get the current Date using
const date = new Date()
- The year part of the term is available from this date (check the Date docs to see how to get the year out of this date.
- The semester is a bit harder to get, but the logic is as follows:
- If the (zero-indexed) month is between 0 (January) and 5 (June) we will consider the current semester to be "Spring"
- If the month is between 6 (July) and 11 (December), the semester is "Fall".
- Again, check the docs to figure out how to get the month from the
date variable
- Finally, return "`${semester} ${year}`"
getNextTerm
- The prototype of this function should be
export function getNextTerm(term: Term): Term
- This function should split the term into its component semester and year parts.
- Then, if the current semester is "Spring", you can just return "`Fall ${year}`"
- If the current semester is "Fall", add one to the year and return "`Spring ${newYear}`"
getPreviousTerm
- The prototype of this function should be
export function getPreviousTerm(term: Term): Term
- Reverse the logic of
getNextTerm!
Teachables
Testing Steps
Work with @zaviermiller to test :)
Dependencies
Description
We'll need to be able to interact with different terms in the app. This story is to create some common functionality we can use.
Technical Details
apps/applicant-tracking/src/utilscalledterm.tsgetCurrentTerm,getNextTerm,getPreviousTermBefore we get into the technical details let's talk about what a term is.
There are two parts to a term: the semester (Spring and Fall) and the year. The term is then just these two parts concatenated, i.e. Fall 2024
getCurrentTermexport function getCurrentTerm(): Termconst date = new Date()datevariablegetNextTermexport function getNextTerm(term: Term): TermgetPreviousTermexport function getPreviousTerm(term: Term): TermgetNextTerm!Teachables
Testing Steps
Work with @zaviermiller to test :)
Dependencies