Time Is Cursed Because We Are Cursed

I’ve never met an engineer that had positive things to say about time. Whether how fast it was passing and bringing their deadlines closer or, more frequently, about how carefully you need to hold it while building systems.

We talk a lot, as engineers, about time being cursed. We talk substantially less about why it’s cursed, and—more to the point—how to understand it so you can teach computers about it.

So today I want to talk about time, and how the real curse was us all along.

What is time?

Time is one of those things we all intuitively understand until the exact moment we need to explain them clearly enough that a computer can understand them, like names or addresses or money. Then we realize we never understood them at all.

When talking about time, we could be talking about any of a number of separate measurement systems we’ve duct-taped together haphazardly:

Whenever we talk about years, we’re talking about where the earth is in relation to the sun. Humans care about this because it turns out that the sun is kinda important for farming, and farming is kinda important for civilization as we know it. We would like to be able to grow crops and not starve, and that means being aware of the seasons and our passage through them, which means keeping track of where we are in relation to the sun, which is what gives us seasons.

Whenever we talk about months or weeks, we’re talking about where the moon is in relation to earth. A year is a long period of time, and we needed to be able to track where we were in it. Fortunately, the moon has easily-tracked phases that repeat throughout the year, and we can use that to subdivide the solar year. Unfortunately, those easily-tracked phases don’t match exactly to a solar year; there are about 12.37 moon cycles in a year. Whoops. We’ve smoothed over this problem by just making months have different numbers of days.

But wait, there are 365.25 days1 in a year, and 365.25 divided by 12.37 is about 29.5 days per lunar cycle. So we need a different number of days in a month, but why do we have 28, 30, 31, and sometimes 29 day months? Why not just have 29 days in the first month, then 30 days in the next, and so on? There’s a long answer to this that involves some contradictory and disputed history and I’ve tried typing it up a few times only to give up trying to summarize it while maintaining accuracy. It doesn’t matter, the short version is it’s the Romans’ fault, and then Pope Gregory XIII formalized it and now we’re stuck with it until someone decides to change it.

Anyways, back to periods of time. For days, we base those on the earth’s rotation on its axis. Because that determines what part of the world the sun is shining on, and where the sun is shining turns out to be important for animals. Unfortunately, orbital mechanics are inconsiderate and uncooperative, and the amount of time it takes earth to spin one complete rotation around its axis is not a clean fraction of the amount of time it takes earth to orbit the sun. So we get 365.25 days in a year, which we address by just inserting a leap day in February every 4 years.2

For weeks, orbital mechanics don’t need to come into it, but did anyways, because why not at this point? It seems like various religions used 7 as a significant number and so when creating a division larger than a day but shorter than a month, we just went with 7. That neither the lunar calendar nor the solar calendar work nicely with 7 didn’t seem to deter us. I’m not enough of a historian to know whether these religions influenced each other, but the clearest explanation I can find is that there were 7 planets visible in the sky, so 7 is important.

Days get divided into 24 hours because Egyptians had a base-12 counting system, so 12 hours for day and 12 hours for night. We dealt with summer days being longer than winter days by just making the first hours in the day shorter during the winter, then the Greeks standardized their lengths and let sunrise move around. Then we came up with Daylight Saving Time and it’s been a mess since.

Hours got divided into 60 minutes because when the Greeks standardized the length of hours to help with their astronomical calculations they were basing their work on prior art from the Babylonians. The Babylonians made their astronomical calculations in base-60, so we got the 60 minute hour. Then of course the 60 minute second. Conveniently, 60 is also easily divided into chunks of various sizes.

So it would stand to reason that a second is measured as a fraction of a solar day, but don’t be ridiculous, obviously we needed another system.3 If for no other reason than the rotation of the earth on its axis varies over time, and science abhors a unit that arbitrarily changes size. It makes that whole Doing Science thing unnecessarily tricky. So instead we found something that doesn’t change: the rate of radioactive decay. We measure the radioactive decay rate of Caesium-133 and define a second based on that. To keep clocks synced to earth’s rotation and not have day and night drift as the earth’s rotation slows or speeds up, we insert a leap second as necessary. Depending on what time system you’re working with, those seconds may or may not be included.

But wait, I’m lying to you. Because it turns out the rate of radioactive decay of Caesium-133 isn’t actually consistent. Thanks to gravitational time dilation, the altitude of the sample of Caesium-133 influences how fast it decays. So we take lots of samples at various altitudes, average and weight them, and that estimate is what we call a second.

There’s one last version of a second we need to be aware of. How do our computers know anything about time? Well, it depends. Some computers have atomic clocks and can use the Caesium-133 method, but—as we just saw—two computers at different altitudes will have two different understandings of what a second is. Some computers use GPS—it turns out GPS requires very accurate time keeping, and if you can talk to the satellites, you can piggyback off that. But for most computers, it’s a gross hack—we use less accurate mechanical measurements, and sync periodically with the more accurate computers so we don’t get too out of sync. So when our software measures time, it’s less of a physical or orbital measurement and more of a shrugged “close enough” that occasionally may leap forward or jump back. Unless you use the computer’s monotonic clock, which is yet another measurement of a second that will not match any of our other definitions and can drift slightly over time.

We haven’t even addressed timezones yet, or Daylight Saving Time. Or how municipalities of any size, from counties to countries, can change their timezone or whether they observe Daylight Saving or not. The folks behind the tz database are heroes.

Time is cursed because we’re cursed

It turns out our society is built on the needs of our fragile human bodies, the things we need to prosper in our natural environment, and the thousands of years of history we built on. To quote a very underappreciated children’s book: who says time is cursed? You do, Nicholas.

We built systems to the best of our understanding at the time, for the context we were in in the moment, and they outlasted our context by thousands of years. As engineers, this story should be familiar to us. Time is the ultimate legacy system.

It’s your job to shield your organization from the curse

The point of hiring highly-paid engineers to build things for you is that you will never have to think about Caesium-133 or understand the difference between UTC and UT1. Our job is to provide an abstraction over this hot mess of a system and let people (both our colleagues and our users) interact with it in the way that is natural.

The way to deal with the curse of time is to understand the different systems people may be using, figure out which one is relevant to the issue at hand, and learn to convert between them.

Is a month 43,830 minutes or somewhere between 28 and 31 days depending on which calendar month it is? Well, that depends! Is it important that there are exactly 12 months in a year—maybe because you’re doing billing, and it’s important where revenue falls on a calendar? Or is it more important that a month begins at the same time of day—maybe because you’re scheduling a monthly meeting, and you need it to be at a consistent time?

As always, the real problem with computers is actually just people, and engineering is as much about understanding people as it is about understanding computers.

Footnotes

  • 1 We’ll come back to this in a minute. 
  • 2 There’s more to this. We’re not going to talk about it. If you’re doing math that needs to calculate this by hand for some reason, you should be reading better reference materials than my blog. 
  • 3 Technically we did, and (depending on what you’re doing or who you’re talking to, do) measure seconds as a fraction of a day but mostly we don’t anymore.