diff --git a/src/config/env.ts b/src/config/env.ts index 402f6b7..55312be 100644 --- a/src/config/env.ts +++ b/src/config/env.ts @@ -4,6 +4,20 @@ dotenv.config(); // Set timezone for Date operations — all attendance/time records are in Czech local time process.env.TZ = process.env.TZ || 'Europe/Prague'; +// Override Date.toJSON to serialize as local time instead of UTC +// MySQL DATETIME stores local time, Prisma creates Date objects, +// JSON.stringify calls toJSON() which defaults to toISOString() (UTC with Z suffix). +// This causes times to shift by timezone offset on the frontend. +Date.prototype.toJSON = function () { + const y = this.getFullYear(); + const m = String(this.getMonth() + 1).padStart(2, '0'); + const d = String(this.getDate()).padStart(2, '0'); + const h = String(this.getHours()).padStart(2, '0'); + const min = String(this.getMinutes()).padStart(2, '0'); + const s = String(this.getSeconds()).padStart(2, '0'); + return `${y}-${m}-${d}T${h}:${min}:${s}`; +}; + function required(key: string): string { const val = process.env[key]; if (!val) throw new Error(`Missing required env variable: ${key}`);