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`)], |
| 8 | christmas: [new Date(`${year}-12-1`), new Date(`${year}-12-26`)] |
| 9 | } |
| 10 | const filePaths = { |
| 11 | normal: "normal", |
| 12 | halloween: "seasonal/halloween", |
| 13 | christmas: "seasonal/christmas", |
| 14 | pride: "seasonal/pride", |
| 15 | trans: "seasonal/trans" |
| 16 | } |
| 17 | |
| 18 | let current = new Date(); |
| 19 | let currentSeason = Object.keys(dates).find((str) => current >= dates[str][0] && current <= dates[str][1]) || "normal"; |
| 20 | |
| 21 | return { |
| 22 | season: currentSeason, |
| 23 | filePath: filePaths[currentSeason] |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | const Season = async (req, res) => { |
| 28 | return res.status(200).send(getSeason()); |
| 29 | } |
| 30 | |
| 31 | export default Season; |
| 32 | export { getSeason }; |