Skip to content

Commit 7c7bb25

Browse files
Bug Fixes
Fixed logic in the next session time calculation
1 parent 3b43b51 commit 7c7bb25

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

js/main.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,36 +67,43 @@ document.addEventListener('DOMContentLoaded', () => {
6767
if (nextSessionEl) {
6868
function updateNextSession() {
6969
var now = new Date();
70-
var day = now.getDay();
70+
var day = now.getDay(); // 0=Sun … 4=Thu … 6=Sat
7171
var hour = now.getHours();
72-
var sessionDuration = 2; // sessions last ~2 hours
72+
var sessionStart = 18;
73+
var sessionEnd = 20; // 18:00–20:00
7374

74-
// Check if it's Thursday during the session window (18:00–20:00)
75-
if (day === 4 && hour >= 18 && hour < 18 + sessionDuration) {
75+
// During the session window
76+
if (day === 4 && hour >= sessionStart && hour < sessionEnd) {
7677
nextSessionEl.textContent = 'Happening now!';
7778
return;
7879
}
7980

80-
// Find next Thursday 18:00
81+
// Build the target: next Thursday at 18:00
8182
var target = new Date(now);
82-
target.setHours(18, 0, 0, 0);
83-
var daysUntil = (4 - day + 7) % 7;
84-
// If it's Thursday but session is over, go to next week
85-
if (daysUntil === 0 && hour >= 18 + sessionDuration) daysUntil = 7;
83+
target.setHours(sessionStart, 0, 0, 0);
84+
85+
var daysUntil = (4 - day + 7) % 7; // 0 on Thursday
86+
if (daysUntil === 0 && hour >= sessionEnd) {
87+
daysUntil = 7; // session already ended today
88+
}
8689
target.setDate(target.getDate() + daysUntil);
8790

91+
// Whole-millisecond difference → days / hours / minutes
8892
var diff = target - now;
89-
var d = Math.floor(diff / 86400000);
90-
var h = Math.floor((diff % 86400000) / 3600000);
93+
var totalHours = Math.floor(diff / 3600000);
94+
var d = Math.floor(totalHours / 24);
95+
var h = totalHours % 24;
9196
var m = Math.floor((diff % 3600000) / 60000);
9297

93-
var isToday = now.toDateString() === target.toDateString();
94-
if (isToday) {
98+
// Pick a friendly label
99+
if (d === 0) {
95100
nextSessionEl.textContent = 'Today in ' + h + 'h ' + m + 'm';
96-
} else if (daysUntil === 1) {
97-
nextSessionEl.textContent = 'Tomorrow at 18:00';
101+
} else if (d === 1 && h === 0 && m === 0) {
102+
nextSessionEl.textContent = 'Tomorrow at ' + sessionStart + ':00';
103+
} else if (d === 1) {
104+
nextSessionEl.textContent = 'Tomorrow at ' + sessionStart + ':00';
98105
} else {
99-
nextSessionEl.textContent = 'Next session in ' + d + 'd ' + h + 'h';
106+
nextSessionEl.textContent = 'Next Thursday in ' + d + 'd ' + h + 'h';
100107
}
101108
}
102109
updateNextSession();

0 commit comments

Comments
 (0)