Make digital clock format configurable via CONFIG.timeFormat

This commit is contained in:
Richard Zink committed 2026-10-07 13:06:03 +02:00
1 parent 66ca03ade4
commit c2996e4762
2 files changed
+52 -6

No files matched your search

+42 -1
View File
@@ -808,6 +808,47 @@ var effect = (VANTA.CLOUDS2 || VANTA.CLOUDS)({
return (h < 10 ? '0' : '') + h + ':' + (m < 10 ? '0' : '') + m + ':' + (s < 10 ? '0' : '') + s;
}
function pad2(n) { return n < 10 ? '0' + n : '' + n; }
function pad3(n) { return n < 10 ? '00' + n : n < 100 ? '0' + n : '' + n; }
function formatDateTime(format, date) {
// Parse ISO-8601-ish format string and replace tokens with date values
var result = '';
var i = 0;
while (i < format.length) {
var ch = format.charAt(i);
if (ch === 'Y' && format.substr(i, 4) === 'YYYY') {
result += date.getFullYear();
i += 4;
} else if (ch === 'Y') {
result += date.getFullYear();
i += 1;
} else if (ch === 'M' && format.substr(i, 2) === 'MM') {
result += pad2(date.getMonth() + 1);
i += 2;
} else if (ch === 'D' && format.substr(i, 2) === 'DD') {
result += pad2(date.getDate());
i += 2;
} else if (ch === 'H' && format.substr(i, 2) === 'HH') {
result += pad2(date.getHours());
i += 2;
} else if (ch === 'm' && format.substr(i, 2) === 'mm') {
result += pad2(date.getMinutes());
i += 2;
} else if (ch === 's' && format.substr(i, 2) === 'ss') {
result += pad2(date.getSeconds());
i += 2;
} else if (ch === 's' && format.substr(i, 3) === 'sss') {
result += pad3(date.getMilliseconds());
i += 3;
} else {
result += ch;
i += 1;
}
}
return result;
}
function formatDateShort(date) {
var d = date.getDate();
var mo = date.getMonth() + 1;
@@ -1020,7 +1061,7 @@ var effect = (VANTA.CLOUDS2 || VANTA.CLOUDS)({
var m = now.getMinutes();
var s = now.getSeconds();
document.getElementById('digital-clock').textContent = formatTimeHMS(h, m, s);
document.getElementById('digital-clock').textContent = formatDateTime((window.CONFIG && window.CONFIG.timeFormat) || 'HH:mm:ss', now);
var hourAngle = ((h % 12) + m / 60) * 30;
var minuteAngle = (m + s / 60) * 6;