From e6329e7922f55bd511b7de4487253b6092a481f3 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Wed, 22 Oct 2025 23:20:18 +0700 Subject: [PATCH] update timezone --- src/app.ts | 4 ++++ src/interfaces/date-serializer.ts | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/interfaces/date-serializer.ts diff --git a/src/app.ts b/src/app.ts index 236fb105..7f0e0220 100644 --- a/src/app.ts +++ b/src/app.ts @@ -13,12 +13,16 @@ import { OrganizationController } from "./controllers/OrganizationController"; import logMiddleware from "./middlewares/logs"; import { CommandController } from "./controllers/CommandController"; import { ProfileSalaryController } from "./controllers/ProfileSalaryController"; +import { DateSerializer } from "./interfaces/date-serializer"; import { initWebSocket } from "./services/webSocket"; async function main() { await AppDataSource.initialize(); + // Setup custom Date serialization for local timezone + DateSerializer.setupDateSerialization(); + initWebSocket(); const app = express(); diff --git a/src/interfaces/date-serializer.ts b/src/interfaces/date-serializer.ts new file mode 100644 index 00000000..5c876ffc --- /dev/null +++ b/src/interfaces/date-serializer.ts @@ -0,0 +1,24 @@ +// Custom Date serializer for local timezone +export class DateSerializer { + static toLocalTime(date: Date): string | null { + if (!date) return null; + + // Convert UTC date to Thailand timezone (+07:00) + const offset = 7 * 60; // Thailand is UTC+7 + const localTime = new Date(date.getTime() + offset * 60 * 1000); + + // Format as ISO string but replace Z with +07:00 + const isoString = localTime.toISOString(); + return isoString.replace("Z", "+07:00"); + } + + static setupDateSerialization() { + // Override Date.prototype.toJSON to use local time + Date.prototype.toJSON = function () { + const offset = 7 * 60; // Thailand timezone offset in minutes + const localTime = new Date(this.getTime() + offset * 60 * 1000); + const isoString = localTime.toISOString(); + return isoString.replace("Z", "+07:00"); + }; + } +}