Basis Lab

Bytes, Text and File Formats

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.

FIG 1Which of the two each thing is
an instanta local readingneeds a zone stored with
when a payment was taken100
when a log line was writ100
a shop's closing time011
a date of birth010
a meeting in a calendar011
Coded 1 for yes and 0 for no. The first two rows are instants and need no zone, because the instant is zoneless by nature and a zone is only applied when it is displayed. The third and fifth need the zone stored, since a closing time or a meeting means a reading on a specific clock and loses its meaning without knowing which. The fourth is the odd one: a date of birth is a local date with no time at all, and storing it as an instant at midnight is the mistake that shifts it a day for anybody west of the storing server.

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 contents

This 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

The rest of this course

  1. 01Everything Is a Run of Bytes
  2. 02Counting in Twos and Sixteensopening only
  3. 03Letters as Numbersopening only
  4. 04Whole Numbers, and Where They Stopopening only
  5. 05Numbers With Fractions In Themopening only
  6. 06Dates, Times, and the Day It Movedyou are here
  7. 07Rows, Columns and the Separator Problemopening only
  8. 08Making It Smalleropening only

Read alongside