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. We can’t cover it in all its detail; that’s several books, or maybe several series of books. So rather than attempting to write a reference manual, or telling you the Best Way To Think About Time1, this post is going to attempt to give you an overview of some of the more common time measuring systems we use and what purpose they serve. The goal is to be less of a reference text that you can use to implement a system that deals with time and more to help guide you towards problems during the system design phase instead of learning about them while you’re elbow deep in implementation.

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, 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 days2 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 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, to organize human activities that give structure to society like work and religious observances, 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.

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.3

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 Time4 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.5 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 how to know whether you’re in Daylight Saving Time or not. 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?

Computers are only aware of time as an accumulation of the number of _their_6 seconds (nanoseconds, but whatever) that have passed since they last synced with an authoritative time source. Everything else we need to teach them about. For minutes and hours, that’s straightforward: they’re an accumulation of seconds. But for days, weeks, months, and years, those are defined by orbital mechanics and politics, and we need to teach our computers those rules and update those rules when they change.

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 The whole point of this post is there isn't a Best Time System, there are a bunch of them that we've developed for specific purposes, and your job as an engineer is to understand each of them as a tool you can deploy in the appropriate situations, and to recognize when problems you're working on are using different systems so you can convert appropriately. 
  • 2 We’ll come back to this in a minute. 
  • 3 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. 
  • 4 This is the fault of an entomologist and a golfer who, I am not joking, wanted more time in the daylight for their hobbies. Then during World War I everyone wanted to conserve coal. This whole system didn't start until the twentieth century. 
  • 5 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. 
  • 6 Because the hardware in computers that measures time can skew over time, it is not safe to assume that any computer's second is equal to any other computer's second or a standard second. This causes problems in distributed systems. Each and every website is a distributed system.