tags:

views:

311

answers:

5

I need to represent dates earlier than January 1 0001. Do you know a library that includes such a type?

It should provide the following functionality:

  • Add/Subtract
  • BigTimeSpan
  • Greater / Less than comparison

It would be ok if values would be less exact the longer the date is ago.

+2  A: 

Take a look at this thread on SO with exactly the same question. Basically, there is no built-in support, so you'll need to find a 3rd party implementation or build it yourself.

Qua
Do you know a library for this?
Take a look at the link. It contains information about how you would go about building a class to handle this.
Qua
The link in the link only shows a way to represent Years BC and AD. I also need dates (and maybe time).
It'll be very hard to get that right. You also need correct culture specific info (when did they change from Julian to Gregorian calendar for example)
Sander Rijken
Maybe I'll just try to merge the existing DateTime and a custom class then. The problem that it would be hard was the reason why I was looking for a 3rd party library.
A: 

Maybe this is of help? Representing Large AD and BC Dates in C#.

Dan Diplo
That's the link Qua linked to.
+2  A: 

Joda Time + IKVM

typeseven
+1  A: 

If you really only need those three operations (meaning no day-of-week, day-of-month, time zones etc): just use long as number of seconds (or milliseconds) from pivot date. 2^64 seconds give you half a trillion of years.

ima
+4  A: 

There were 445 days in 45 BC, so you'll need to add that in, and the switch from Julian (45bc) to the previous roman calendar. The Gregorian calendar change came a lot later (1500s) than you need so you don't have to worry about that.

The two main problems of using DateTime are the min and max constants. Obviously being a struct you can't subclass it either.

My first option would be to write my BigDateTime or BCDateTime struct, and use a DateTime inside that via composition. You can then set your current Calendar:

CultureInfo.CurrentCulture.DateTimeFormat.Calendar = new JulianCalendar();

for to the Julian one but as I mentioned that only gives you to 45 years BC

If the year is below 45 you switch Calendars again to your own subclassed Calendar object. If the year is 45, you'll need another Calendar with the 445 days for that year (they did this to adjust between the older Calendar).

What will your min and max constants be for this object? The dawning of civilisation itself?!

You will need to pick those, and also bare in mind the Julian calendar and its previous non-reformed version were specific for the countries of the Roman empire. Being a westerner I have no idea of the other calendars that existed, you'll get a lot more information from the wikipedia articles though.

If you choose to do all cultures then you have a mammoth task on your hands (as the original .NET team did) to implement calendars that already exist. Different calendars have different starting epochs relative to BC, such as the Islamic, Chinese and Hindu calendars. More information on that is here. So if you want every culture and not just the Roman empire you will need to make your own version of the following, or atleast some of them:

System.Globalization.Calendar
    System.Globalization.EastAsianLunisolarCalendar 
    System.Globalization.GregorianCalendar 
    System.Globalization.HebrewCalendar 
    System.Globalization.HijriCalendar 
    System.Globalization.JapaneseCalendar 
    System.Globalization.JulianCalendar 
    System.Globalization.KoreanCalendar 
    System.Globalization.PersianCalendar 
    System.Globalization.TaiwanCalendar 
    System.Globalization.ThaiBuddhistCalendar 
    System.Globalization.UmAlQuraCalendar

Good luck! It'd be interesting to see how you get on.

Chris S
Wrapping a DateTime sounds like a pretty quick and pleasant solution. The best solution will depends on what kind of precision is required in these pre-Dark Ages dates - years, months, days...?
Kirk Broadhurst