initialize method

void initialize(
  1. int year,
  2. double day
)

Initialize the Julian object 1582 A.D.: 10 days removed from calendar 3000 A.D.: Arbitrary error checking limit

Implementation

void initialize(int year, double day) {
  assert((year > 1582) && (year < 3000));
  assert((day >= 1.0) && (day < 367.0));

  // Now calculate Julian date

  year--;

  // Centuries are not leap years unless they divide by 400
  int A = (year / 100).round();
  int B = 2 - A + (A / 4).round();

  double newYears = (365.25 * year).round() +
      (30.6001 * 14).round() +
      1720994.5 +
      B; // 1720994.5 = Oct 30, year -1

  _date = newYears + day;
}