views:

482

answers:

13

What is the best way to store time ?

There seem to be a lot of ways to handle this.

Wikipedia has a listing, but most of them are epoch based. What if you were an archaeologist and wanted to store a date in your program?

+1  A: 

How exact do you think archaeological dates are? Archaeologists would just store the year (at best). Just make sure you allow more than two digits for the year.

Seriously, it doesn't matter a whole lot. IIRC, the Unix epoch won't run out of milliseconds for another 30 years. On one hand, I want to think that some of my programs will still be useful then. On the other, it will certainly be someone else's problem.

Bill the Lizard
Think of the children. :P
Brad Gilbert
The "unix epoch" isn't going to run out of anything. A signed 32 bit counter of seconds since that epoch will overflow in just under 30 years, but it's not too farfetched to believe we'll have transitioned to counting "unix" time with 64 bit counters. Once that happens, we're good up through the heat death of the universe.
nsayer
A: 

Number of picoseconds since the big bang? 64 bits should be enough, although we would have to watch out for the Y130B bug.

Matt Howells
I wouldn't advise an epoch which occurred an unknown time ago - you have to update all your timestamps whenever cosmologists change their minds ;-)
Steve Jessop
Think Kelvin - Celsius, but were Kelvin is unknown.
Brad Gilbert
+3  A: 

Use a negative number.

A 64bit long of milliseconds is +/- 292 million years, which is enough for anyone except an astronomer or geologist.

A long of seconds is significantly more than the age of the universe.

Also note, as others have pointed out, that in case of archeology you have problems with timestamps anyway, because the dates are all uncertain.

For example in Egyptology, there are periods where the sequential chronology is known, but nobody is quite sure how that translates into our year count, even though it's narrowed down to a few possibilities. So you end up with dates listed as "X, Y, or Z BCE", and something else known to have happened 5 years later as "(X+5), (Y+5) or (Z+5) BCE". Of course when talking among themselves, the Egyptologists will call the dates "so many years after blah", where blah is an important event, rather than trying to relate it to our calendar at all.

To cope with that, you'd want to copy them, and use an epoch based on the best available event for the period you're studying.

Steve Jessop
+2  A: 

Archaeologists, depending on their field, typically want to store dates as years B.P. - that is, Years Before Present. The further you go away from the present, the more "fuzzy" dates become and the less absolute precision matters. So for archaeologists, I would just store integers representing YBP.

If you're talking about archeologists that study post-columbian timeframes (rather specialist, but they do exist), then you should probably use a time standard that includes at least dates as well as years. The java spec uses a 64 bit counter of milliseconds before or after the Unix epoch, and that works pretty well, since it has millisecond precision and a very wide range.

nsayer
To make it even more fun, Present=1950, so you can have -ve years before present.
Martin Beckett
@mgb - you are correct. I forgot about that nuance. But archaeologists typically deal with dates long enough ago that +/- 50 years is within their margin of error.
nsayer
A: 

Jim Croce had time in a bottle.

chris
I literally started to type in the same joke but thought better of it.I'm not the one who downvoted you, though.Another options: 1) a jar hidden under the bed. 2) time can't be stored, but slips inexorably through our fingers.Glad that comments carry no karma!
kcrumley
+2  A: 
Peter Turner
They probably don't care because they'll be dead for longer than the gregorian/julian calendar has existed.
Brad Gilbert
A: 

Many older systems used Julian dates. Works well.

Brian Knoblauch
+3  A: 

You should follow the recommendations in the relevant RFC .

Khoth
A: 

Standard date representations should be just fine when combined with a measure of error in the date (e.g. 100 BC +/- 100years). You can't use YBP because the present is constantly moving forwards.

Marcin
YBP is actually defined as years before 1950. But the further back in time you go, the larger the margin of error becomes. In fields where YBP is used, the 60 year difference between 1950 and now is well inside of the margin of error, and can thus be ignored.
nsayer
+4  A: 

I'm on the Java JSR-310 (Date Time API) and we've defined time using nano second accuracy, since standard epochs (i.e. "January 1, 1970 at midnight UTC")

If you want to see the debate which led up to this and the pros and cons from folks far more knowlegable than me, search back through the public dev group emails.

Andrew Harmel-Law
A: 

Any date/time system needs a reference. You have to define a null point somewhere. A sepcific date is represented as an offset to it. I can not think of a system that works differently.

You can try something similar to the kelvin scale in temperature: 0 K is the lowest possible temperature, therefore all temperatures most be >= 0. In this case, it would be the moment the fourth dimension (time) came into existence. Good luck defining it ;-)

Another thought: The bigger the distance to now() becomes, the less important is the precision. (If you read anywhere that Socrates died 399 BC, do not take this too literally...) So a float would be a better type than an integer.

Treb
A: 

One common design problem you see in databases is that people get tricky with date and time storage in the hopes of optimising performance. There is very rarely any good reason to stray from using the system supplied data types for dates, however, and plenty of pitfalls if you do stray.

David Aldridge
+2  A: 

Read Calendrical Calculations.

Epochs work. In the US and Europe we generally use the Gregorian Calendar. It was adopted at various dates in various countries. It was initially pitched in 1582. But some countries (the US) didn't adopt it until 1752. Except in Alaska, where it was 1867.

All dates prior to adoption (in your country) are called "proleptic" dates. They're dates with caveats; some interpretation is required to understand them.

However, this all works great. If you're doing archeological work after the adoption of the Gregorian Calendar, the epoch doesn't matter. If you're doing work before the calendar, but after proleptic year "1" (remember, there was no Gregorian year before 1582,), then a epoch of Gregorian year "1" (like in Calendrical Calculations) is no worse than any other.

If you're doing work before proleptic year 1 (years -1 through -2.0b) you'll still be in good shape with a simple epoch-based system. You'll have to-the-day accuracy for things that happened (a) before humans counted the days and (b) when the length of the day was different than it is now. For proleptic years prior to -2.0b, you'll have to invent your own calendar. Or use approximations.

In short, what's wrong with an epoch? Do you have something better? Do you mind sharing?

S.Lott
There is a Perl module to handle the Gregorian/Julian Calendar.http://search.cpan.org/dist/DateTime-Calendar-Christian/
Brad Gilbert