Make digital clock format configurable via CONFIG.timeFormat
This commit is contained in:
1 parent
66ca03ade4
commit
c2996e4762
2 files changed
+52
-6
No files matched your search
@@ -1,14 +1,19 @@
|
||||
/* Application configuration
|
||||
* debug - Show debug panel (0/1)
|
||||
* theme - Color palette: 'ash', 'gruvbox' or 'nord'
|
||||
* units - Measurement units: 'metric' or 'imperial'
|
||||
* language - UI language: 'de' or 'en'
|
||||
* debug - Show debug panel (0/1)
|
||||
* theme - Color palette: 'ash', 'gruvbox' or 'nord'
|
||||
* units - Measurement units: 'metric' or 'imperial'
|
||||
* language - UI language: 'de' or 'en'
|
||||
* timeFormat - ISO-8601-ish format string for the digital clock.
|
||||
* Date-only: YYYY, YYYY-MM, YYYY-MM-DD
|
||||
* Date-time: above + T + HH:mm, HH:mm:ss, HH:mm:ss.sss
|
||||
* Optional timezone offset (e.g. +02:00)
|
||||
*/
|
||||
window.CONFIG = {
|
||||
debug: 1,
|
||||
theme: 'ash',
|
||||
units: 'metric',
|
||||
language: 'en'
|
||||
language: 'en',
|
||||
timeFormat: 'HH:mm:ss'
|
||||
};
|
||||
|
||||
// List of available themes. The key is the theme id (used in config.theme),
|
||||
|
||||
+42
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user