All files / gregorian index.ts

100% Statements 19/19
100% Branches 2/2
100% Functions 1/1
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x 1x                           1x 16x 16x   16x 13x 13x 13x 13x 13x 13x   3x 3x 3x 3x 3x 3x   16x                  
import ifpos from "../ifpos";
import ifnav from "../ifnav";
/**
 * Converts a Julian Day (JD) to a Gregorian date and time.
 * ---
 *
 * @param jd - The Julian Day to convert.
 * @returns An object containing the year, month, day, hour, minute, and second of the Gregorian date and time at UT.
 *
 * @example
 * const jd = 2459345.5;
 * const result = toGregorian(jd);
 * console.log(result);
 * // Output: { year: 2021, month: 1, day: 1, hour: 0, minute: 0, second: 0 }
 */
export default function toGregorian(jd: number) {
  const jj = ifpos(jd);
  const kk = ifnav(jd);
  let year, month, day, hour, minute, second;
  if (jd > 0) {
    year = jj.year;
    month = jj.month;
    day = jj.day;
    hour = jj.hour;
    minute = jj.minute;
    second = jj.second;
  } else {
    year = kk.year;
    month = kk.month;
    day = kk.day;
    hour = kk.hour;
    minute = kk.minute;
    second = kk.second;
  }
  return {
    year,
    month,
    day,
    hour,
    minute,
    second,
  };
}