UNPKG

@mbc-cqrs-serverless/core

Version:
47 lines 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toISOString = toISOString; exports.toISOStringWithTimezone = toISOStringWithTimezone; exports.isISOString = isISOString; exports.isISOStringWithTimezone = isISOStringWithTimezone; function toISOString(date) { if (!date) { return undefined; } return date.toISOString(); } function toISOStringWithTimezone(date) { if (!date) { return undefined; } return (date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) + 'T' + pad(date.getHours()) + ':' + pad(date.getMinutes()) + ':' + pad(date.getSeconds()) + getTimezoneOffset(date)); } function isISOString(val) { const d = new Date(val); return !Number.isNaN(d.valueOf()) && d.toISOString() === val; } function isISOStringWithTimezone(val) { const d = new Date(val); return !Number.isNaN(d.valueOf()) && toISOStringWithTimezone(d) === val; } function pad(n) { return `${Math.floor(Math.abs(n))}`.padStart(2, '0'); } // Get timezone offset in ISO format (+hh:mm or -hh:mm) function getTimezoneOffset(date) { const tzOffset = -date.getTimezoneOffset(); const diff = tzOffset >= 0 ? '+' : '-'; return diff + pad(tzOffset / 60) + ':' + pad(tzOffset % 60); } //# sourceMappingURL=datetime.js.map