#include // Gregorian Calendar started on October 15, 1582 const long gregorianStart = (31L * (10 + 12L * 1582) + 15); long greg2jul( int day, int month, int year ) { // From "Numerical Recipes in C", adapted if (year == 0) throw std::domain_error("There is no year 0"); // There is no calendar year 0. As a consequence, e.g., the year 10 // BC of the calendar is the year -9 of the Julian system. The // formal parameter "year" of this procedure is the *calendar* year, // positive (AD) or negative (BC). long jy = (year < 0 ? year + 1 : year); long jm; // Months before March are considered the last months of the // previous year if (month > 2) jm = month + 1; else { --jy; jm = month + 13; } long result = day + 1720995L; result += static_cast(365.25 * jy); result += static_cast(30.6001 * jm); if ((31L * (month + 12L * year) + day) >= gregorianStart) { long cent = static_cast(0.01 * jy); result += 2 - cent; result += static_cast(0.25 * cent); } return result; }