local-iso-dt
Version:
Convert the most common types of dates into ISO8601/RFC3339-formatted YYYY-MM-DDTHH:MM:SS strings in the local timezone
23 lines (22 loc) • 578 B
JavaScript
;
exports.__esModule = true;
exports.localISOdt = void 0;
function localISOdt(d) {
if (!d)
d = new Date();
if (/^\d\d\d\d-\d\d-\d\d/.test(d))
return d;
if (/^\d+\.?\d*$/.test(d)) {
if (d < 4102512345)
d *= 1000;
if (d > 4102512345000)
d /= 1000;
if (d > 4102512345000)
d /= 1000;
}
if (!(d instanceof Date))
d = new Date(d);
return new Date(d.getTime() - d.getTimezoneOffset() * 60000)
.toISOString().slice(0, -5);
}
exports.localISOdt = localISOdt;