diff --git a/web/index.html b/web/index.html index 54f7eb3..ac28463 100644 --- a/web/index.html +++ b/web/index.html @@ -140,7 +140,38 @@ const DIRECTIONS = { const DAYS = ["воскресенье","понедельник","вторник","среда","четверг","пятница","суббота"]; function toMin(t){ const [h,m]=t.split(":").map(Number); return h*60+m; } -function nowMs(){ return new Date(Date.now()+3*3600*1000); } // МСК = UTC+3 + +// Текущее время по МСК, независимо от часового пояса устройства +const MSK_TZ = "Europe/Moscow"; +let mskFmt = null; +try { + mskFmt = new Intl.DateTimeFormat("en-US", { + timeZone: MSK_TZ, hourCycle: "h23", + year: "numeric", month: "2-digit", day: "2-digit", + hour: "2-digit", minute: "2-digit", second: "2-digit" + }); +} catch(e){ mskFmt = null; } + +function nowMs(){ + if (mskFmt) { + try { + const parts = {}; + mskFmt.formatToParts(new Date()).forEach(x => parts[x.type] = x.value); + const hour = Number(parts.hour) % 24; // на части движков полночь приходит как "24" + return { + hour: hour, + minute: Number(parts.minute), + second: Number(parts.second), + day: new Date(Date.UTC(Number(parts.year), Number(parts.month) - 1, + Number(parts.day))).getUTCDay() + }; + } catch(e){ /* ниже — запасной вариант */ } + } + // Запасной вариант: МСК = UTC+3 (переход на летнее время отменён) + const d = new Date(Date.now() + 3*3600*1000); + return { hour: d.getUTCHours(), minute: d.getUTCMinutes(), + second: d.getUTCSeconds(), day: d.getUTCDay() }; +} function fmtWait(m){ if(m <= 0) return "отправление сейчас"; @@ -154,7 +185,7 @@ let currentStop = "Полярные Зори"; function render(){ const now = nowMs(); - const curMin = now.getHours()*60 + now.getMinutes(); + const curMin = now.hour*60 + now.minute; const dirs = DIRECTIONS[currentStop]; document.getElementById("dirBox").innerHTML = dirs.map(d=>{ const upcoming = SCHEDULE @@ -185,14 +216,14 @@ function renderTable(){ } function renderDay(){ - const dow = nowMs().getDay(); + const dow = nowMs().day; document.getElementById("dayBadge").innerHTML = `Сегодня ${DAYS[dow]}`; } function tickClock(){ const d = nowMs(); const p = n=>String(n).padStart(2,"0"); - document.getElementById("clock").innerHTML = `${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())} МСК`; + document.getElementById("clock").innerHTML = `${p(d.hour)}:${p(d.minute)}:${p(d.second)} МСК`; } document.querySelectorAll(".pick").forEach(btn=>{