From 17f7fc5d845497b52c2e8a666b1ddb66649803e8 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Fri, 13 Feb 2026 17:45:44 +0700 Subject: [PATCH] fix registry employer Invalid time value --- src/interfaces/date-serializer.ts | 5 ++++- src/interfaces/extension.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/interfaces/date-serializer.ts b/src/interfaces/date-serializer.ts index 5c876ffc..b3f0c541 100644 --- a/src/interfaces/date-serializer.ts +++ b/src/interfaces/date-serializer.ts @@ -14,7 +14,10 @@ export class DateSerializer { static setupDateSerialization() { // Override Date.prototype.toJSON to use local time - Date.prototype.toJSON = function () { + Date.prototype.toJSON = function (): any { + // Check for Invalid Date - return null for invalid dates + if (isNaN(this.getTime())) return null; + const offset = 7 * 60; // Thailand timezone offset in minutes const localTime = new Date(this.getTime() + offset * 60 * 1000); const isoString = localTime.toISOString(); diff --git a/src/interfaces/extension.ts b/src/interfaces/extension.ts index ff6aeccb..405ed849 100644 --- a/src/interfaces/extension.ts +++ b/src/interfaces/extension.ts @@ -184,6 +184,7 @@ class Extension { } public static ToThaiFullDate(value: Date) { + if (value == null || value == undefined || isNaN(value.getTime())) return ""; let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear(); return ( "วันที่ " + @@ -195,11 +196,13 @@ class Extension { ); } public static ToThaiFullDate2(value: Date) { + if (value == null || value == undefined || isNaN(value.getTime())) return ""; let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear(); return value.getDate() + " " + Extension.ToThaiMonth(value.getMonth() + 1) + " " + yy; } public static ToThaiShortDate(value: Date) { + if (value == null || value == undefined || isNaN(value.getTime())) return ""; let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear(); return ( "วันที่ " + @@ -212,6 +215,7 @@ class Extension { } public static ToThaiShortDate_noPrefix(value: Date) { + if (value == null || value == undefined || isNaN(value.getTime())) return ""; let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear(); return ( value.getDate() + @@ -223,6 +227,7 @@ class Extension { } public static ToThaiShortDate_monthYear(value: Date) { + if (value == null || value == undefined || isNaN(value.getTime())) return ""; let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear(); return ( value.getDate() + " เดือน " + Extension.ToThaiMonth(value.getMonth() + 1) + " พ.ศ. " + yy @@ -230,11 +235,13 @@ class Extension { } public static ToThaiShortDate_monthYear2(value: Date) { + if (value == null || value == undefined || isNaN(value.getTime())) return ""; let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear(); return value.getDate() + " " + Extension.ToThaiMonth(value.getMonth() + 1) + " พ.ศ. " + yy; } public static ToThaiShortYear(value: Date) { + if (value == null || value == undefined || isNaN(value.getTime())) return ""; let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear(); return yy.toString(); } @@ -394,6 +401,7 @@ class Extension { } public static toDateOnlyString(date: Date): string { + if (date == null || date == undefined || isNaN(date.getTime())) return ""; return ( date.getFullYear() + "-" +