fix validate date in mixin (function dateToISO)

This commit is contained in:
Warunee Tamkoo 2023-09-22 17:33:18 +07:00
parent f81d520cec
commit 32a68116dc

View file

@ -244,13 +244,17 @@ export const useCounterMixin = defineStore("mixin", () => {
}
function dateToISO(date: Date) {
return (
date.getFullYear() +
"-" +
appendLeadingZeroes(date.getMonth() + 1) +
"-" +
appendLeadingZeroes(date.getDate())
);
const isValidDate = Boolean(+date);
if (!isValidDate) return null;
if (isValidDate && date.getFullYear() < 1000) {
return (
date.getFullYear() +
"-" +
appendLeadingZeroes(date.getMonth() + 1) +
"-" +
appendLeadingZeroes(date.getDate())
);
}
}
function appendLeadingZeroes(n: number) {