struct tm *mjddate (double mjd)
{
static struct tm date;
double ijd, c, e, h;
int a, b, f;
h = 24.0 * modf (mjd, &ijd);
if (ijd < -100840) {
c = ijd + 2401525.0;
} else {
b = (int)((ijd + 532784.75) / 36524.25);
c = ijd + 2401526.0 + (b - b/4);
}
a = (int)((c-122.1)/365.25);
e = 365.0 * a + a/4;
f = (int)((c-e)/30.6001);
date.tm_wday = ((int)mjd + 3) % 7;
date.tm_mday = (int)(c-e+0.5) - (int)(30.6001*f);
date.tm_mon = f-1 - 12 * (f/14);
date.tm_year = a-4715 - ((7 + date.tm_mon)/10) - 1900;
date.tm_hour = (int)h;
date.tm_min = (int)(h = 60.0 * (h - date.tm_hour));
date.tm_sec = (int)(h = 60.0 * (h - date.tm_min));
date.tm_isdst = 0;
return &date;
}