mirror of
https://github.com/BradGroux/veritas-kanban.git
synced 2026-10-07 04:07:50 +00:00
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:
parent
db6d741b3f
commit
23a96d3ea7
1 changed files with 12 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue