Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 50s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 50s
This commit is contained in:
commit
4ea364672a
2 changed files with 28 additions and 0 deletions
|
|
@ -9,10 +9,14 @@ import error from "./middlewares/error";
|
||||||
import { AppDataSource } from "./database/data-source";
|
import { AppDataSource } from "./database/data-source";
|
||||||
import { RegisterRoutes } from "./routes";
|
import { RegisterRoutes } from "./routes";
|
||||||
import logMiddleware from "./middlewares/logs";
|
import logMiddleware from "./middlewares/logs";
|
||||||
|
import { DateSerializer } from "./interfaces/date-serializer";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await AppDataSource.initialize();
|
await AppDataSource.initialize();
|
||||||
|
|
||||||
|
// Setup custom Date serialization for local timezone
|
||||||
|
DateSerializer.setupDateSerialization();
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
|
|
|
||||||
24
src/interfaces/date-serializer.ts
Normal file
24
src/interfaces/date-serializer.ts
Normal file
|
|
@ -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");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue