Molochou
← All notes

Timezones and the deadline that drifts

Put deadlines on a month grid and you will meet this bug. A card is due on the twelfth. Someone opens the board from another country and it sits on the eleventh. Nobody typed anything wrong. Both screens are showing the truth about different questions.

Two different things called a date

An instant is a point on the world's timeline. It is the same instant for everyone, and what it is called depends on where you are standing. Nine in the evening in one place is the following morning in another.

A calendar day is a label people agree on locally. "Due Friday" does not mean a moment. It means a square on a grid, and it is the same square regardless of who is looking.

Almost every date library, database column and API default gives you the first one. Almost every deadline a person types is the second one. The bug is that conversion, and it is silent, because the value is never wrong by much. It is wrong by one square, at the boundary, for some of your users.

Where it actually goes wrong

Not in storage. Storage is easy once you have decided.

It goes wrong at the edges, in the places where a conversion happens without anybody choosing it. A date picker that hands back midnight local time and gets serialised to UTC. A server that formats a day for an email using its own timezone, which is whatever the container was built with. A comparison that asks whether a deadline has passed by comparing it to right now, when the question a person is actually asking is whether today is past that square.

Each of these is one line, each of them is defensible on its own, and together they produce a deadline that drifts depending on who opens the board.

The rule I settle on

If the thing is a moment, store a moment: created, edited, sent. These are real points in time and converting them for display is correct behaviour.

If the thing is a day a person picked, store a day. A plain calendar date with no time and no zone attached, because attaching one is inventing information the person never gave you. "Due the twelfth" carries no hour, and the moment you add midnight to it you have made something up and then converted your invention.

Overdue then means comparing today's date in the reader's own calendar against that day. Two labels, one comparison, nothing converted.

It sounds pedantic until the first time somebody misses a deadline the interface showed them a day early.