typia
Version:
Superfast runtime validators with only one line
27 lines (26 loc) • 571 B
JavaScript
//#region src/internal/_isFormatDate.ts
const _isFormatDate = (str) => {
const match = PATTERN.exec(str);
if (match === null) return false;
const year = Number(match[1]);
const month = Number(match[2]);
return Number(match[3]) <= DAYS[month - 1] + (month === 2 && (year % 400 === 0 || year % 4 === 0 && year % 100 !== 0) ? 1 : 0);
};
const PATTERN = /^([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;
const DAYS = [
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
];
//#endregion
export { _isFormatDate };
//# sourceMappingURL=_isFormatDate.mjs.map