{"success":true,"name":"store-time-in-utc-once-convert-only-at-the-screen","description":"Saving, comparing, or displaying dates and times anywhere in the stack","category":"ai-brimind","path":"ai-brimind/store-time-in-utc-once-convert-only-at-the-screen/SKILL.md","file":"SKILL.md","content":"---\nname: store-time-in-utc-once-convert-only-at-the-screen\ndescription: \"Saving, comparing, or displaying dates and times anywhere in the stack\"\n---\n\n# Store Time in UTC Once, Convert Only at the Screen\n\n## When to use\nYou are writing code that saves a date/time to the DB, compares dates (deadlines, 'today', expiry), or displays a time to users, and no explicit decision exists about timezones — things just use whatever the server or browser happens to be set to.\n\n## Example request\nBooking saved as the string '03/07/2026 14:00' → is that 2 PM where? Strings lose the timezone forever; store a real Date/timestamp (UTC) and the ambiguity dies. 'Show today's orders' compares server-local midnight to stored dates → the day boundary is wrong for every user not in the server's timezone; 'today' is a user-side concept computed from THEIR offset. Deadline checks pass on your machine, fail on the deployed server → the two machines sit in different timezones; UTC everywhere in storage and logic makes both machines agree. Displaying raw UTC to the user → correct but unreadable; conversion to local time belongs at the last step, in the display layer, using the date tools the platform provides.\n\n## Instructions\nAct as a developer who treats time as the sneakiest data type in the stack — bugs hide for months and explode only for the user in another country or the night the clocks change. For any code touching dates, do this: (1) Apply the one golden rule and say it: STORE and COMPUTE in UTC, CONVERT at the display edge. The database holds real timestamp/Date values (Mongo Dates are UTC by nature; in SQL prefer the timezone-aware timestamp type) — never formatted strings like '03/07/2026', which amputate the timezone and can't be compared or sorted reliably. (2) When saving 'now', use the platform's UTC now — not a hand-formatted local string. When saving a user-chosen time (a booking at '14:00'), be explicit about WHOSE 14:00 it is and convert it to UTC at the border, once. (3) For logic like 'expired?', 'before deadline?', compare UTC to UTC — two absolute instants — never formatted strings. For 'today/this week' style ranges, notice the trap out loud: a 'day' depends on the viewer's timezone, so compute the range from the user's offset, not the server's midnight. (4) Convert to local time only in the frontend display layer, using the environment's built-ins (toLocaleString / Intl on the web, or the date library the project already uses — check before adding a new one; formatting dates is a solved problem). (5) Distrust your dev machine as evidence: it shares YOUR timezone, so it hides these bugs by construction — test with the clock/timezone changed or values near midnight. Only move on once you can trace one date in your change from input → storage → comparison → display and name the timezone it is in at each step; if any step answers 'whatever the machine happens to use', that step is the bug waiting.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #200\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}