Date and Time Handling Rules

Date and Time Handling Rules

Sets out a backend developer's rules for date and time handling: UTC instants, IANA zones, ISO 8601 APIs, half-open ranges and injected clocks.

Date and Time Handling taste of a backend developer who has debugged too many off-by-one-hour bugs

  • Store instants as UTC timestamps (timestamptz in PostgreSQL), never as local wall-clock time without an offset. Confidence: 0.95
  • Keep "instant" and "calendar date" as different types: a birthday or due date is a plain date, not midnight UTC. Confidence: 0.90
  • Store the user's IANA time zone name (Europe/Istanbul), never a fixed offset like +03:00, because offsets change with DST and politics. Confidence: 0.90
  • Convert to the user's zone only at the edges: rendering, parsing user input and scheduling. Confidence: 0.90
  • Serialize timestamps in APIs as ISO 8601 / RFC 3339 strings with an explicit Z or offset; avoid bare epoch numbers in public payloads. Confidence: 0.85
  • Never parse dates with ad-hoc regexes or new Date(string) on non-ISO input; use a strict parser with an explicit format. Confidence: 0.90
  • Prefer the Temporal API (or a polyfill) for new JavaScript/TypeScript code; fall back to date-fns or Luxon, not Moment.js. Confidence: 0.80
  • Format for humans with Intl.DateTimeFormat and the user's locale instead of hand-built strings. Confidence: 0.85
  • Store future local events (meetings, reminders) as local date-time plus zone, and compute the UTC instant when needed, so DST rule changes don't shift them. Confidence: 0.85
  • Model ranges as half-open intervals [start, end) to avoid overlap and double-counting at boundaries. Confidence: 0.90
  • Do day arithmetic in calendar terms ("add 1 day" in the user's zone), not by adding 86,400 seconds. Confidence: 0.85
  • Use a monotonic clock (performance.now(), time.monotonic()) for measuring durations and timeouts, never wall-clock time. Confidence: 0.95
  • Inject a clock dependency instead of calling Date.now() directly in business logic, so tests can freeze and advance time. Confidence: 0.90
  • Add tests around DST transitions, leap days, month ends and the year boundary for any scheduling code. Confidence: 0.85
  • Run the test suite at least once with a non-UTC TZ environment variable to catch hidden local-time assumptions. Confidence: 0.75
  • Keep server, database and container clocks in UTC and synced with NTP. Confidence: 0.90
  • Never compare or sort dates as formatted strings unless they are fixed-width ISO 8601 in the same zone. Confidence: 0.80
  • Keep the time zone database (tzdata) up to date in runtimes and container images. Confidence: 0.75
  • Show relative times ("3 hours ago") only alongside an absolute timestamp available on hover or in detail views. Confidence: 0.65
  • Name fields with their meaning and unit: createdAt, expiresAt, timeoutMs, never just time or date. Confidence: 0.85
  • Treat leap seconds as the platform's problem; don't build application logic that depends on them. Confidence: 0.70

Public domain (CC0 1.0) · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,389 prompts

More by @OpenSourceBuffGuy

See all
Suburban backyard where the sky falls prompt image

Suburban backyard where the sky falls

Generates a realistic handheld phone video of an ordinary backyard that is interrupted when the whole sky drops like a solid ceiling.

video-prompt, handheld, home-video, single-take, surreal, photorealistic, visual-effects, natural-light, hailuo, smartphone-photo, negative-prompt, candid, quick

Eight panel Nutella storyboard with pancake and jar scenes prompt image

Eight panel Nutella storyboard with pancake and jar scenes

Draws a single-page eight-panel storyboard for a premium chocolate-spread commercial, with scene cards, camera directions and macro food shots.

image-prompt, storyboard, food-photography, product-photography, advertising, multi-panel, macro, cinematic, studio-lighting, luxury, photorealistic, vertical-format, text-rendering, gpt-image, structured-output, timed-beats, cooking, infographic, bokeh, poster, video-ad, camera-movement

Nine expression portrait collage with film borders prompt image

Nine expression portrait collage with film borders

Edits an uploaded photo into a 9-frame photobooth portrait collage with a different playful expression in each frame, streetwear outfit and soft studio light.

image-prompt, gpt-image, chatgpt, reference-image, face-reference, photo-editing, collage, multi-panel, portrait, candid, close-up, studio-lighting, soft-lighting, white-background, fashion, editorial, vertical-format, film-grain, woman, photorealistic, muted-colors, fashion-shoot, long-form, for-photographers, for-content-creators, hairstyles

Reviews

Loading reviews…

Discussion

Loading comments…