Initial commit — Meridian OS browser desktop demo
This commit is contained in:
39
js/widgets/clock.js
Normal file
39
js/widgets/clock.js
Normal file
@@ -0,0 +1,39 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user