How can I convert an official DateTime to an astronomically accurate DateTime?

I was trying to figure out how to convert a birthday (DateTime) to an astronomically "exact" DateTime value. Time zone: UTC + 1.

Example:

My friend was born 1984-01-27 11:35

1984 is a leap year. But 1700, 1800, and 1900 were not leap years. So, until February 29, 2000, we are in astronomical exact time. In 1984 we are "almost" one day behind. So the astronomically accurate time would be after the official DateTime of my friend's birth, right?

These are the Gregorian calendar settings that I know:

  • Each year has 365 days
  • Every 4th year is a leap year (= 366 days instead of 365).
  • Every 100th year is not a leap year.
  • Every 400th year is a leap year (specify the previous rule)
  • An extra day is added at the end of February (February has 29 days in a leap year).

Astronomically, a year is 365 2422 days. This means that there are 24.0159254794 hours during the day. The time value when the official and astronomical times are "exactly" the same would be 2000-03-01T00: 00: 00, right?

Thus, it would be necessary to find out how big the difference between the official time and the astronomically exact time at a certain official time is.

I thought about it for hours until my head started to ache. I thought I'd share my headache with you. Maybe you guys know a timing library that can calculate this?

+3


source to share


1 answer


I have come up with a "solution" that seems accurate enough. Here's what it does:

  • The method starts at 1600-03-01T00: 00.18 years after Pope Gregor XIII. (after which our system of the Gregorian calendar is named) fixed the Julian calendar (named after Julius Caesar) in 1582, announcing that after October 4 (Thursday) the next day would be October 15 (Friday) - so there really isn't a fifth until October 14, 1582 in the history books, and the addition of calendar rules for 100 and 400.
  • The method adds up the difference between the official date and the exact date before the specified date is reached.
  • In leap years, the correction added by Pope Gregor XIII applies. This is done at the end of February.

Code:



public static DateTime OfficialDateTimeToExactDateTime(DateTime dtOfficial)
{
    const double dExactDayLengthInHours = 24.0159254794;
    DateTime dtParse = new DateTime(1600, 3, 1, 0, 0, 0);
    double dErrorInHours = 0.0;

    while (dtParse <= dtOfficial)
    {
        dErrorInHours += dExactDayLengthInHours - 24;
        dtParse = dtParse.AddDays(1);
        if (dtParse.Month == 3 && dtParse.Day == 1 &&
            ((dtParse.Year % 4 == 0 && dtParse.Year % 100 != 0) ||
             (dtParse.Year % 400 == 0)) )
        {
            dErrorInHours -= 24;
        }
    }

    dErrorInHours += ((double)dtOfficial.Hour + (double)dtOfficial.Minute / 60 + (double)dtOfficial.Second / 3600) *  (dExactDayLengthInHours - 24);

    return dtOfficial.AddHours(dErrorInHours * -1);
}

      

I have checked several tests:

  • If you pass the date before 2000-03-01T00: 00, you will receive a negative correction. Because we measure the days shorter because they actually are.
  • If you pass the date after 2000-03-01T00: 00, you will receive a positive correction. This is because 2000 is a leap year (while 1700, 1800 and 1900 are not), but the correction applied is too large. At 24 x 400 = 4800 years, the correction will be about one day too large. So in 1600 + 4800 = 6400 (if the person is still alive), you would need to delcare 6400 for a non-leap year, despite the Gregorian calendar rules.
+1


source







All Articles