Reputation: 8830
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
Upvotes: 3
Views: 493
Reputation:
I would suggest NTP timestamps. They have 128 bits, a range larger than the age of the universe, and an accuracy/precision less than the smallest measurable time. Refer to https://www.eecis.udel.edu/~mills/y2k.html and https://www.eecis.udel.edu/~mills/time.html.
Upvotes: 1
Reputation: 179779
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.
Upvotes: 1
Reputation: 8830
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...
Upvotes: 0
Reputation: 9804
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.
Upvotes: 0
Reputation: 20271
If the time span offered by typical datetime variables is too small, you have two options:
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...
Upvotes: 4
Reputation: 2057
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.
Upvotes: 6
Reputation: 391286
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.
Upvotes: 5
Reputation: 391818
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.
Upvotes: 8
Reputation: 14257
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.
Upvotes: 0