PineaFan | e69bd22 | 2022-12-04 22:18:20 +0000 | [diff] [blame] | 1 | function 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`)], |
PineappleFan | 37476d2 | 2023-02-03 21:36:40 +0000 | [diff] [blame^] | 8 | christmas: [new Date(`${year}-12-1`), new Date(`${year}-12-26`)], |
| 9 | aprilFools: [new Date(`${year}-04-01`), new Date(`${year}-04-01`)] |
PineaFan | e69bd22 | 2022-12-04 22:18:20 +0000 | [diff] [blame] | 10 | } |
| 11 | const filePaths = { |
| 12 | normal: "normal", |
| 13 | halloween: "seasonal/halloween", |
| 14 | christmas: "seasonal/christmas", |
| 15 | pride: "seasonal/pride", |
PineappleFan | 37476d2 | 2023-02-03 21:36:40 +0000 | [diff] [blame^] | 16 | trans: "seasonal/trans", |
| 17 | aprilFools: "seasonal/aprilFools" |
PineaFan | e69bd22 | 2022-12-04 22:18:20 +0000 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | let current = new Date(); |
| 21 | let currentSeason = Object.keys(dates).find((str) => current >= dates[str][0] && current <= dates[str][1]) || "normal"; |
| 22 | |
| 23 | return { |
| 24 | season: currentSeason, |
| 25 | filePath: filePaths[currentSeason] |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | const Season = async (req, res) => { |
| 30 | return res.status(200).send(getSeason()); |
| 31 | } |
| 32 | |
| 33 | export default Season; |
| 34 | export { getSeason }; |