40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
import State from '../core/state.js';
|
|
|
|
const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
|
|
function formatTime(date) {
|
|
let h = date.getHours();
|
|
const m = date.getMinutes().toString().padStart(2, '0');
|
|
const ampm = h >= 12 ? 'PM' : 'AM';
|
|
h = h % 12 || 12;
|
|
return `${h}:${m} ${ampm}`;
|
|
}
|
|
|
|
function formatDate(date) {
|
|
return `${DAYS[date.getDay()]}, ${MONTHS[date.getMonth()]} ${date.getDate()}`;
|
|
}
|
|
|
|
function updateClock() {
|
|
const now = new Date();
|
|
const timeEl = document.getElementById('clock-time');
|
|
const dateEl = document.getElementById('clock-date');
|
|
if (timeEl) timeEl.textContent = formatTime(now);
|
|
if (dateEl) dateEl.textContent = formatDate(now);
|
|
|
|
// Update login screen time
|
|
const loginTimeEl = document.getElementById('login-time');
|
|
if (loginTimeEl) loginTimeEl.textContent = formatTime(now);
|
|
|
|
// Update taskbar time
|
|
const statusTimeEl = document.getElementById('status-time');
|
|
if (statusTimeEl) statusTimeEl.textContent = formatTime(now);
|
|
}
|
|
|
|
function init() {
|
|
updateClock();
|
|
setInterval(updateClock, 1000);
|
|
}
|
|
|
|
init();
|