Dates, Times, and the Day It Moved
Last timeNumbers With Fractions In Them
An instant and a local time are different things. Storing one when you meant the other is why a date is a day earlier for some users and not for others.
An instant and a local time
Two different things are both called a date and time, and keeping them apart
prevents most of the trouble in this lesson.
An instant is a single moment, the same moment everywhere. When a payment was
taken, when a server logged a line, when a message was sent. Everyone in the
world agrees it happened once, and they disagree only about what their own clock
said at the time.
A local time is a reading on a particular clock. A meeting at nine in the
morning, a shop that closes at six, a birthday on the fourteenth. These are not
instants: nine in the morning is a different moment in Berlin and in Chicago,
and that is not an error to be corrected but the meaning of the statement.
| an instant | a local reading | needs a zone stored with | |
|---|---|---|---|
| when a payment was taken | 1 | 0 | 0 |
| when a log line was writ | 1 | 0 | 0 |
| a shop's closing time | 0 | 1 | 1 |
| a date of birth | 0 | 1 | 0 |
| a meeting in a calendar | 0 | 1 | 1 |
The commonest error is a stored timestamp with no zone and no offset, which
looks like an instant and is not one. Two such values written by servers in
different places cannot be ordered, compared or subtracted correctly, and
nothing in the value says so.
Storing the instant
The storage form that removes all of this is a count of seconds from a fixed
origin, conventionally the start of 1970. It carries no zone, no calendar, no
month lengths and no daylight saving, and the whole of its meaning is how long
after the origin the moment is.
The lesson stops here
5 more paragraphs to go
You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.
The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.
See the planThe contentsThis is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents