Beispiel #1
0
void Ephemeris::ToJulianDate(DateTime epoch, double& julianDate)
{
	int y = epoch.Month <= 2 ? epoch.Year - 1 : epoch.Year;
	int m = epoch.Month <= 2 ? epoch.Month + 12 : epoch.Month;
	/* 
	* The reason for the peculiar definition of B are to account for the "lost days" in October 1582
	* when the Gregorian Calendar replaced the Julian Calendar in Europe, and to deal with the
	* introduction of a leap day in the Gregorian calendar.
	*/

	int B;
	if (epoch.Year < 1582)
	{
		B = -2;
	}
	else if (epoch.Year == 1582 && epoch.Month < 10)
	{
		B = -2;
	}
	else if (epoch.Year == 1582 && epoch.Month == 10 && epoch.Day <= 4)
	{
		B = -2;
	}
	else
	{
		B = MyInt(y / 400.0) - MyInt(y / 100.0);
	}

	double universalTime = epoch.Millisec / 3600000.0 + epoch.Second / 3600.0 + epoch.Minute / 60.0 + epoch.Hour;
	julianDate = MyInt(365.25 * y) + MyInt(30.6001 * (m + 1)) + B + 1720996.5 + epoch.Day + universalTime / 24.0;
}
Beispiel #2
0
inline MyInt operator-(const MyInt& rhs) { return MyInt(-rhs.val); }
Beispiel #3
0
void Ephemeris::ToDateTime(double julianDate, DateTime& dateTime)
{
    long a = MyInt(julianDate + 0.5);
    long b = 0;
    long c = 0;
    if (a < 2299161)
    {
        b = 0;
        c = a + 1524;
    }
    if (a >= 2299161)
    {
        b = MyInt((a - 1867216.25) / 36524.25);
        c = a + b - MyInt(b / 4.0) + 1525;
    }
    long d = MyInt((c - 122.1) / 365.25);
    long e = MyInt(365.25 * d);
    long f = MyInt((c - e) / 30.6001);

    double day = c - e - MyInt(30.6001 * f) + MyFrac(julianDate + 0.5);
    int month = (f - 1 - 12 * MyInt(f / 14.0));
    int year = (d - 4715 - MyInt((7 + month) / 10.0));

    double universalTime = MyFrac(day) * 24.0;
    int hour = MyInt(universalTime);
    double r = MyFrac(universalTime) * 60.0;
    int minute = MyInt(r);
    r = MyFrac(r) * 60;
    int second = MyInt(r);

	dateTime.Year = year;
	dateTime.Month = month;
	dateTime.Day = MyInt(day);
	dateTime.Hour = hour;
	dateTime.Minute = minute;
	dateTime.Second = second;
}