import { NextResponse } from "next/server"; const TZ = "Asia/Kolkata"; /** * GET /api/time * Returns the server's current time in IST. The app can call this to verify * that the user's device clock matches the server, and to use a trusted * timestamp source for log entries if needed. * * No auth required — time is not sensitive. */ export async function GET() { const now = new Date(); const istDate = now.toLocaleDateString("sv-SE", { timeZone: TZ }); // YYYY-MM-DD const istTime = now.toLocaleTimeString("en-IN", { timeZone: TZ, hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false, }); const istLabel = now.toLocaleString("en-IN", { timeZone: TZ, weekday: "short", day: "numeric", month: "short", year: "numeric", hour: "2-digit", minute: "2-digit", hour12: true, }); return NextResponse.json( { utc: now.toISOString(), // e.g. "2026-05-28T09:00:00.000Z" istDate, // e.g. "2026-05-28" istTime, // e.g. "14:30:00" ist: istLabel, // e.g. "Wed, 28 May 2026, 02:30 PM" offsetMinutes: 330, // IST = UTC +5:30 }, { headers: { // Do not cache — always return live server time "Cache-Control": "no-store", }, } ); }