Add full weekday/month names; evaluate \n and \t escapes in format
This commit is contained in:
1 parent
90730af49d
commit
86b2714b21
2 files changed
+57
-10
No files matched your search
+27
-3
@@ -824,27 +824,51 @@ var effect = (VANTA.CLOUDS2 || VANTA.CLOUDS)({
|
||||
// Any other character is a literal (including whitespace).
|
||||
//
|
||||
// Non-standard extension tokens (lookup in i18n dict):
|
||||
// DDD weekday short name (Mon., Tue., ...) from i18n
|
||||
// MMM month short name (January, February, ...) from i18n
|
||||
// DDD weekday short name (Mo., Tu., ...) from i18n
|
||||
// dddd weekday full name (Monday, Tuesday,...) from i18n
|
||||
// MMM month short name (Jan., Feb., ...) from i18n
|
||||
// MMMM month full name (January, ...) from i18n
|
||||
//
|
||||
// Escape sequences are also evaluated:
|
||||
// \n newline
|
||||
// \t tab
|
||||
// \\ literal backslash
|
||||
var result = '';
|
||||
var i = 0;
|
||||
var weekdayKeys = ['Su.', 'Mo.', 'Tu.', 'We.', 'Th.', 'Fr.', 'Sa.'];
|
||||
var weekdayFull = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||
var monthKeys = ['January', 'February', 'March', 'April', 'May', 'June',
|
||||
'July', 'August', 'September', 'October', 'November', 'December'];
|
||||
while (i < format.length) {
|
||||
var ch = format.charAt(i);
|
||||
// Handle escape sequences \n, \t, \\
|
||||
if (ch === '\\' && i + 1 < format.length) {
|
||||
var next = format.charAt(i + 1);
|
||||
if (next === 'n') result += '\n';
|
||||
else if (next === 't') result += '\t';
|
||||
else if (next === '\\') result += '\\';
|
||||
else result += ch + next;
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
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, 3) === 'MMM') {
|
||||
} else if (ch === 'M' && format.substr(i, 4) === 'MMMM') {
|
||||
result += t(monthKeys[date.getMonth()]);
|
||||
i += 4;
|
||||
} else if (ch === 'M' && format.substr(i, 3) === 'MMM') {
|
||||
result += t(monthKeys[date.getMonth()].substring(0, 3) + '.');
|
||||
i += 3;
|
||||
} else if (ch === 'M' && format.substr(i, 2) === 'MM') {
|
||||
result += pad2(date.getMonth() + 1);
|
||||
i += 2;
|
||||
} else if (ch === 'D' && format.substr(i, 4) === 'dddd') {
|
||||
result += t(weekdayFull[date.getDay()]);
|
||||
i += 4;
|
||||
} else if (ch === 'D' && format.substr(i, 3) === 'DDD') {
|
||||
result += t(weekdayKeys[date.getDay()]);
|
||||
i += 3;
|
||||
|
||||
Reference in new issue
Block a user