Skip to content

Storing a Birthday

Storing a Birthday

A user's birthday is March 15. How do you store it so it always means March 15, no matter where the user travels?

The naive approach

// The naive approach: store as a full datetime in UTC
const birthday = new Date("2024-03-15T00:00:00Z");
// In New York that is March 14 at 8 PM — the wrong local date!
console.log(birthday.toLocaleString("en-US", { timeZone: "America/New_York" }));

Watch it break

The naive approach silently produces wrong results — there is no GMT equivalent to demonstrate because the failure is not using GMT.

Why

A birthday is a *calendar date*, not an instant in time. Storing it as a UTC datetime ties it to a specific moment, which shifts when viewed from a different timezone. GMT's plain date functions (`PlainDate`) are timezone-free by design — "2024-03-15" is March 15 everywhere.

The gmt approach

import { addDays } from "@northguild/gmt";

const birthday = "2024-03-15";
const nextYear = addDays(birthday, 365);
// "2025-03-15" — same calendar date, no timezone ambiguity

Same widget, working