typia
Version:
Superfast runtime validators with only one line
26 lines • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._isFormatDateTime = void 0;
const _isFormatDate_1 = require("./_isFormatDate");
const _isFormatDateTime = (str) => {
const match = PATTERN.exec(str);
if (match === null || (0, _isFormatDate_1._isFormatDate)(match[1]) === false)
return false;
if (match[7] !== "60")
return true;
const instant = new Date(0);
instant.setUTCFullYear(Number(match[2]), Number(match[3]) - 1, Number(match[4]));
instant.setUTCHours(Number(match[5]), Number(match[6]), 0, 0);
const offset = match[8] === undefined
? 0
: (match[8] === "+" ? 1 : -1) *
(Number(match[9]) * 60 + Number(match[10]));
instant.setUTCMinutes(instant.getUTCMinutes() - offset);
return (instant.getUTCHours() === 23 &&
instant.getUTCMinutes() === 59 &&
((instant.getUTCMonth() === 5 && instant.getUTCDate() === 30) ||
(instant.getUTCMonth() === 11 && instant.getUTCDate() === 31)));
};
exports._isFormatDateTime = _isFormatDateTime;
const PATTERN = /^(([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))[Tt]((?:[01][0-9]|2[0-3])):([0-5][0-9]):([0-5][0-9]|60)(?:\.[0-9]+)?(?:[Zz]|([+-])((?:[01][0-9]|2[0-3])):([0-5][0-9]))$/;
//# sourceMappingURL=_isFormatDateTime.js.map