This commit is contained in:
2022-12-03 03:10:46 +01:00
parent df3312a604
commit 46d6b1d991
86 changed files with 1078 additions and 0 deletions

31
js/times.js Normal file
View File

@@ -0,0 +1,31 @@
function calculateTimes() {
let now = new Date();
// Calculate the number of seasons (weeks) since the seed time.
let numberOfSeasonsPassed = Math.floor(Math.abs(
(now - winterStarts) / (7 * 24 * 60 * 60 * 1000)
));
let currentSeason = seasons[numberOfSeasonsPassed % 4];
// Calculate the next season.
let nextSeason = seasons[(numberOfSeasonsPassed + 1) % 4];
let nextSeasonStart = new Date(winterStarts);
nextSeasonStart.setDate(nextSeasonStart.getDate() + ((numberOfSeasonsPassed + 1) * 7));
// How much time until the next season.
let timeTilNextSeason = nextSeasonStart - now;
let days = Math.floor(timeTilNextSeason / (24 * 60 * 60 * 1000));
let hours = Math.floor((timeTilNextSeason / (60 * 60 * 1000)) - (days * 24));
let minutes = Math.floor((timeTilNextSeason / (60 * 1000)) - (hours * 60) - (days * 24 * 60));
let seconds = Math.floor((timeTilNextSeason / 1000) - (minutes * 60) - (hours * 60 * 60) - (days * 24 * 60 * 60));
return {
currentSeason,
nextSeason,
days,
hours,
minutes,
seconds
}
}