MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / parseDate

Function parseDate

modules/crypt/etc/x509.js:208–227  ·  view source on GitHub ↗
(date)

Source from the content-addressed store, hash-verified

206Object.freeze(X509);
207
208function parseDate(date) {
209 if (!date.endsWith("Z"))
210 throw new Error("unexpected timezone");
211
212 const parts = [];
213 if (13 === date.length) {
214 for (let i = 0, length = date.length; (i + 1) < length; i += 2)
215 parts.push(parseInt(date.slice(i, i + 2)));
216 parts[0] += (parts[0] < 50) ? 2000 : 1900;
217 }
218 else if (15 === date.length) {
219 parts.push(parseInt(date.slice(0, 4)));
220 for (let i = 4, length = date.length; (i + 1) < length; i += 2)
221 parts.push(parseInt(date.slice(i, i + 2)));
222 }
223 else
224 throw new Error("unexpected date");
225 parts[1] -= 1;
226 return Date.UTC.apply(null, parts);
227}
228
229export default X509;

Callers 1

decodeTBSFunction · 0.85

Calls 2

sliceMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected