summary refs log tree commit diff
path: root/v2/strftime.js
diff options
context:
space:
mode:
authorwlodekm <[email protected]>2024-11-15 09:46:47 +0200
committerwlodekm <[email protected]>2024-11-15 09:46:47 +0200
commitd28d8333ebe71e2937660b13d9afb1d516cf14f0 (patch)
tree6c941712ec80b785a940b37aec52b2cea7861835 /v2/strftime.js
parentd51dbb974d83125f4bfb017188de6a013b7f746c (diff)
v1.0.2
Diffstat (limited to 'v2/strftime.js')
-rw-r--r--v2/strftime.js92
1 files changed, 0 insertions, 92 deletions
diff --git a/v2/strftime.js b/v2/strftime.js
deleted file mode 100644
index ecc3f77..0000000
--- a/v2/strftime.js
+++ /dev/null
@@ -1,92 +0,0 @@
-/* Port of strftime(). Compatibility notes:
- *
- * %c - formatted string is slightly different
- * %D - not implemented (use "%m/%d/%y" or "%d/%m/%y")
- * %e - space is not added
- * %E - not implemented
- * %h - not implemented (use "%b")
- * %k - space is not added
- * %n - not implemented (use "\n")
- * %O - not implemented
- * %r - not implemented (use "%I:%M:%S %p")
- * %R - not implemented (use "%H:%M")
- * %t - not implemented (use "\t")
- * %T - not implemented (use "%H:%M:%S")
- * %U - not implemented
- * %W - not implemented
- * %+ - not implemented
- * %% - not implemented (use "%")
- *
- * strftime() reference:
- * http://man7.org/linux/man-pages/man3/strftime.3.html
- *
- * Day of year (%j) code based on Joe Orost's answer:
- * http://stackoverflow.com/questions/8619879/javascript-calculate-the-day-of-the-year-1-366
- *
- * Week number (%V) code based on Taco van den Broek's prototype:
- * http://techblog.procurios.nl/k/news/view/33796/14863/calculate-iso-8601-week-and-year-in-javascript.html
- */
-export default function strftime(sFormat, date) {
-    if (!(date instanceof Date)) date = new Date();
-    let nDay = date.getDay(),
-        nDate = date.getDate(),
-        nMonth = date.getMonth(),
-        nYear = date.getFullYear(),
-        nHour = date.getHours(),
-        aDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
-        aMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
-        aDayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334],
-        isLeapYear = function () {
-            return (nYear % 4 === 0 && nYear % 100 !== 0) || nYear % 400 === 0;
-        },
-        getThursday = function () {
-            let target = new Date(date);
-            target.setDate(nDate - ((nDay + 6) % 7) + 3);
-            return target;
-        },
-        zeroPad = function (nNum, nPad) {
-            return ('' + (Math.pow(10, nPad) + nNum)).slice(1);
-        };
-    return sFormat.replace(/%[a-z]/gi, function (sMatch) {
-        return {
-            '%a': aDays[nDay].slice(0, 3),
-            '%A': aDays[nDay],
-            '%b': aMonths[nMonth].slice(0, 3),
-            '%B': aMonths[nMonth],
-            '%c': date.toUTCString(),
-            '%C': Math.floor(nYear / 100),
-            '%d': zeroPad(nDate, 2),
-            '%e': nDate,
-            '%F': date.toISOString().slice(0, 10),
-            '%G': getThursday().getFullYear(),
-            '%g': ('' + getThursday().getFullYear()).slice(2),
-            '%H': zeroPad(nHour, 2),
-            '%I': zeroPad((nHour + 11) % 12 + 1, 2),
-            '%j': zeroPad(aDayCount[nMonth] + nDate + ((nMonth > 1 && isLeapYear()) ? 1 : 0), 3),
-            '%k': '' + nHour,
-            '%l': (nHour + 11) % 12 + 1,
-            '%m': zeroPad(nMonth + 1, 2),
-            '%M': zeroPad(date.getMinutes(), 2),
-            '%p': (nHour < 12) ? 'AM' : 'PM',
-            '%P': (nHour < 12) ? 'am' : 'pm',
-            '%s': Math.round(date.getTime() / 1000),
-            '%S': zeroPad(date.getSeconds(), 2),
-            '%u': nDay || 7,
-            '%V': (function () {
-                let target = getThursday(),
-                    n1stThu = target.valueOf();
-                target.setMonth(0, 1);
-                let nJan1 = target.getDay();
-                if (nJan1 !== 4) target.setMonth(0, 1 + ((4 - nJan1) + 7) % 7);
-                return zeroPad(1 + Math.ceil((n1stThu - target) / 604800000), 2);
-            })(),
-            '%w': '' + nDay,
-            '%x': date.toLocaleDateString(),
-            '%X': date.toLocaleTimeString(),
-            '%y': ('' + nYear).slice(2),
-            '%Y': nYear,
-            '%z': date.toTimeString().replace(/.+GMT([+-]\d+).+/, '$1'),
-            '%Z': date.toTimeString().replace(/.+\((.+?)\)$/, '$1')
-        }[sMatch] || sMatch;
-    });
-}
\ No newline at end of file