This function converts a Julian Date, expressed as two double-precision numbers, into a Gregorian calendar date (year, month, day) and time (hour, minute, second).

Depending on the value of the timescale argument, the function behaves as follows:

  • CALCEPH_UTC: The function handles leap seconds. It requires that the ephemeris file associated to eph contains leap second history (constants DELTET or DELTA_AT).

  • Other timescales (e.g., CALCEPH_TT, CALCEPH_TDB): The time is treated as continuous. The seconds field is always in the range [0, 60[.

If the timescale is CALCEPH_UTC and the ephemeris file does not contain the required leap second constants, the function returns an error.

The following example converts a JD to a calendar date in TDB:

t_calcephbin *peph;
double jd0 = 2451545.0; /* J2000.0 */
double jdfrac = 0.5;    /* 12h */
int yy, mm, dd, hh, min;
double sec;

/* open the ephemeris file */
peph = calceph_open("example_lsk.tls");
if (peph != NULL)
{
    /* convert JD to Calendar (UTC) */
    if (calceph_time_jd_to_cal(peph, CALCEPH_UTC, jd0, jdfrac,
                               &yy, &mm, &dd, &hh, &min, &sec) != 0)
    {
        printf("Date: %d-%d-%d %d:%d:%f\n", yy, mm, dd, hh, min, sec);
    }

    /* close the file */
    calceph_close(peph);
}