Question

If I wanted to work using dates and time going millions of years into the past/future how would I do it in C/C++/C#?

For example say I was working on an algorithm to see if a comet was going to hit the earth? Are there commercial or open source libraries that do this?

Most DateTime values only work for a few years. Unixes will run out in only 2038!.

Tony

Was it helpful?

Solution

Astronomers use their own calendar, different from the civil, Gregorian calendar.

Astronomical Julian Dates are what they use.

Look at http://en.wikipedia.org/wiki/Julian_day

Here's a typical package: Solar Clock.

OTHER TIPS

You can't work out future UTC dates down to the second, because of the existence of leap seconds (one of which is scheduled for December 31, a couple of weeks from now). No one knows when leap seconds will be added to the calendar, because no one knows the rate at which the Earth's rotation will continue to slow in the future.

Well, not to be blunt or anything, but if it will hit the earth in like 1700 years, I don't think we'll need to know the actual date.

Unless it's a tuesday.

Never could get the hang of tuesdays.

If the time span offered by typical datetime variables is too small, you have two options:

  1. Using a variable with a bigger scope (i.e. more bits)
  2. Allowing for less precision

Which one you should choose depends on what exactly you want to do. But in general, my advice is option number 2. When we are talking about centuries or millenia, milliseconds are usually not that important...

When it comes to astronomical events, it doesn't matter which part of the earth is facing the Sun, i.e. has daylight. Therefore, calendars and dates are irrelevant too. You should simply use time. A 64 bit time_t for instance is quite sufficient.

Even when you do use time, keep in mind that 3-body systems (like Earth-Sun-Jupiter) are chaotic. Predicting the position of the Earth in the far future has a rather large margin of error.

A 64-bit time_t will work until the year 292,277,026,596.

You just need more bits to store the value and/or use larger increments of time to represent by the timestamp. Instead of ms, do years, then possibly use a math library/API designed for very large numbers if that isn't enough (and depending on your precision requirements) or use floating point.

The DateTime object in C# goes from 1.1.0001 to 12.31.9999. It's even more limited in SQL Server where the earliest date is something like 1735.

You're pretty much going to have to write something yourself or try to scrounge something from someone else. Going forward is probably easier (except the leap second thing.) There is some pretty good info on calendars here.

I think the problem is not knowing whether the comet is going to hit on a Friday or Sunday but if the comet is or isn't going to hit. I guess this means that you could model time in 1000ths of a second as a 64bit long long type. You can resolve 213 Billion Years. You can then have a routine which maps this back to meaning full-ish dates...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top