From 0bcb9878b19964fc0cfe7f744d31b21718117dd9 Mon Sep 17 00:00:00 2001 From: Richard Zink Date: Wed, 7 Oct 2026 13:14:45 +0200 Subject: [PATCH] Strict ISO 8601 tokens: MM=month (always), mm=minute --- config.js | 19 ++++++++++--------- index.html | 25 +++++++++++++------------ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/config.js b/config.js index 27e43b2..841979a 100644 --- a/config.js +++ b/config.js @@ -13,23 +13,24 @@ * window.TRANSLATIONS in i18n.js. English ('en') is the base; * if a key is missing in the current language, English is used. * - * timeFormat - Format string for the digital clock, using ISO-8601-ish - * tokens. Any character that is not a token is treated as a - * literal (including whitespace). + * timeFormat - Format string for the digital clock, using strict + * ISO 8601 tokens (case-sensitive). Any other character is + * treated as a literal (including whitespace). * * YYYY 4-digit year (2026) - * MM month 01-12 (10) + * MM month 01-12 (10) - always month * DD day 01-31 (07) * HH hour 00-23 (24h) (14) - * hh hour 01-12 (12h) (02) - * a AM / PM (PM) - * mm minute 00-59 (35) - * ss second 00-59 (22) + * mm minute 00-59 (35) - lowercase! + * ss second 00-59 (22) - lowercase! * sss millisecond 000-999 (456) + * T literal 'T' * * Date-only forms: YYYY, YYYY-MM, YYYY-MM-DD * Date-time forms: above + T + HH:mm, HH:mm:ss, HH:mm:ss.sss - * Any other character is a literal (incl. spaces). + * Any other character is a literal (incl. spaces, tabs, \n). + * + * Note: MM is ALWAYS month (ISO). For minutes use mm (lowercase). * * Examples: * 'HH:mm:ss' -> 14:35:22 diff --git a/index.html b/index.html index a937142..7427d81 100644 --- a/index.html +++ b/index.html @@ -812,7 +812,16 @@ var effect = (VANTA.CLOUDS2 || VANTA.CLOUDS)({ 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 + // Strict ISO 8601 format tokens (case-sensitive): + // YYYY 4-digit year (2026) + // MM month 01-12 (10) -- always month, never minute + // DD day 01-31 (07) + // HH hour 00-23 (14) + // mm minute 00-59 (35) -- lowercase + // ss second 00-59 (22) -- lowercase + // sss millisecond 000-999 (456) + // T literal 'T' + // Any other character is a literal (including whitespace). var result = ''; var i = 0; while (i < format.length) { @@ -832,23 +841,15 @@ var effect = (VANTA.CLOUDS2 || VANTA.CLOUDS)({ } else if (ch === 'H' && format.substr(i, 2) === 'HH') { result += pad2(date.getHours()); i += 2; - } else if (ch === 'h' && format.substr(i, 2) === 'hh') { - var h12 = date.getHours() % 12; - if (h12 === 0) h12 = 12; - result += pad2(h12); - i += 2; - } else if (ch === 'a') { - result += date.getHours() < 12 ? 'AM' : 'PM'; - i += 1; } 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 if (ch === 's' && format.substr(i, 2) === 'ss') { + result += pad2(date.getSeconds()); + i += 2; } else { result += ch; i += 1;