แก้ error Undefined NaN ของ month-picker

This commit is contained in:
Warunee Tamkoo 2025-07-16 15:09:14 +07:00
parent 21ffca18bf
commit 11631b733b

View file

@ -225,7 +225,13 @@ export const useCounterMixin = defineStore("mixin", () => {
}
function monthYear2Thai(month: number, year: number, isFullMonth = false) {
const date = new Date(`${year}-${month + 1}-1`);
if (
month < 0 ||
month > 11 ||
!Number.isFinite(month) ||
!Number.isFinite(year)
)
return "";
const fullMonthThai = [
"มกราคม",
"กุมภาพันธ์",
@ -254,19 +260,12 @@ export const useCounterMixin = defineStore("mixin", () => {
"พ.ย.",
"ธ.ค.",
];
let dstYear = 0;
if (date.getFullYear() > 2500) {
dstYear = date.getFullYear();
} else {
dstYear = date.getFullYear() + 543;
}
let dstMonth = "";
if (isFullMonth) {
dstMonth = fullMonthThai[date.getMonth()];
} else {
dstMonth = abbrMonthThai[date.getMonth()];
}
return dstMonth + " " + dstYear;
// assume year is in BE if > 2500
let dstYear = year > 2500 ? year : year + 543;
// month is already 0-based
let dstMonth = isFullMonth ? fullMonthThai[month] : abbrMonthThai[month];
return `${dstMonth} ${dstYear}`;
}
function dateToISO(date: Date) {