Unix time to hit 10**9!

KM on 2001-09-08T23:54:07

schwern writes "On Sunday, September 9th, 2001 at 01:46:40 AM GMT Unix time will hit 1 billion seconds since the Unix epoch began.

The last time the epoch date stepped up an order of magnitude was March 3rd, 1973 when it hit 100 million. The 2 billion mark will be reached on May 18th, 2033. So this doesn't happen very often."

For the chronologically curious, you can watch the time ticking down to 10**9 with a simple one-liner...

perl -e 'do{$|=printf"\r%04d",1e9-time}while$|'

Ok, so it's not the Millenium, it's not 2038, and it ain't Halley's Comet. Why do you care? Because of The Dreaded September 9th, 2001 Bug! You may have been getting away with this kind of thing:

my @sorted_times = sort @epoch_times;

Since sort does a string comparison by default, there's a subtle bug hidden in that code. For the last 28 years, the time has been the same length. Always nine digits. Two digits of the same length will sort properly as strings:

9998 lt 9999 # yep, that's true.

but if they're not the same length, you've got problems

10000 lt 9999 # Unfortuntely, that's true, too.

So sorts and comparisons on dates might start breaking in subtle ways. Double check your code, folks! Make sure you're using numeric comparisons on time.

Other annoyances brought about by the advent of 10**9th, poorly written fixed-width data files may begin breaking if they only allocated 9 characters to store time. Maybe you get an error, maybe it gets truncated.

So don't be surprised if its 1970 all over again!


Here's a nicely formatted one-liner.

schwern on 2001-09-09T00:06:46

perl -e 'do{$|=printf"\r%d h %02d m %02d s", map { ($_/3600, $_/60%60, $_%60) } 1e9-time}while$|'





So you get a nice:





1 h 40 m 07 s

sort()ing time is evil

miyagawa on 2001-09-09T10:34:13

But you can catch such mistakes with Dunce::time.

So, what did everyone do?

jjn1056 on 2001-09-09T16:17:16

I went out and played music with my band. Anyone get falling down drunk over this?

CVSup broke

jhi on 2001-09-09T16:49:34

At least CVSup assumedly broke (didn't see
the original message myself, was forwarded
a copy). Not because of sorting, but because
of only reserving 9 digits for the timestamp. Ouch.

simple

tarpan on 2001-09-10T06:40:28

I did a simpler version, just a...

perl -e 'while( 1 ) { printf("%d\n",time); sleep(1); };

...and cheered when it hit 1000000000

Re:So, what did everyone do?

dmitri on 2001-09-10T13:47:15

I drank beer for the occasion. Dear UNIX, let there be many more billions to come!