long gregorian_calendar_to_jd(int y, int m, int d)
{
y+=8000;
if(m<3) { y--; m+=12; }
return (y*365) +(y/4) -(y/100) +(y/400) -1200820
+(m*153+3)/5-92
+d-1
;
}
A similar function works for the
Julian calendar;
just omit the last two year-related corrections and
compensate for the epoch with a different constant.
y+=8000;
y
so we can simplify reasoning about our
calculations by considering only positive year values.
Any value divisible by 4000 could be chosen, since the
pattern of leap years in the reformed Gregorian calendar
repeats every 4000 years.
if(m<3) { y--; m+=12; }
return (y*365) +(y/4)
-(y/100) +(y/400)
-1200820
+(m*153+3)/5-92
+d-1