julianDay method

int julianDay ()

Computes the Julian day which is the number of days since Monday, January 1, 4713 BC.

Implementation

int julianDay() {
  int a = ((14 - month) ~/ 12);
  int y = year + 4800 - a;
  int m = month + (12 * a) - 3;
  int jd = (day + (((153 * m) + 2) ~/ 5) + (365 * y) + (y ~/ 4));

  // --- Correction for dates since 1582-10-15 <=> Gregorian Calendar
  if (year > 1582 ||
      (year == 1582 && (month > 10 || (month == 10 && day >= 15)))) {
    jd = (jd - (y ~/ 100) + (y ~/ 400) - 32045);
  } else {
    jd = jd - 32083;
  }
  return jd;
}