blob: c3066cc3e45b7e4d72d589a82b6ef92ea0ec5d85 [file] [log] [blame]
PineappleFan459a2e62023-02-14 08:50:54 +00001function daysIntoSeason(date) {
2 return Math.floor((new Date().getTime() - date.getTime()) / (1000 * 60 * 60 * 24))
3}
4
PineaFane69bd222022-12-04 22:18:20 +00005function getSeason() {
6 let year = new Date().getFullYear();
7
8 const dates = {
9 pride: [new Date(`${year}-6-1`), new Date(`${year}-6-31`)],
10 halloween: [new Date(`${year}-10-25`), new Date(`${year}-11-1`)],
11 trans: [new Date(`${year}-11-13`), new Date(`${year}-11-19`)],
PineappleFan37476d22023-02-03 21:36:40 +000012 christmas: [new Date(`${year}-12-1`), new Date(`${year}-12-26`)],
13 aprilFools: [new Date(`${year}-04-01`), new Date(`${year}-04-01`)]
PineaFane69bd222022-12-04 22:18:20 +000014 }
15 const filePaths = {
16 normal: "normal",
17 halloween: "seasonal/halloween",
18 christmas: "seasonal/christmas",
19 pride: "seasonal/pride",
PineappleFan37476d22023-02-03 21:36:40 +000020 trans: "seasonal/trans",
21 aprilFools: "seasonal/aprilFools"
PineaFane69bd222022-12-04 22:18:20 +000022 }
23
24 let current = new Date();
25 let currentSeason = Object.keys(dates).find((str) => current >= dates[str][0] && current <= dates[str][1]) || "normal";
Ashefe6f6b2023-02-13 22:07:43 +000026 let daysIntoSeason;
PineappleFane9ce4cc2023-02-13 22:05:07 +000027 if (currentSeason !== "normal") {
PineappleFan459a2e62023-02-14 08:50:54 +000028 daysIntoSeason = daysIntoSeason(dates[currentSeason][0])
Ashefe6f6b2023-02-13 22:07:43 +000029 } else {
PineappleFan459a2e62023-02-14 08:50:54 +000030 // Calculate the days from the end of each season
31 let days = Object.keys(dates).map((str) => daysIntoSeason(dates[str][1])).filter((num) => num > 0);
32 daysIntoSeason = Math.min(...days);
PineappleFane9ce4cc2023-02-13 22:05:07 +000033 }
PineaFane69bd222022-12-04 22:18:20 +000034
35 return {
36 season: currentSeason,
PineappleFane9ce4cc2023-02-13 22:05:07 +000037 filePath: filePaths[currentSeason],
38 daysIntoSeason: daysIntoSeason
PineaFane69bd222022-12-04 22:18:20 +000039 }
40}
41
42const Season = async (req, res) => {
43 return res.status(200).send(getSeason());
44}
45
46export default Season;
47export { getSeason };