Strict ISO 8601 tokens: MM=month (always), mm=minute

This commit is contained in:
Richard Zink committed 2026-10-07 13:14:45 +02:00
1 parent 2c0e84d267
commit 0bcb9878b1
2 files changed
+23 -21

No files matched your search

+13 -12
View File
@@ -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;