Fix Upload File Task #2264

This commit is contained in:
harid 2026-01-30 15:42:47 +07:00
parent 5d7c0e7ca5
commit 3a50a95e7c
2 changed files with 150 additions and 153 deletions

View file

@ -1,4 +1,46 @@
class Extension {
public static checkDateTime(value: any, format: "dd/MM/yyyy" | "yyyy-MM-dd"): Date | null {
if (value == null) return null;
let dateStr = String(value).trim();
if (!dateStr) return null;
const parts = dateStr.replace(/-/g, "/").split("/");
if (parts.length !== 3) return null;
let year = 0, month = 0, day = 0;
switch (format) {
case "dd/MM/yyyy":
year = Number(parts[2]);
month = Number(parts[1]);
day = Number(parts[0]);
break;
case "yyyy-MM-dd":
year = Number(parts[0]);
month = Number(parts[1]);
day = Number(parts[2]);
break;
}
if (isNaN(year) || isNaN(month) || isNaN(day)) return null;
// พ.ศ. → ค.ศ.
if (year > 2500) year -= 543;
// clamp month
if (month < 1 || month > 12) month = 1;
// clamp day
const maxDay = new Date(year, month, 0).getDate();
if (day < 1) day = 1;
else if (day > maxDay) day = maxDay;
const date = new Date(year, month - 1, day);
return isNaN(date.getTime()) ? null : date;
}
public static ToThaiMonth(value: number) {
switch (value) {
case 1: