Nucleus transcripts, fixed season api (again), fixed hydration issues
diff --git a/pages/api/season.js b/pages/api/season.js
index c3066cc..2603a52 100644
--- a/pages/api/season.js
+++ b/pages/api/season.js
@@ -2,6 +2,14 @@
return Math.floor((new Date().getTime() - date.getTime()) / (1000 * 60 * 60 * 24))
}
+function daysSinceDate(date) {
+ // If the date is after today, make it last year
+ if (date > new Date()) {
+ date.setFullYear(date.getFullYear() - 1);
+ }
+ return Math.floor((new Date().getTime() - date.getTime()) / (1000 * 60 * 60 * 24));
+}
+
function getSeason() {
let year = new Date().getFullYear();
@@ -10,7 +18,8 @@
halloween: [new Date(`${year}-10-25`), new Date(`${year}-11-1`)],
trans: [new Date(`${year}-11-13`), new Date(`${year}-11-19`)],
christmas: [new Date(`${year}-12-1`), new Date(`${year}-12-26`)],
- aprilFools: [new Date(`${year}-04-01`), new Date(`${year}-04-01`)]
+ aprilFools: [new Date(`${year}-04-01`), new Date(`${year}-04-01`)],
+ fake: [new Date(`${year}-01-01`), new Date(`${year}-01-01`)]
}
const filePaths = {
normal: "normal",
@@ -23,19 +32,19 @@
let current = new Date();
let currentSeason = Object.keys(dates).find((str) => current >= dates[str][0] && current <= dates[str][1]) || "normal";
- let daysIntoSeason;
+ let currentDaysIntoSeason;
if (currentSeason !== "normal") {
- daysIntoSeason = daysIntoSeason(dates[currentSeason][0])
+ currentDaysIntoSeason = daysIntoSeason(dates[currentSeason][0])
} else {
- // Calculate the days from the end of each season
- let days = Object.keys(dates).map((str) => daysIntoSeason(dates[str][1])).filter((num) => num > 0);
- daysIntoSeason = Math.min(...days);
+ // Calculate how many days it has been since each season ended
+ let days = Object.keys(dates).map((str) => daysSinceDate(dates[str][1]))
+ currentDaysIntoSeason = Math.min(...days);
}
return {
season: currentSeason,
filePath: filePaths[currentSeason],
- daysIntoSeason: daysIntoSeason
+ daysIntoSeason: currentDaysIntoSeason
}
}