30th December 2016
The UNIX Epoch and 2038 bug
Unix (and as a result, Linux, and many other) systems tend to store times as what is called a "signed 32-bit integer". A signed integer is a way of storing a binary number in a way which will allow it to express both positive and negative numbers. So, instead of using the simple binary method of using 00, 01, 10, 11, etc to count from 0 upwards, the mid-point is used to express "zero", so that the 32-bit binary can be used to represent a range from -2,147,483,647 to +2,147,483,647, rather than from 0 to +4,294,967,295:
Decimal | 32-bit Binary | Signed Decimal | Date |
---|---|---|---|
0 | 00000000 00000000 00000000 00000000 | -2,147,483,647 | 1901-12-13 20:45:53 |
1 | 00000000 00000000 00000000 00000001 | -2,147,483,646 | 1901-12-13 20:45:54 |
2 | 00000000 00000000 00000000 00000010 | -2,147,483,645 | 1901-12-13 20:45:55 |
3 | 00000000 00000000 00000000 00000011 | -2,147,483,644 | 1901-12-13 20:45:56 |
... | |||
2,147,483,646 | 01111111 11111111 11111111 11111110 | -1 | 1969-12-31 23:59:59 |
2,147,483,647 | 01111111 11111111 11111111 11111111 | 0 | 1970-01-01 00:00:00 |
2,147,483,648 | 10000000 00000000 00000000 00000000 | +1 | 1970-01-01 00:00:01 |
... | |||
3,630,626,514 | 01011000 01100110 11110110 11010011 | +1,483,142,867 | 2016-12-30 00:07:47 |
3,630,712,447 | 11011000 01101000 01000110 01111111 | +1,483,228,800 | 2017-01-01 00:00:00 |
... | |||
4,294,967,294 | 11111111 11111111 11111111 11111110 | +2,147,483,646 | 2038-01-19 03:14:06 |
4,294,967,295 | 11111111 11111111 11111111 11111111 | +2,147,483,647 | 2038-01-19 03:14:07 |
The designers of Unix, around 1970, decided that a signed 32-bit integer would be a suitable representation for dates. You can take zero as being midnight on the 1st January 1970 (UTC), and each second bumps that number up by one. So midnight was zero, one minute past midnight was 60, two minutes past midnight was 120, and so on. And this method could be used to count backwards, too, all the way back to 2.147 billion seconds before that date.
That covers a period from December 1901 up until January 2038. So any company records, etc, could be covered quite reasonably, and, around 1970, when the Stanley Kubrick / Arthur C Clarke movie "2001" was predicting how different the world would be in the mind-bogglingly futuristic year of 2001, that would have seemed perfectly reasonable. And, indeed, this system is still in wide use today, and is causing no problems. At the time of writing this, approaching New Year's Eve 2016, the time is 1483142867 seconds since 1st January 1970, or 01011000 01100110 11110110 11010011 in signed 32-bit binary. So there's still plenty of room to work with, and few people designing a system in 1970 would expect it to still be in use in 2017.Some systems have now moved on to 64-bit times, and will be unaffected by this "bug". Others, however, will have to come up with a workaround. But there's no need to panic, there are 21 years yet until 2038!