Strict ISO 8601 tokens: MM=month (always), mm=minute
This commit is contained in:
1 parent
2c0e84d267
commit
0bcb9878b1
2 files changed
+23
-21
No files matched your search
@@ -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
|
||||
|
||||
+13
-12
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user