feat: add timezone offset to all API response meta

Every API response now includes:
  meta.timezone: 'UTC-06:00' (human-readable)
  meta.utcOffset: -6 (numeric, for client-side math)

Uses system time — no config needed.
This commit is contained in:
Brad Groux 2026-02-05 19:24:22 -06:00
parent db6d741b3f
commit 23a96d3ea7

View file

@ -36,6 +36,8 @@ export interface PaginationMeta {
interface EnvelopeMeta {
timestamp: string;
timezone: string;
utcOffset: number;
requestId?: string;
pagination?: PaginationMeta;
}
@ -108,8 +110,17 @@ export function responseEnvelopeMiddleware(_req: Request, res: Response, next: N
// Override res.json
res.json = function envelopedJson(data?: unknown): Response {
const now = new Date();
const offsetMinutes = now.getTimezoneOffset(); // positive = west of UTC
const offsetHours = -offsetMinutes / 60; // flip sign: CST = -6
const sign = offsetHours >= 0 ? '+' : '-';
const absH = String(Math.floor(Math.abs(offsetHours))).padStart(2, '0');
const absM = String(Math.abs(offsetMinutes) % 60).padStart(2, '0');
const meta: EnvelopeMeta = {
timestamp: new Date().toISOString(),
timestamp: now.toISOString(),
timezone: `UTC${sign}${absH}:${absM}`,
utcOffset: offsetHours,
};
// Include requestId if available (set by request-id middleware)