blob: 52cfb819029c1ec524b7e123779f9f4a15436a06 [file] [log] [blame]
PineaFane69bd222022-12-04 22:18:20 +00001function getSeason() {
2 let year = new Date().getFullYear();
3
4 const dates = {
5 pride: [new Date(`${year}-6-1`), new Date(`${year}-6-31`)],
6 halloween: [new Date(`${year}-10-25`), new Date(`${year}-11-1`)],
7 trans: [new Date(`${year}-11-13`), new Date(`${year}-11-19`)],
PineappleFan37476d22023-02-03 21:36:40 +00008 christmas: [new Date(`${year}-12-1`), new Date(`${year}-12-26`)],
9 aprilFools: [new Date(`${year}-04-01`), new Date(`${year}-04-01`)]
PineaFane69bd222022-12-04 22:18:20 +000010 }
11 const filePaths = {
12 normal: "normal",
13 halloween: "seasonal/halloween",
14 christmas: "seasonal/christmas",
15 pride: "seasonal/pride",
PineappleFan37476d22023-02-03 21:36:40 +000016 trans: "seasonal/trans",
17 aprilFools: "seasonal/aprilFools"
PineaFane69bd222022-12-04 22:18:20 +000018 }
19
20 let current = new Date();
21 let currentSeason = Object.keys(dates).find((str) => current >= dates[str][0] && current <= dates[str][1]) || "normal";
Ashefe6f6b2023-02-13 22:07:43 +000022 let daysIntoSeason;
PineappleFane9ce4cc2023-02-13 22:05:07 +000023 if (currentSeason !== "normal") {
24 daysIntoSeason = Math.floor((new Date().getTime() - dates[currentSeason][0].getTime()) / (1000 * 60 * 60 * 24))
Ashefe6f6b2023-02-13 22:07:43 +000025 } else {
26 // Calculate days past the most recent season
27 let mostRecentSeason = Object.keys(dates).reduce((a, b) => dates[a][1] > dates[b][1] ? a : b);
28 daysIntoSeason = Math.floor((new Date().getTime() - dates[mostRecentSeason][1].getTime()) / (1000 * 60 * 60 * 24))
PineappleFane9ce4cc2023-02-13 22:05:07 +000029 }
PineaFane69bd222022-12-04 22:18:20 +000030
31 return {
32 season: currentSeason,
PineappleFane9ce4cc2023-02-13 22:05:07 +000033 filePath: filePaths[currentSeason],
34 daysIntoSeason: daysIntoSeason
PineaFane69bd222022-12-04 22:18:20 +000035 }
36}
37
38const Season = async (req, res) => {
39 return res.status(200).send(getSeason());
40}
41
42export default Season;
43export { getSeason };