|
|
|
@ -179,28 +179,34 @@ export async function getEventsPageProps({ |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function getCurrentTerm(): { year: string; term: string } { |
|
|
|
|
const date = new Date(); |
|
|
|
|
export function getCurrentTerm() { |
|
|
|
|
const today = new Date().toLocaleDateString("en-CA", { |
|
|
|
|
timeZone: "EST", |
|
|
|
|
year: "numeric", |
|
|
|
|
month: "numeric", |
|
|
|
|
day: "numeric", |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const [year] = today.split("-"); |
|
|
|
|
|
|
|
|
|
let term = ""; |
|
|
|
|
const year = date.getUTCFullYear().toString(); |
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
new Date(`${year}-01-01 EST`).getTime() <= date.getTime() && |
|
|
|
|
date.getTime() <= new Date(`${year}-04-30 EST`).getTime() |
|
|
|
|
) { |
|
|
|
|
if (`${year}-01-01` <= today) { |
|
|
|
|
term = "winter"; |
|
|
|
|
} else if ( |
|
|
|
|
new Date(`${year}-05-01 EST`).getTime() <= date.getTime() && |
|
|
|
|
date.getTime() <= new Date(`${year}-08-31 EST`).getTime() |
|
|
|
|
) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (`${year}-05-01` <= today) { |
|
|
|
|
term = "spring"; |
|
|
|
|
} else if ( |
|
|
|
|
new Date(`${year}-09-01 EST`).getTime() <= date.getTime() && |
|
|
|
|
date.getTime() <= new Date(`${year}-12-31 EST`).getTime() |
|
|
|
|
) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (`${year}-09-01` <= today) { |
|
|
|
|
term = "fall"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (term === "") { |
|
|
|
|
throw new Error("Error setting the current term"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { year, term }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -211,7 +217,7 @@ function getPastTerm( |
|
|
|
|
const index = TERMS.indexOf(term); |
|
|
|
|
|
|
|
|
|
if (index === -1) { |
|
|
|
|
throw new Error("Not a valid term"); |
|
|
|
|
throw new Error(`[getPastTerm] Not a valid term: "${term}" "${year}"`); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return index === 0 |
|
|
|
@ -232,7 +238,7 @@ function getFutureTerm( |
|
|
|
|
const index = TERMS.indexOf(term); |
|
|
|
|
|
|
|
|
|
if (index === -1) { |
|
|
|
|
throw new Error("Not a valid term"); |
|
|
|
|
throw new Error(`[getFutureTerm] Not a valid term: "${term}" "${year}"`); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return index === TERMS.length - 1 |
|
|
|
|