blob: 2603a5251c7f82998c450404af635d932a2d5379 [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
pineafanf5dd1872023-02-28 17:33:16 +00005function daysSinceDate(date) {
6 // If the date is after today, make it last year
7 if (date > new Date()) {
8 date.setFullYear(date.getFullYear() - 1);
9 }
10 return Math.floor((new Date().getTime() - date.getTime()) / (1000 * 60 * 60 * 24));
11}
12
PineaFane69bd222022-12-04 22:18:20 +000013function getSeason() {
14 let year = new Date().getFullYear();
15
16 const dates = {
17 pride: [new Date(`${year}-6-1`), new Date(`${year}-6-31`)],
18 halloween: [new Date(`${year}-10-25`), new Date(`${year}-11-1`)],
19 trans: [new Date(`${year}-11-13`), new Date(`${year}-11-19`)],
PineappleFan37476d22023-02-03 21:36:40 +000020 christmas: [new Date(`${year}-12-1`), new Date(`${year}-12-26`)],
pineafanf5dd1872023-02-28 17:33:16 +000021 aprilFools: [new Date(`${year}-04-01`), new Date(`${year}-04-01`)],
22 fake: [new Date(`${year}-01-01`), new Date(`${year}-01-01`)]
PineaFane69bd222022-12-04 22:18:20 +000023 }
24 const filePaths = {
25 normal: "normal",
26 halloween: "seasonal/halloween",
27 christmas: "seasonal/christmas",
28 pride: "seasonal/pride",
PineappleFan37476d22023-02-03 21:36:40 +000029 trans: "seasonal/trans",
30 aprilFools: "seasonal/aprilFools"
PineaFane69bd222022-12-04 22:18:20 +000031 }
32
33 let current = new Date();
34 let currentSeason = Object.keys(dates).find((str) => current >= dates[str][0] && current <= dates[str][1]) || "normal";
pineafanf5dd1872023-02-28 17:33:16 +000035 let currentDaysIntoSeason;
PineappleFane9ce4cc2023-02-13 22:05:07 +000036 if (currentSeason !== "normal") {
pineafanf5dd1872023-02-28 17:33:16 +000037 currentDaysIntoSeason = daysIntoSeason(dates[currentSeason][0])
Ashefe6f6b2023-02-13 22:07:43 +000038 } else {
pineafanf5dd1872023-02-28 17:33:16 +000039 // Calculate how many days it has been since each season ended
40 let days = Object.keys(dates).map((str) => daysSinceDate(dates[str][1]))
41 currentDaysIntoSeason = Math.min(...days);
PineappleFane9ce4cc2023-02-13 22:05:07 +000042 }
PineaFane69bd222022-12-04 22:18:20 +000043
44 return {
45 season: currentSeason,
PineappleFane9ce4cc2023-02-13 22:05:07 +000046 filePath: filePaths[currentSeason],
pineafanf5dd1872023-02-28 17:33:16 +000047 daysIntoSeason: currentDaysIntoSeason
PineaFane69bd222022-12-04 22:18:20 +000048 }
49}
50
51const Season = async (req, res) => {
52 return res.status(200).send(getSeason());
53}
54
55export default Season;
56export { getSeason };