2
$\begingroup$

I have today discovered the intricacies of software dates. That led me to this page which shows:

$$JD=int[365.25\; y]+int[30.6001\; (m+1)]+D+\frac{UT\_hours}{24.0}+1\,720\,981.5 \qquad$$

However, peaking at the v8 source code (the main JavaScript compiler), we see this:

// Compute modified Julian day from year, month, date.
// The missing days in 1582 are ignored for JavaScript compatibility.
function ToJulianDay(y, m, D) {
  var jy = (m > 1) ? y : y - 1;
  var jm = (m > 1) ? m + 2 : m + 14;
  var ja = FLOOR(0.01*jy);
  return FLOOR(FLOOR(365.25*jy) + FLOOR(30.6001*jm) + D + 1720995) + 2 - ja + FLOOR(0.25*ja);
}

If I can try and translate that last part into math, it would be:

$$JD=int[int[365.25*jy] + int[30.6001*jm] + D + 1720995] + 2 - ja + int[0.25*ja];$$

Compared to:

$$JD=int[365.25\; y]+int[30.6001\; (m+1)]+D+\frac{UT\_hours}{24.0}+1\,720\,981.5 \qquad$$

Why isn't it exactly the same? What are the differences? I went so far as to find Hofmann-Wellenhof, B., Lichtenegger, H., K. and Wasle, E., 2008. GNSS - Global Navigation Satellite Systems, and found it said:

The relations for date conversions are taken from Montenbruck (1984) and are slightly modified so that they are only valid for an epoch between March 1900 and February 2100.

Montenbruck looks like a German text.

So I am not quite sure. What is the correct equation for figuring out the Julian date from the current date?

$\endgroup$
1
  • $\begingroup$ Montenbruck is the name of the author of this book $\endgroup$
    – Jean Marie
    Commented May 28, 2022 at 14:07

1 Answer 1

1
$\begingroup$

For more concise formulas, I'll write $\lfloor x\rfloor$ for the "floor" function.

The formula in the function ToJulianDay is then

$$ JD = \left\lfloor\lfloor 365.25 jy\rfloor + \lfloor 30.6001 jm\rfloor + D + 1720995\right\rfloor + 2 - ja + \lfloor 0.25 ja\rfloor. $$

We can make this a little easier to parse by pulling some integer parts out of the sum inside the first $\lfloor \cdot\rfloor$:

$$ JD = \lfloor 365.25 jy\rfloor + \lfloor 30.6001 jm\rfloor + \lfloor D\rfloor + 1720995 + 2 - ja + \lfloor 0.25 ja\rfloor. $$

Simplify:

$$ JD = \lfloor 365.25 jy\rfloor + \lfloor 30.6001 jm\rfloor + \lfloor D\rfloor + 1720997 - ja + \lfloor 0.25 ja\rfloor. $$

For $jy = 1900$ through $jy = 1999,$ we have $ja = 19$ and $\lfloor 0.25 ja\rfloor = \lfloor 4.75\rfloor = 4,$ so $$- ja + \lfloor 0.25 ja\rfloor = -15.$$

For $jy = 2000$ through $j y = 2099,$ we have $ja = 20$ and $\lfloor 0.25 ja\rfloor = \lfloor 5\rfloor = 5,$ so again $$- ja + \lfloor 0.25 ja\rfloor = -15.$$

Therefore for the entire time period $jy = 1900$ through $jy = 2099$ inclusive (which, as the quote from Hofmann-Wellenhof et al. says, is the period starting in March $1900$ and ending in February $2100$),

\begin{align} JD &= \lfloor 365.25 jy\rfloor + \lfloor 30.6001 jm\rfloor + \lfloor D\rfloor + 1720997 - 15 \\ &= \lfloor 365.25 jy\rfloor + \lfloor 30.6001 jm\rfloor + \lfloor D\rfloor + 1720982. \end{align}

On the other hand, if you plug $UT\_hours = 12$ into the ESA formula, you get \begin{align} JD &= \lfloor 365.25 y\rfloor + \lfloor 30.6001(m+1)\rfloor + D + \frac{UT\_hours}{24} + 1720981.5 \\ &= \lfloor 365.25 y\rfloor + \lfloor 30.6001(m+1)\rfloor + D + \frac{12}{24} + 1720981.5 \\ &= \lfloor 365.25 y\rfloor + \lfloor 30.6001(m+1)\rfloor + D + 1720982. \end{align}

So this is exactly the same thing as long as $m+1 = jm$ and as long as $D$ is an integer.

The months numbers are evidently input differently: for the ESA formula, February is month $M = 2$ and we set $m = M + 12 = 14$ in the formula, so $m+1 = 15$, but in the ToJulianDay function, February is input as month $m = 1$ and the function sets $jm = m + 14 = 15$; so indeed $m+1 = jm$ in this case. On the other hand, March is month $M=3$ in the ESA formula, which sets $m = M = 3,$ so $m + 1 = 4,$ but it is month $m = 2$ as input to ToJulianDay, so the function sets $jm = m + 2 = 4.$ So once again $m + 1 = jm.$ It will go similarly for other months.

So at noon UTC on any day in this period, the two functions give the same results.

Outside that period of time, the ToJulianDay function is correct and the other is not.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .