(Note · · 6 min read)

The attendance report is wrong for one office

A system works perfectly for one office and produces wrong numbers for the second one. A shift that starts at eleven at night belongs to one day in one report and a different day in another, and nobody can say which is correct because the question was never decided.

By Md. Habibur Rahman Shohel, full-stack & AI product engineer in Dhaka

Store the instant, keep the zone separately

Store the moment something happened as an absolute instant, in a column that carries a zone, and let the database handle the conversion. Storing local time with no zone makes the value unreadable later: nobody can reconstruct which offset applied.

But the instant alone is not enough. Keep the zone the event belongs to — the office's zone, the customer's zone — because that is what decides which day and which shift it falls in. Two records with the same instant can belong to different days.

A date is not a timestamp

Some values are genuinely instants: a clock-in, a payment, a log entry. Others are calendar values with no instant attached — a birthday, a contract start date, a public holiday. Storing those as timestamps gives them a time, and that time shifts across zones until the date itself changes.

Use a plain date column for calendar facts. A date of birth that moves by a day for users in another region is this mistake, and nothing else.

Decide what a day means, in writing

For an attendance or booking system this is the central decision, not a detail: does a day run from midnight in the office's zone, or from a shift boundary, and which day does an overnight shift belong to? Answer it once, in one place in the code, and have every report use that function.

When each report derives the day itself, they diverge — and the divergence is discovered by somebody comparing two screens and losing confidence in both.

Convert at the edges, work in absolutes

Convert to local time when displaying and when interpreting input, and keep everything in between absolute. The common bug is the opposite: converting early, then doing arithmetic on local values, where adding twenty-four hours is not reliably the next day.

Use a zone identifier such as Asia/Dhaka rather than a fixed offset. An offset is a fact about one moment, not about a place, and a place whose rules change leaves stored offsets wrong.

Recurring events are rules, not copies

A weekly shift at nine in the morning means nine local, including after a clock change. Storing a list of precomputed instants means every one of them drifts when the rules move. Store the rule — the local time, the zone, the recurrence — and compute instants as needed.

Where a clock change makes a local time ambiguous or non-existent, the behaviour has to be chosen rather than left to whichever library is in use.

Set the server's zone and stop relying on it

Code that depends on the server's local zone behaves differently on a developer machine, in the test run and in production. Set servers to a single zone, and then write code that never reads it: pass the relevant zone explicitly wherever a day boundary is computed.

Test with a zone that is not your own, and with one whose offset is not a whole number of hours. A system that only works in the zone where it was written is a system that has one customer.

Common questions

How should timestamps be stored in a multi-region app?

As absolute instants in a zone-aware column, with the zone the event belongs to stored separately. The instant says when it happened; the zone decides which day and shift it falls in, and two records with the same instant can belong to different days.

Why does a date of birth shift by a day for some users?

Because it was stored as a timestamp. A calendar value with no instant attached — a birthday, a contract date, a holiday — belongs in a plain date column, or it acquires a time that shifts across zones until the date changes.

Should recurring schedules be stored as precomputed times?

No. Store the rule — local time, zone and recurrence — and compute instants when needed. A list of precomputed instants drifts whenever a zone's rules change, and the behaviour at an ambiguous or non-existent local time must be chosen explicitly.

Why use a zone name rather than an offset?

An offset is a fact about one moment, not about a place. A zone identifier like Asia/Dhaka stays correct when a region's rules change, whereas stored offsets silently become wrong.

Need something like this built?