blob: 52cfb819029c1ec524b7e123779f9f4a15436a06 [file] [log] [blame]
function getSeason() {
let year = new Date().getFullYear();
const dates = {
pride: [new Date(`${year}-6-1`), new Date(`${year}-6-31`)],
halloween: [new Date(`${year}-10-25`), new Date(`${year}-11-1`)],
trans: [new Date(`${year}-11-13`), new Date(`${year}-11-19`)],
christmas: [new Date(`${year}-12-1`), new Date(`${year}-12-26`)],
aprilFools: [new Date(`${year}-04-01`), new Date(`${year}-04-01`)]
}
const filePaths = {
normal: "normal",
halloween: "seasonal/halloween",
christmas: "seasonal/christmas",
pride: "seasonal/pride",
trans: "seasonal/trans",
aprilFools: "seasonal/aprilFools"
}
let current = new Date();
let currentSeason = Object.keys(dates).find((str) => current >= dates[str][0] && current <= dates[str][1]) || "normal";
let daysIntoSeason;
if (currentSeason !== "normal") {
daysIntoSeason = Math.floor((new Date().getTime() - dates[currentSeason][0].getTime()) / (1000 * 60 * 60 * 24))
} else {
// Calculate days past the most recent season
let mostRecentSeason = Object.keys(dates).reduce((a, b) => dates[a][1] > dates[b][1] ? a : b);
daysIntoSeason = Math.floor((new Date().getTime() - dates[mostRecentSeason][1].getTime()) / (1000 * 60 * 60 * 24))
}
return {
season: currentSeason,
filePath: filePaths[currentSeason],
daysIntoSeason: daysIntoSeason
}
}
const Season = async (req, res) => {
return res.status(200).send(getSeason());
}
export default Season;
export { getSeason };