$$\def\|{&}\DeclareMathOperator{\D}{\bigtriangleup\!} \DeclareMathOperator{\d}{\text{d}\!}$$

$$\DeclareMathOperator{\trunc}{trunc} \DeclareMathOperator{\Div}{div} \DeclareMathOperator{\gcd}{gcd} \DeclareMathOperator{\lcm}{lcm} \DeclareMathOperator{\bdom}{dom} \def\dfloor#1{\left\lfloor #1 \right\rfloor} \def\dceil#1{\left\lceil #1 \right\rceil} \def\dround#1{\left[ #1 \right]} \def\dparen#1{\left( #1 \right)} \def\dmod#1#2{\left\lfloor #1 \right\rceil_{#2}} \def\ddom#1#2{\left\lceil #1 \right\rfloor_{#2}} \def\dabs#1{\left| #1 \right|} \def\dfloorratio#1#2{\dfloor{\dfrac{#1}{#2}}} \def\dceilratio#1#2{\dceil{\dfrac{#1}{#2}}} \def\mod1ratio#1#2{\left\lfloor \dfrac{#1}{#2} \right\rceil_1} \def\dom1ratio#1#2{\left\lceil \dfrac{#1}{#2} \right\rfloor_1} \def\eqvide#1{\qquad\text{(vide \eqref{#1})}} \def\eqavide#1{\|\text{(vide \eqref{#1})}}$$

In astronomical formulas that contain a date, it is not convenient to write that date as a combination of years, months, and days, especially because not all years have the same number of days and not all months have the same number of days. It is much more convenient to measure the date as the number of days since some fixed day. The Julian Day Number (JDN) or Julian Date (JD) and its relatives are much used for this in astronomy. This page explains how you can translate a date from various calendars to the Julian Date, or the other way around.

The first part of this page provides algorithms for some modern and historical calendars. The second part (from Section 15) explains how I deduced those algorithms.

There are many different algorithms in use for converting between calendar dates and day numbers. The only thing that counts is that they provide the correct answers for all day numbers and calendar dates. If there is only a limited number of input values and possible outcomes (for example for calculating the month number and day-within-the-month number from the day-within-the-year number), then you can usually find many different algorithms that all give just the right answers for those particular values (but perhaps very different answers for all other input values), even if there is no logical connection between that algorithm and the calendar. In such a case there is often also little or no logical connection between the algorithm that converts from date to day number and the algorithm that converts from day number to date, but the algorithms may be shorter then.

For every algorithm, you should know for which input values it was designed to work. Some calendar algorithms only work well with positive numbers and give wrong results for negative years or negative day numbers. The algorithms I give below are designed to work for all years (including negative ones), all months in each year, all days in each month, and for all Julian Day Numbers (including negative ones).

Some of the fomulas express a choice: If a certain condition is met, then a certain action should be taken (for example, apply a correction to something), and if that condition is not met, then a different action or no action at all should be taken. Such alternative paths are easy to use in manual calculations, in applications that process one date at a time, and in applications written in a programming language that requires compilation before the program can be executed (for example, written in C or Fortran) but are not very convenient for use in applications that can handle many dates at once (in an array) and that are written in a programming language that can be executed immediately (such as Basic or Perl or IDL), for which the execution of an if-then statement per date is much slower than the execution of a single fixed calculation for each date in an array.

If the calendrical calculations below here involve such choices, then where possible I give a formula that circumvents if-then constructions and is therefore convenient for application to arrays of dates in direct-execution programming languagues. The accompanying text explains which choice is being worked around.

## 1. Different Kinds of Day Numbers

For astronomical calculations that depend on time it is useful to have a continuous time scale that uses only a single unit, and not three like most calendars (days, months, years), and that in addition uses a fixed time zone so that there is no confusion about which precise instant of time is meant.

The IAU has adopted the Julian Date (JD) for this purpose. This should not be confused with "a date in the Julian Calendar". There are various other timescales that look like JD. The next table describes a few of them.

Name Kind Begins From JD
JD Julian Date Decimal 12:00 UTC = JD
JDN Julian Day Number Whole 12:00 UTC = ⌊JD⌋
CJD Chronological Julian Date Decimal 00:00 LT = JD + 0.5 + TZ
CJDN Chronological Julian Day Number Whole 00:00 LT = ⌊JD + 0.5 + TZ⌋

"Whole" means that that timescale uses whole numbers only and counts whole days only. "Decimal" means that that timescale uses decimal numbers (with a part after the decimal point) and indicates instants of time. The "Begins" column shows when each next calendar day begins. 12:00 UTC means that a new calendar day begins at 12:00 (noon) universal time, which is not 12:00 noon local time ― except if you happen to be in a time zone equal to UTC, such as in Great Britain in winter. 00:00 LT means that a new calendar day begins at midnight local time. The "From JD"-column shows how the other numbers can be calculated from JD. In that column, "TZ" stands for an adjustment for your local time zone; that adjustment is 0 for UTC.

In practice, "decimal" JDs and CJDs are usually written with at least one digit after the decimal marker (even if that digit is 0), and "whole" JDNs and CJDNs without digits after the decimal marker.

The zero point of JD (i.e., JD 0.0) corresponds to 12:00 UTC on 1 January −4712 in the Julian calendar. The zero point of CJD corresponds to 00:00 (midnight) local time on 1 January −4712. JDN 0 corresponds to the period from 12:00 UTC on 1 January −4712 to 12:00 UTC on 2 January −4712. CJDN 0 corresponds to 1 January −4712 (the whole day, in local time).

Let's see which instants or periods of time correspond in the Gregorian calendar to the number 2455772 in the timescales of the previous table, in a time zone in which the clock reads 2 hours later than UTC (for example, in Central Europe in summer).

Example When
JD 2455772.0 exactly at 14:00 hours on 29 July 2011
JDN 2455772 from 14:00 hours on 29 July 2011 until 14:00 hours on 30 July 2011
CJD 2455772.0 exactly at 00:00 hours (midnight) on 29 July 2011
CJDN 2455772 the whole calendar day of 29 July 2011

To avoid round-off errors it is best to do calendrical calculations with whole numbers only. In what follows we use CJDN for that.

## 2. Notation

### 2.1. Rounding

In the formulas given below, many numbers are rounded to a nearby whole number. It is important that those numbers get rounded in the right direction. Whole numbers are already rounded, so those don't change.

The types of rounding that we use here are downward rounding to the nearest whole number (for $$x$$ this is indicated by $$\dfloor{x}$$) or upward rounding to the nearest whole number ($$\dceil{x}$$). The standard rounding function on calculators usually rounds to the nearest whole number (our notation for that is $$\dround{x}$$) and the standard conversion from a decimal number to a whole number in a computer language is usually by rounding in the direction of zero (our notation for that is $$\trunc(x)$$). The below table shows these different kinds of rounding for some values.

$${x}$$ $${\dfloor{x}}$$ $${\dround{x}}$$ $${\dceil{x}}$$ $${\trunc(x)}$$
−5 −5 −5 −5 −5
−4.9 −5 −5 −4 −4
−4.2 −5 −4 −4 −4
−4 −4 −4 −4 −4
−0.2 −1 0 0 0
0 0 0 0 0
0.2 0 0 1 0
4 4 4 4 4
4.2 4 4 5 4
4.9 4 5 5 4
5 5 5 5 5

### 2.2. Modular Arithmetic

If you divide the whole number $$y$$ by the whole number $$x$$ then you get a quotient $$q$$ and a remainder $$r$$. Sometimes we're interested in the quotient, and sometimes in the remainder. We choose to have the remainder never be negative. Then $$0 ≤ r \lt |x|$$ and

\begin{align} q \| = \dfloorratio{y}{x} \\ r \| = y \bmod x = \dmod{y}{x} = y − x\dfloorratio{y}{x} \\ y \| = q x + r = \dfloorratio{y}{x} x + \dmod{y}{x} \end{align}

The notations $$y \bmod x$$ and $$\dmod{y}{x}$$ mean: the non-negative remainder from the division of $$y$$ by $$x$$. That first one is a standard notation; I invented that second one.

We find

$$\frac{y}{x} = \dfloorratio{y}{x} + \dfrac{\dmod{y}{x}}{x}$$

and if $$x = 1$$ then

$$y = \dfloor{y} + \dmod{y}{1}$$

The notation $$x ≡ y \pmod{n}$$ means that $$x$$ and $$y$$ differ by some multiple of $$n$$. One says that $$x$$ and $$y$$ are congruent modulo $$n$$, and $$n$$ is called the modulus. The equation $$x ≡ y \pmod{n}$$ is called a congruence.

Modular arithmetic is arithmetic in which all calculations are modulo a fixed $$n$$. That means that you can subtract arbitrary multiples of $$n$$ from all terms and factors without changing the congruence. If $$x ≡ y \pmod{n}$$ and $$p$$ is a whole number, then also $$x + pn ≡ y \pmod{n}$$, and $$px ≡ py \pmod{n}$$, and also $$px ≡ py \pmod{pn}$$.

A well-known example of modular arithmetic is clock face arithmetic. The face of a typical clock can show hours between 1 and 12. If you see two pictures of a clock face and in the first picture it shows 3 o'clock and in the second picture it shows 7 o'clock, then the second picture might have been made 4 hours after the first one, but also 4 + 12 = 16 hours later, or 4 + 10×12 hours = 5 days and 4 hours later, or 4 hours plus any desired multiple of 12 hours later (or earlier). If $$t_1$$ is the time of the first picture and $$t_2$$ is the time of the second picture (measured in hours from a fixed moment), then all you know from the pictures is that $$t_2 ≡ t_1 + 4 \pmod{12}$$. And if the clock shows $$t$$ hours now, then after $$y$$ more hours it will show $$(t + y) \bmod 12 = \dmod{t + y}{12}$$ hours.

Note the difference in notation: $$z = x \bmod y$$ means that $$z$$ is equal to the remainder of dividing $$x$$ by $$y$$, and $$z ≡ x \pmod{y}$$ means that $$z$$ is equal to $$x$$ except for an arbitrary multiple of $$y$$. If $$z = x \bmod y$$ then also $$z ≡ x \pmod{y}$$, but the opposite need not be true,

### 2.3. Division

The notation $$\Div(x, y)$$ means: divide $$x$$ by $$y$$ and return the quotient $$q$$ and remainder $$r$$ of the division, such that the remainder is nonnegative and smaller in magnitude than $$y$$, so $$0 ≤ r \lt \dabs{y}$$:

\begin{align} \{ q, r \} \| = \Div(x, y) \\ x \| = q y + r \\ q \| = \dfloorratio{x}{y} \\ r \| = \dmod{x}{y} \end{align}

## 3. Validity

The following calendar formulas are mathematically exact, but if you use them in a computer program that calculates using numbers that cover a fixed amount of memory storage (such as 32-bit integers or 64-bit integers) then the period of time for which those formulas can yield the correct results in such a computer program is limited. With 32-bit numbers there can be at most $$W = 2^{32} = 4294967296$$ different day numbers, which corresponds to roughly 11.8 million years. That is large enough to be practical, but there is a problem that causes many calendars to not reach that limit.

Many of the calendar calculations have the form

$$y = \dfloorratio{f x + t}{g}$$

with whole numbers $$f \gt 1$$ and $$g \gt 0$$. Then the intermediate result $$f x + t$$ is almost always larger than $$x$$ and larger than the end result $$y$$. That intermediate result must fit in the $$W$$ unique values, which means that $$x$$ can have at most $$W/f$$ unique values, which is (much) less than $$W$$. We'll encounter a calendar for which one of the calculations has $$f = 765433$$. Then, for 32-bit numbers, $$x$$ can have at most $$2^{32}/765433 = 5611$$ unique values. For that case the $$x$$ counts months, and 5611 months cover about 450 years, so when using 32-bit numbers that calendar can handle at most about 450 years, if you program that formula exactly as given above. That is far too little to be practical.

In such a case you can do two things:

1. Do the calculations in a roundabout way that takes more calculation steps but is mathematically equivalent to the simple formula and that (where possible) extends the range to the 11.8 million years that is the highest achievable for 32-bit numbers.

2. Calculate using 64-bit numbers instead of 32-bit numbers. For 64-bit numbers, too, only $$W/f$$ unique values can be used with the above formula, but for 64-bit numbers the value of $$W$$ is $$2^{32}$$ times (about 4 thousand million times) greater than it is for 32-bit numbers. For that tough case where 32-bit numbers give a range of only about 450 years, 64-bit numbers give a range of about 450×4 thousand million years, which means about 1800 thousand million years, which is over 100 times the current age of the Universe. In practice, then, there is no limit when you use 64-bit numbers. And calculating using the simpler formula with 64-bit numbers can even take less calculation time than calculating using the roundabout way with 32-bit numbers.

Below, I provide for every described calendar an estimate of the period for which it can be used when calculating with 32-bit numbers. (For my calculation environment that estimate is exact, but there is a very slight chance that it is different for yours.) If that period contains less than 7.5 million days (around 20'500 years) then I provide more cumbersome alternative formulas that extend the range to the maximum extent possible. Chapter 16 provides such alternative formulas for every calendar for which they increase the range.

## 4. The GregorianCalendar

The Gregorian calendar is the successor of the Julian calendar. The Gregorian calendar was introduced in different countries on different dates. The first countries did so on October 15, 1582 (in the Gregorian calendar), which corresponds to CJDN 2299161.

If you calculate using 32-bit numbers then the following algorithms work for dates from Gregorian year −1'469'899 through 1'469'901. See Sec. 16.2 for more details and alternative algorithms, including a way to increase the useful range of the following algorithms to the for 32-bit numbers maximum possible of about 11 million years.

### 4.1. From Gregorian Date to CJDN

One algorithm to calculate a CJDN $$J$$ from a Gregorian date (calendar year $$a$$, calendar month $$m$$, calendar day $$d$$) is:

\begin{align} \{ a_1, m_1 \} \| = \Div(m − 3, 12) \\ \{ c_1, a_2 \} \| = \Div(a + a_1, 100) \\ J \| = \dfloorratio{146097 c_1}{4} + \dfloorratio{36525 a_2}{100} \notag \\ \| + \dfloorratio{153 m_1 + 2}{5} + d + 1721119 \end{align}

For example: what is the CJDN for 7 September 2010 on the Gregorian calendar? Then $$a = 2010$$, $$m = 9$$, $$d = 7$$ so

\begin{align*} \{ a_1, m_1 \} \| = \Div(m − 3, 12) = \Div(9 − 3, 12) = \Div(6, 12) = \{ 0, 6 \} \\ \{ c_1, a_2 \} \| = \Div(a + a_1, 100) = \Div(2010 + 0, 100) = \{ 20, 10 \} \\ J \| = \dfloorratio{146097 c_1}{4} + \dfloorratio{36525 a_2}{100} \\ \| + \dfloorratio{153 m_1 + 2}{5} + d + 1721119 \\ \| = \dfloorratio{146097×20}{4} + \dfloorratio{36525×10}{100} \\ \| + \dfloorratio{153×6 + 2}{5} + 7 + 1721119 \\ \| = \dfloorratio{2921940}{4} + \dfloorratio{365250}{100} \\ \| + \dfloorratio{920}{5} + 7 + 1721119 \\ \| = 730485 + 3652 + 184 + 7 + 1721119 = 2455447 \end{align*}

And here are the calculations for a few more dates:

$${a}$$ $${m}$$ $${d}$$ $${a_1}$$ $${m_1}$$ $${c_1}$$ $${a_2}$$ $${•c_1}$$ $${•a_2}$$ $${•m_1}$$ $${J}$$
−1000 12 15 0 9 −10 0 −365243 0 153 1356044
−1 12 31 0 9 −1 99 −36525 36159 275 1721059
0 1 1 −1 10 −1 99 −36525 36159 306 1721060
0 2 29 −1 11 −1 99 −36525 36159 337 1721119
0 3 1 0 0 0 0 0 0 0 1721120
2000 2 29 −1 11 19 99 693960 36159 337 2451604
2000 3 1 0 0 20 0 730485 0 0 2451605
2001 2 28 −1 11 20 0 730485 0 337 2451969
2001 3 1 0 0 20 1 730485 365 0 2451970
2010 9 7 0 6 20 10 730485 3652 184 2455447
2100 2 28 −1 11 20 99 730485 36159 337 2488128
2100 3 1 0 0 21 0 767009 0 0 2488129

### 4.2. From CJDN to Gregorian Date

The algorithm to calculate a Gregorian date (calendar year $$a$$, calendar month $$m$$, calendar day $$d$$) from a CJDN $$J$$ is:

\begin{align} \{ c_1, ε_1 \} \| = \Div(4 J − 6884477, 146097) \\ \{ a_1, ε_2 \} \| = \Div\dparen{100 \dfloorratio{ε_1}{4} + 99, 36525} \\ \{ m_1, ε_3 \} \| = \Div\dparen{5 \dfloorratio{ε_2}{100} + 2, 153} \\ \{ a_2, m_2 \} \| = \Div(m_1 + 2, 12) \\ a \| = 100 c_1 + a_1 + a_2 \\ m \| = m_2 + 1 \\ d \| = \dfloorratio{ε_3}{5} + 1 \end{align}

For example, which date in the Gregorian calendar corresponds to CJDN 2452827? Then $$J = 2452827$$ and then

\begin{align*} \{ c_1, ε_1 \} \| = \Div(4 J − 6884477, 146097) \\ \| = \Div(4×2452827 − 6884477, 146097) \\ \| = \Div(2926831, 146097) = \{ 20, 4891 \} \\ \{ a_1, ε_2 \} \| = \Div\dparen{100 \dfloorratio{ε_1}{4} + 99, 36525} \\ \| = \Div\dparen{100 \dfloorratio{4891}{4} + 99, 36525} \\ \| = \Div(100×1222 + 99, 36525) \\ \| = \Div(122299, 36525) = \{ 3, 12724 \} \\ \{ m_1, ε_3 \} \| = \Div\dparen{5 \dfloorratio{ε_2}{100} + 2, 153} = \Div\dparen{5 \dfloorratio{12724}{100} + 2, 153} \\ \| = \Div(5×127 + 2, 153) = \Div(637, 153) = \{ 4, 25 \} \\ \{ a_2, m_2 \} \| = \Div(m_1 + 2, 12) = \Div(4 + 2, 12) = \Div(6, 12) = \{ 0, 6 \} \\ a \| = 100 c_1 + a_1 + a_2 = 100×20 + 3 + 0 = 2003 \\ m \| = m_2 + 1 = 6 + 1 = 7 \\ d \| = \dfloorratio{ε_3}{5} + 1 = \dfloorratio{25}{5} + 1 = 6 \end{align*}

The date is 6 July 2003.

And here are the calculations for the same dates as before.

$${J}$$ $${c_1}$$ $${ε_1}$$ $${a_1}$$ $${ε_2}$$ $${m_1}$$ $${ε_3}$$ $${a_2}$$ $${m_2}$$ $${a}$$ $${m}$$ $${d}$$
2451604 19 146096 99 36524 11 144 1 1 2000 2 29
2451605 20 3 0 99 0 2 0 2 2000 3 1
2451969 20 1459 0 36499 11 139 1 1 2001 2 28
2451970 20 1463 1 74 0 2 0 2 2001 3 1
2452827 20 4891 3 12724 4 25 0 6 2003 7 6
2488128 20 146095 99 36424 11 139 1 1 2100 2 28
2488129 21 2 0 99 0 2 0 2 2100 3 1

## 5. The Milanković Calendar

For calculations with 32-bit numbers the below formulas are usable for Milanković years −653'199 through 653'289.

See section 16.3 for the derivation of the formulas mentioned below, and for how you can increase the usable range of the formulas to the maximum of (for 32-bit numbers) 11.8 million years.

### 5.1. From Milanković Date to CJDN

Some Eastern Orthodox churches use a calendar invented by Milutin Milanković, that differs from the Gregorian calendar only in the rules for which century years are leap years. One algorithm to calculate a CJDN $$J$$ from a Milanković date (calendar year $$a$$, calendar month $$m$$, calendar day $$d$$) is:

\begin{align} \{ a_1, m_1 \} \| = \Div(m ― 3, 12) \\ \{ c_1, a_2 \} \| = \Div(a + a_1, 100) \\ J \| = \dfloorratio{328718 c_1 + 6}{9} + \dfloorratio{36525 a_2}{100} \notag \\ \| + \dfloorratio{153 m_1 + 2}{5} + d + 1721119 \end{align}

For example, which CJDN corresponds to date 6 July 2003 in the Milanković calendar? Then $$a = 2003$$, $$m = 7$$, $$d = 6$$, and then

\begin{align*} \{ a_1, m_1 \} \| = \Div(m ― 3, 12) = \Div(7 ― 3, 12) = \{ 0, 4 \} \\ \{ c_1, a_2 \} \| = \Div(a + a_1, 100) = \Div(2003 + 0, 100) = \{ 20, 3 \} \\ J \| = \dfloorratio{328718 c_1 + 6}{9} + \dfloorratio{36525 a_2}{100} \\ \| + \dfloorratio{153 m_1 + 2}{5} + d + 1721119 \\ \| = \dfloorratio{328718×20 + 6}{9} + \dfloorratio{36525×3}{100} \\ \| + \dfloorratio{153×4 + 2}{5} + 6 + 1721119 \\ \| = \dfloorratio{6574366}{9} + \dfloorratio{109575}{100} \\ \| + \dfloorratio{614}{5} + 6 + 1721119 \\ \| = 730485 + 1095 + 122 + 6 + 1721119 = 2452827 \end{align*}

so that date corresponds to CJDN 2452827.

Here are some more examples:

$${a}$$ $${m}$$ $${d}$$ $${a_1}$$ $${m_1}$$ $${c_1}$$ $${a_2}$$ $${•c_1}$$ $${•a_2}$$ $${•m_1}$$ $${J}$$
−1000 12 15 0 9 −10 0 −365242 0 275 1356167
−1 12 31 0 9 −1 99 −36524 36159 275 1721060
0 1 1 −1 10 −1 99 −36524 36159 306 1721061
0 2 28 −1 11 −1 99 −36524 36159 337 1721119
0 3 1 0 0 0 0 0 0 0 1721120
2000 2 29 −1 11 19 99 693960 36159 337 2451604
2000 3 1 0 0 20 0 730485 0 0 2451605
2001 2 28 −1 11 20 0 730485 0 337 2451969
2001 3 1 0 0 20 1 730485 365 0 2451970
2003 7 6 0 4 20 3 730485 1095 122 2452827
2010 9 7 0 6 20 10 730485 3652 184 2455447
2100 2 28 −1 11 20 99 730485 36159 337 2488128
2100 3 1 0 0 21 0 767009 0 0 2488129

### 5.2. From CJDN to Milanković Date

An algorithm to convert CJDN $$J$$ to year $$a$$, month $$m$$, day $$d$$ in the Milanković calendar is:

\begin{align} \{ c_1, ε_1 \} \| = \Div(9 J − 15490078, 328718) \\ \{ a_1, ε_2 \} \| = \Div\dparen{100 \dfloorratio{ε_1}{4} + 99, 36525} \\ \{ m_1, ε_3 \} \| = \Div\dparen{5 \dfloorratio{ε_2}{100} + 2, 153} \\ \{ a_2, m_0 \} \| = \Div(m_1 + 2, 12) \\ a \| = 100 c_1 + a_1 + a_2 \\ m \| = m_0 + 1 \\ d \| = \dfloorratio{ε_3}{5} + 1 \end{align}

$${J}$$ $${c_1}$$ $${ε_1}$$ $${a_1}$$ $${ε_2}$$ $${m_1}$$ $${ε_3}$$ $${a_2}$$ $${m_0}$$ $${a}$$ $${m}$$ $${d}$$
1356167 −10 2605 0 28999 9 70 0 11 −1000 12 15
1721060 −1 328180 99 30524 9 150 0 11 −1 12 31
1721061 −1 328189 99 30624 10 2 1 0 0 1 1
1721119 −1 328711 99 36424 11 139 1 1 0 2 28
1721120 0 2 0 99 0 2 0 2 0 3 1
2451604 19 328716 99 36524 11 144 1 1 2000 2 29
2451605 20 7 0 99 0 2 0 2 2000 3 1
2451969 20 3283 0 36499 11 139 1 1 2001 2 28
2451970 20 3292 1 74 0 2 0 2 2001 3 1
2452827 20 11005 3 12724 4 25 0 6 2003 7 6
2455447 20 34585 10 19049 6 34 0 8 2010 9 7
2488128 20 328714 99 36424 11 139 1 1 2100 2 28
2488129 21 5 0 99 0 2 0 2 2100 3 1

## 6. The Hershel Calendar

The English scientist John Herschel (1792 - 1871) invented a revision to the Gregorian Calendar that makes it more closely follow the average length of a solar year. His idea was to add a leap year rule that says that a year is not a leap year after all (and February contains 28 days) if the year number is evenly divisible by 4000. Then the full set of rules for leap years are:

1. only if the year number is evenly divisible by 4

2. but not if the year number is evenly divisible by 100

3. but have a leap year anyway if the year number is evenly divisible by 400

4. but don't have a leap year after all if the year number is evenly divisible by 4000.

For calculations with 32-bit numbers the below formulas are usable for Herschel years −587'599 through 587'960.

See section 16.4 for the derivation of the formulas mentioned below, and for how you can increase the usable range of the formulas to the maximum of (for 32-bit numbers) 11.8 million years.

### 6.1. From Herschel Date to CJDN

The calculations are as follows, from year $$a$$, month $$m$$, and day $$d$$ in the Herschel calendar to CJDN $$J$$:

\begin{align} \{ α_1, m_1 \} \| = \Div(m − 3, 12) \\ \{ c_1, a_2 \} \| = \Div(a + α_1, 100) \\ \{ c_2, c_3 \} \| = \Div(c_1, 4) \\ J \| = \dfloorratio{1460969 c_2 + 9}{10} + \dfloorratio{146097 c_3}{4} + \dfloorratio{36525 a_2}{100} \notag \\ \| + \dfloorratio{153 m_1 + 2}{5} + d + 1721119 \end{align}

For example, which CJDN corresponds to the date 11 August 2022 in the Herschel Calendar? Then $$a = 2022$$, $$m = 0$$, and $$d = 11$$, and then

\begin{align*} \{ α_1, m_1 \} \| = \Div(m − 3, 12) = \Div(8 ― 3, 12) = \Div(5, 12) = \{ 0, 5 \} \\ \{ c_1, a_2 \} \| = \Div(a + α_1, 100) = \Div(2022 + 0, 100) \\ \| = \Div(2022, 100) = \{ 20, 22 \} \\ \{ c_2, c_3 \} \| = \Div(c_1, 4) = \Div(20, 4) = \{ 5, 0 \} \\ J \| = \dfloorratio{1460969 c_2 + 9}{10} + \dfloorratio{146097 c_3}{4} + \dfloorratio{36525 a_2}{100} \\ \| + \dfloorratio{153 m_1 + 2}{5} + d + 1721120 \\ \| = \dfloorratio{1460969×5 + 9}{10} + \dfloorratio{146097×0}{4} + \dfloorratio{36525×22}{100} \\ \| + \dfloorratio{153×5 + 2}{5} + 11 + 1721120 \\ \| + \dfloorratio{153 m_1 + 2}{5} + d + 1721120 \\ \| = \dfloorratio{7304854}{10} + 0 + \dfloorratio{803550}{100} \\ \| + \dfloorratio{767}{5} + 11 + 1721120 \\ \| = 730485 + 0 + 8035 + 153 + 11 + 1721119 = 2459803 \end{align*}

Some more examples:

$${a}$$ $${m}$$ $${d}$$ $${α_1}$$ $${m_1}$$ $${c_1}$$ $${a_2}$$ $${c_2}$$ $${c_3}$$ $${•c_2}$$ $${•c_3}$$ $${•a_2}$$ $${•m_1}$$ $${J}$$
2022 7 22 0 4 20 22 5 0 730485 0 8035 122 2459783
1000 1 1 −1 10 9 99 2 1 292194 36524 36159 306 2086303
2000 2 29 −1 11 19 99 4 3 584388 109572 36159 337 2451604
2000 3 1 0 0 20 0 5 0 730485 0 0 0 2451605
2022 8 11 0 5 20 22 5 0 730485 0 8035 153 2459803
3600 2 29 −1 11 35 99 8 3 1168776 109572 36159 337 3035992
3600 3 1 0 0 36 0 9 0 1314873 0 0 0 3035993
4000 2 28 −1 11 39 99 9 3 1314873 109572 36159 337 3182088
4000 3 1 0 0 40 0 10 0 1460969 0 0 0 3182089
5800000 1 1 −1 10 57999 99 14499 3 2118258954 109572 36159 306 2120126111

### 6.2. From CJDN to Herschel Date

In the opposite direction the calculations are as follows:

\begin{align} \{ c_2, ε_1 \} \| = \Div(10 J − 17211200, 1460969) \\ \{ c_3, ε_2 \} \| = \Div\dparen{4 \dfloorratio{ε_1}{10} + 3, 146097} \\ \{ a_2, ε_3 \} \| = \Div\dparen{100 \dfloorratio{ε_2}{4} + 99, 36525} \\ \{ m_1, ε_4 \} \| = \Div\dparen{5 \dfloorratio{ε_3}{100} + 2, 153} \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) \\ a \| = 400 c_2 + 100 c_3 + a_2 + α_1 \\ m \| = m_0 + 1 \\ d \| = \dfloorratio{ε_4}{5} + 1 \end{align}

For example, which Herschel date goes with CJDN 2459803? Then $$J = 2459803$$ and then

\begin{align*} \{ c_2, ε_1 \} \| = \Div(10 J − 17211200, 1460969) = \Div(10×2459803 − 17211200, 1460969) \\ \| = \Div(7386830, 1460969) = \{ 5, 81985 \} \\ \{ c_3, ε_2 \} \| = \Div\dparen{4 \dfloorratio{ε_1}{10} + 3, 146097} = \Div\dparen{4 \dfloorratio{81985}{10} + 3, 146097} \\ \| = \Div(4×8198 + 3, 146097) = \Div(32795, 146097) = \{ 0, 32795 \} \\ \{ a_2, ε_3 \} \| = \Div\dparen{100 \dfloorratio{ε_2}{4} + 99, 36525} = \Div\dparen{100 \dfloorratio{32795}{4} + 99, 36525} \\ \| = \Div(100×8198 + 99, 36525) = \Div(819899, 36525) = \{ 22, 16349 \} \\ \{ m_1, ε_4 \} \| = \Div\dparen{5 \dfloorratio{ε_3}{100} + 2, 153} = \Div\dparen{5 \dfloorratio{16349}{100} + 2, 153} \\ \| = \Div(5×163 + 2, 153) = \Div(817, 153) = \{ 5, 52 \} \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) = \Div(5 + 2, 12) = \Div(7, 12) = \{ 0, 7 \} \\ a \| = 400 c_2 + 100 c_3 + a_2 + α_1 = 400×5 + 100×0 + 22 + 0 = 2022 \\ m \| = m_0 + 1 = 7 + 1 = 8 \\ d \| = \dfloorratio{ε_4}{5} + 1 = \dfloorratio{52}{5} + 1 = 10 + 1 = 11 \end{align*}

so the date is day 11 in month 8 in year 2022.

Some more examples:

$${J}$$ $${c_2}$$ $${ε_1}$$ $${c_3}$$ $${ε_2}$$ $${a_2}$$ $${ε_3}$$ $${m_1}$$ $${ε_4}$$ $${α_1}$$ $${m_0}$$ $${a}$$ $${m}$$ $${d}$$
2459783 5 81785 0 32715 22 14349 4 105 0 6 2022 7 22
2086303 2 729892 1 145862 99 30624 10 2 1 0 1000 1 1
2451604 4 1460964 3 146096 99 36524 11 144 1 1 2000 2 29
2451605 5 5 0 3 0 99 0 2 0 2 2000 3 1
2459803 5 81985 0 32795 22 16349 5 52 0 7 2022 8 11
3035992 8 1460968 3 146096 99 36524 11 144 1 1 3600 2 29
3035993 9 9 0 3 0 99 0 2 0 2 3600 3 1
3182088 9 1460959 3 146092 99 36424 11 139 1 1 4000 2 28
3182089 10 0 0 3 0 99 0 2 0 2 4000 3 1
2120126111 14499 1460379 3 145860 99 30624 10 2 1 0 5800000 1 1

## 7. The Julian Calendar

For calculations with 32-bit numbers the below formulas are usable for Julian years −1'469'871 through 1'469'871.

See section 16.1.1 for the derivation of this algorithm, and for how you can increase the usable range of the formulas to the maximum of (for 32-bit numbers) 11.8 million years.

### 7.1. From Julian Date to CJDN

The algorithm to calculate a CJDN $$J$$ from a Julian date (calendar year $$a$$, calendar month $$m$$, calendar day $$d$$) is:

\begin{align} \{ α_1, m_1 \} \| = \Div(m ― 3, 12) \\ J \| = \dfloorratio{1461(a + α_1)}{4} + \dfloorratio{153 m_1 + 2}{5} + d + 1721117 \end{align}

For example: what is the CJDN for 7 September 2010 on the Julian calendar? Then $$a = 2010$$, $$m = 9$$, $$d = 7$$, and then

\begin{align*} \{ α_1, m_1 \} \| = \Div(m ― 3, 12) = \Div(9 − 3, 12) = \Div(6, 12) = \{ 0, 6 \} \\ J \| = \dfloorratio{1461(a + α_1)}{4} + \dfloorratio{153 m_1 + 2}{5} + d + 1721117 \\ \| = \dfloorratio{1461×(2010 + 0)}{4} + \dfloorratio{153×6 + 2}{5} + 7 + 1721117 \\ \| = \dfloorratio{2936610}{4} + \dfloorratio{920}{5} + 7 + 1721117 \\ \| = 734152 + 184 + 7 + 1721117 = 2455460 \end{align*}

And here are the calculations for a few more dates:

$${a}$$ $${m}$$ $${d}$$ $${α_1}$$ $${m_1}$$ $${•a}$$ $${•m_1}$$ $${J}$$
2000 2 29 −1 11 730134 337 2451617
2000 3 1 0 0 730500 0 2451618
2000 12 1 0 9 730500 275 2451893
2001 2 28 −1 11 730500 337 2451982
2001 3 1 0 0 730865 0 2451983
2010 9 7 0 6 734152 184 2455460
2100 2 28 −1 11 766659 337 2488141
2100 2 29 −1 11 766659 337 2488142
2100 3 1 0 0 767025 0 2488143

### 7.2. From CJDN to Julian Date

The algorithm to calculate a Julian date (calendar year $$j$$, calendar month $$m$$, calendar day $$d$$) from a CJDN $$J$$ is:

\begin{align} \{ a_1, ε_1 \} \| = \Div(4 J − 6884469, 1461) \\ \{ m_1, ε_2 \} \| = \Div\dparen{5 \dfloorratio{ε_1}{4} + 2, 153} \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) \\ a \| = a_1 + α_1 \\ m \| = m_0 + 1 \\ d \| = \dfloorratio{ε_2}{5} + 1 \end{align}

Which Julian date corresponds to CJDN 2455460? Then $$J = 2455460$$ so

\begin{align*} \{ a_1, ε_1 \} \| = \Div(4 J − 6884469, 1461) = \Div(4×2455460 − 6884469, 1461) \\ \| = \Div(2937371, 1461) = \{ 2010, 761 \} \\ \{ m_1, ε_2 \} \| = \Div\dparen{5 \dfloorratio{ε_1}{4} + 2, 153} = \Div\dparen{5 \dfloorratio{761}{4} + 2, 153} \\ \| = \Div(5×190 + 2, 153) = \Div(952, 153) = \{ 6, 34 \} \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) = \Div(6 + 2, 12) = \Div(8, 12) = \{ 0, 8 \} \\ a \| = a_1 + α_1 = 2010 + 0 = 2010 \\ m \| = m_0 + 1 = 8 + 1 = 9 \\ d \| = \dfloorratio{ε_2}{5} + 1 = \dfloorratio{34}{5} + 1 = 6 + 1 = 7 \end{align*}

The date is 7 September 2010.

And here are the calculations for the same dates as before.

$${J}$$ $${a_1}$$ $${ε_1}$$ $${m_1}$$ $${ε_2}$$ $${α_1}$$ $${m_0}$$ $${a}$$ $${m}$$ $${d}$$
2451617 1999 1460 11 144 1 1 2000 2 29
2451618 2000 3 0 2 0 2 2000 3 1
2451893 2000 1103 9 0 0 11 2000 12 1
2451982 2000 1459 11 139 1 1 2001 2 28
2451983 2001 2 0 2 0 2 2001 3 1
2455460 2010 761 6 34 0 8 2010 9 7
2488141 2099 1456 11 139 1 1 2100 2 28
2488142 2099 1460 11 144 1 1 2100 2 29
2488143 2100 3 0 2 0 2 2100 3 1

## 8. The Islamic Calendar

For calculations with 32-bit numbers the below formulas are usable for Islamic years −202'000 through 202'001.

See section 16.9 for the derivation of this algorithm, and for how you can increase the usable range of the formulas to the maximum of (for 32-bit numbers) 11.8 million years.

### 8.1. From Islamic Date to CJDN

The religious Islamic calendar depends on observations and so cannot be caught in formulas. The administrative calendar has fixed rules so it can be caught in formulas. The difference between the religious and administrative calendars should usually be no more than 1 day.

The CJDN can be derived from the year number $$a$$, month number $$m$$, and day number $$d$$ in the most commonly used administrative Islamic calendar (used by al-Fazārī, al-Khwārizmī, al-Battānī, and in the Toledan and Alfonsine Tables) as follows:

$$J = \dfloorratio{10631 a − 10617}{30} + \dfloorratio{325 m − 320}{11} + d + 1948439$$

For example, which CJDN $$J$$ corresponds to the Islamic date 29-08-1432? Then $$a = 1432$$, $$m = 8$$, $$d = 29$$, so

\begin{align*} J \| = \dfloorratio{10631 a − 10617}{30} + \dfloorratio{325 m − 320}{11} + d + 1948439 \\ \| = \dfloorratio{10631×1432 − 10617}{30} + \dfloorratio{325×8 − 320}{11} + 29 + 1948439 \\ \| = \dfloorratio{15212975}{30} + \dfloorratio{2280}{11} + 29 + 1948439 \\ \| = 507099 + 207 + 29 + 1948439 = 2455774 \end{align*}

The CJDN is 2455774, which corresponds to 31 July 2011 in the Gregorian calendar.

And how about the first day of the first month of the first year of the Islamic calendar? Then $$a = 1$$, $$m = 1$$, $$d = 1$$, so

\begin{align*} J \| = \dfloorratio{10631 a − 10617}{30} + \dfloorratio{325 m − 320}{11} + d + 1948439 \\ \| = \dfloorratio{14}{30} + \dfloorratio{5}{11} + 1 + 1948449 \\ \| = 0 + 0 + 1 + 1948439 = 1948440 \end{align*}

which corresponds to 16 July 622 in the Julian calendar.

Some more examples:

$${a}$$ $${m}$$ $${d}$$ $${•a}$$ $${•m}$$ $${J}$$
−1 12 30 −709 325 1948085
0 1 1 −354 0 1948086
0 12 29 −354 325 1948439
1 1 1 0 0 1948440
999 12 29 353658 325 2302451
1000 1 1 354012 0 2302452
1432 8 29 507099 207 2455774

### 8.2. From CJDN to Islamic Date

The following formulas calculate the year number $$a$$, month number $$m$$, and day number $$d$$ in the most commonly used administrative Islamic calendar from the CJDN $$J$$:

\begin{align} \{ a, ε_1 \} \| = \Div(30 J − 58442554, 10631) \\ \{ m, ε_2 \} \| = \Div\dparen{11\dfloorratio{ε_1}{30} + 330, 325} \\ d \| = \dfloorratio{ε_2}{11} + 1 \end{align}

For example, which Islamic date corresponds to CJDN 2455774? Then $$J = 2455774$$, and then

\begin{align*} \{ a, ε_1 \} \| = \Div(30 J − 58442554, 10631) \\ \| = \Div(30×2455774 − 58442554, 10631) \\ \| = \Div(15230666, 10631) = \{ 1432, 7074 \} \\ \{ m, ε_2 \} \| = \Div\dparen{11\dfloorratio{ε_1}{30} + 330, 325} = \Div\dparen{11\dfloorratio{7074}{30} + 330, 325} \\ \| = \Div(11×235 + 330, 325) = \Div(2915, 325) = \{ 8, 315 \} \\ d \| = \dfloorratio{ε_2}{11} + 1 = \dfloorratio{315}{11} + 1 = 28 + 1 = 29 \end{align*}

so $$a = 1432$$, $$m = 8$$, $$d = 29$$ which means 29 Shaban 1432.

Some more examples:

$${J}$$ $${a}$$ $${ε_1}$$ $${m}$$ $${ε_2}$$ $${d}$$
1948085 −1 10627 12 324 30
1948086 0 26 1 5 1
1948439 0 10616 12 313 29
1948440 1 15 1 5 1
2302451 999 10607 12 313 29
2302452 1000 6 1 5 1
2455774 1432 7074 8 315 29

## 9. The Babylonian Calendar

For calculations with 32-bit numbers the below formulas are usable for Babylonian year −25'018 through 25'017.

See section 16.6 for the derivation of this algorithm, and for how you can increase the usable range of the formulas to the maximum of (for 32-bit numbers) 11.8 million years.

### 9.1. From Babylonian Date to CJDN

The Babylonians had a lunisolar calendar in which the beginning of each month was determined from observations of the Moon, but the number of months in each year followed a fixed 19-year pattern. The below formulas for an administrative Babylonian calendar uses that same 19-year pattern, and should usually deviate by at most one day from the calendar that the Babylonians used that depended on observations.

If $$a$$ is the year number in the era of Seleukos, and $$m$$ is the month number (beginning at 1) in the current year, and $$d$$ is the day number (beginning at 1) in the current month, then the CJDN $$J$$ can be found as follows:

$$J = \dfloorratio{6940\dparen{\dfloorratio{235 a + 13}{19} + m − 1}}{235} + d + 1607174$$

For example, which CJDN $$J$$ corresponds to year 3, month 9, day 27 of the era of Seleukos? Then $$a = 3$$, $$m = 9$$, $$d = 27$$, so

\begin{align*} J \| = \dfloorratio{6940\dparen{\dfloorratio{235 a + 13}{19} + m − 1}}{235} + d + 1607174 \\ \| = \dfloorratio{6940\dparen{\dfloorratio{235×3 + 13}{19} + 9 − 1}}{235} + 27 + 1607174 \\ \| = \dfloorratio{6940\dparen{\dfloorratio{718}{19} + 9 − 1}}{235} + 27 + 1607174 \\ \| = \dfloorratio{6940×(37 + 9 − 1)}{235} + 27 + 1607174 \\ \| = \dfloorratio{6940×45}{235} + 27 + 1607174 \\ \| = \dfloorratio{312300}{235} + 27 + 1607174 \\ \| = 1328 + 27 + 1607174 = 1608529 \end{align*}

Some more examples:

$${a}$$ $${m}$$ $${d}$$ $${•a}$$ $${•m}$$ $${J}$$
1 1 1 13 383 1607558
1 1 30 13 383 1607587
1 2 1 13 413 1607588
1 2 29 13 413 1607616
1 3 1 13 442 1607617
2 1 1 25 738 1607913
2 1 29 25 738 1607941
2 2 1 25 767 1607942
3 9 27 37 1328 1608529
999 13 30 12356 365250 1972454
1000 1 1 12369 365280 1972455

### 9.2. From CJDN to Babylonian Date

From CJDN $$J$$, we find the Babylonian year number $$a$$, month number $$m$$, and day number $$d$$ as follows:

\begin{align} \{ m_1, ε_1 \} \| = \Div(235 J − 377685891, 6940) \\ \{ a, ε_2 \} \| = \Div(19 m_1 + 5, 235) \\ m \| = \dfloorratio{ε_2}{19} + 1 \\ d \| = \dfloorratio{ε_1}{235} + 1 \end{align}

For example, which date in the Babylonian calendar corresponds to CJDN $$1608558$$? Then $$J = 1608529$$, so

\begin{align*} \{ m_1, ε_1 \} \| = \Div(235 J − 377685891, 6940) \\ \| = \Div(235×1608529 − 377685891, 6940) \\ \| = \Div(318424, 6940) = \{ 45, 6124 \} \\ \{ a, ε_2 \} \| = \Div(19 m_1 + 5, 235) = \Div(19×45 + 5, 235) \\ \| = \Div(860, 235) = \{ 3, 155 \} \\ m \| = \dfloorratio{ε_2}{19} + 1 = \dfloorratio{155}{19} + 1 = 8 + 1 = 9 \\ d \| = \dfloorratio{ε_1}{235} + 1 = \dfloorratio{6124}{235} + 1 = 26 + 1 = 27 \end{align*}

which means day 27 of month 9 of year 3.

Some more examples:

$${J}$$ $${m_1}$$ $${ε_1}$$ $${a}$$ $${ε_2}$$ $${m}$$ $${d}$$
1607558 13 19 1 17 1 1
1607587 13 6834 1 17 1 30
1607588 14 129 1 36 2 1
1607616 14 6709 1 36 2 29
1607617 15 4 1 55 3 1
1607913 25 164 2 10 1 1
1607941 25 6744 2 10 1 29
1607942 26 39 2 29 2 1
1608529 45 6124 3 155 9 27
1972454 12368 6879 999 232 13 30
1972455 12369 174 1000 16 1 1

## 10. The Jewish Calendar

For calculations with 32-bit numbers the below formulas are usable without adjustment only for Jewish years −223 through 226 (between somewhere in Julian year −3985 and somewhere in Julian year −3534). Outside of that interval you'll get wrong results, and modern times are outside of that interval. A detour is mentioned below where appropriate, so that calculations with 32-bit numbers yield correct results for nearly 12 million years centered on now. For calculations with 64-bit numbers these detours are not necessary in practice.

See section 16.7 for the derivation of this algorithm.

### 10.1. From Jewish Date to CJDN

The Jewish calendar is a lunisolar calendar with complicated rules, and repeats itself only after 251,827,457 days = 35,975,351 weeks = 8,527,680 months = 689,472 years. The algorithm to transform a Jewish date into CJDN is long, and it features very large intermediate results.

In the Jewish calendar, a year has 12 or 13 months, and a month has 29 or 30 days. New Year is the first day of the 7th month, Tishri. The months in a year of 12 months are: 1 = Nisan (נִיסָן‎), 2 = Iyar (אִיָּר / אייר‎), 3 = Sivan (סִיוָן / סיוון‎), 4 = Tammuz (תַּמּוּז‎), 5 = Av (אָב‎), 6 = Elul (אֱלוּל‎), 7 = Tishri (תִּשׁרִי‎), 8 = Ḥeshvan (מַרְחֶשְׁוָן / מרחשוון‎), 9 = Kislev (כִּסְלֵו / כסליו‎), 10 = Tevet (טֵבֵת‎), 11 = Shevat (שְׁבָט‎), 12 = Adar (אֲדָר‎). In a year of 13 months, embolismic month Adar Ⅰ (‎אֲדָר א׳) is inserted between Shevat and regular Adar, and that regular Adar is then temporarily renamed to Adar Ⅱ (אֲדָר ב׳‎). In a year of 13 months, we count Adar Ⅰ as month number 12, and Adar Ⅱ as month number 13.

One algorithm to transform calendar year $$a$$, calendar month $$m$$ (from 1 through 12 or 13), and calendar day $$d$$ (from 1 through 29 or 30) into CJDN is then as follows.

For calculations with 32-bit numbers a detour is necessary for $$δ_3$$ and $$δ_5$$. See below.

\begin{align} m_1 \| = m − 7 \\ a_1 \| = a − \dfloorratio{m_1}{10} \\ δ_3(a_1) \| = \dfloorratio{765433 \dfloorratio{235 a_1 − 234}{19} + 12084}{25920} \\ δ_5(a_1) \| = δ_3(a_1) + \dmod{\dfloorratio{6 δ_3(a_1)}{7}}{2} \\ L_2(a_1) \| = δ_5(a_1 + 1) − δ_5(a_1) \\ d_1(a_1) \| = δ_5(a_1) + 2\dmod{\dfloorratio{L_2(a_1) + 19}{15}}{2} + \dmod{\dfloorratio{L_2(a_1 − 1) + 7}{15}}{2} \\ L \| = d_1(a_1 + 1) − d_1(a_1) \\ d_2 \| = d_1(a_1) + \dfloorratio{384 m_1 + 10}{13} + \dmod{\dfloorratio{L + 1}{2}}{3} \dfloorratio{m_1 + 10}{12} \notag \\ \| − \dmod{\dfloorratio{385 − L}{2}}{3} \dfloorratio{m_1 + 9}{12} \\ J \| = d_2 + d + 347997 \end{align}

The above formulas are partially a summary: To calculate $$L$$ you need $$d_1(a_1 )$$ and $$d_1(a_1 + 1)$$, and to calculate them you need $$L_2(a_1 − 1)$$, $$L_2(a_1)$$, and $$L_2(a_1 + 1)$$, and to calculate those you need $$δ_5(a_1 − 1)$$, $$δ_5(a_1)$$, $$δ_5(a_1 + 1)$$, and $$δ_5(a_1 + 2)$$, and for every $$δ_5$$ also the corresponding $$δ_3$$.

The calculation of $$d_2$$ could be merged into the calculation of $$J$$, but it is convenient to be able to calculate $$d_2$$ separately because it is needed for calendrical calculations in the opposite direction, from CJDN to date.

For 12 Kislev 4682 ($$a = 4682, m = 9, d = 12$$) we find

\begin{align*} m_1 \| = m − 7 = 9 − 7 = 2 \\ a_1 \| = a − \dfloorratio{m_1}{10} = 4682 − \dfloorratio{2}{10} = 4682 \\ δ_3(a_1) \| = δ_3(4682) = \dfloorratio{765433 \dfloorratio{235 a_1 − 234}{19} + 12084}{25920} \\ \| = \dfloorratio{765433 \dfloorratio{235×4682 − 234}{19} + 12084}{25920} \\ \| = \dfloorratio{765433 \dfloorratio{1100036}{19} + 12084}{25920} \\ \| = \dfloorratio{765433×57896 + 12084}{25920} \\ \| = \dfloorratio{44315521052}{25920} = 1709703 \\ δ_3(a_1 − 1) \| = δ_3(4681) = 1709349 \\ δ_3(a_1 + 1) \| = δ_3(4683) = 1710087 \\ δ_3(a_1 + 2) \| = δ_3(4684) = 1710442 \\ δ_5(a_1) \| = δ_5(4682) = δ_3(a_1) + \dmod{\dfloorratio{6 δ_3(a_1)}{7}}{2} \\ \| = 1709703 + \dmod{\dfloorratio{6×1709703}{7}}{2} \\ \| = 1709703 + \dmod{\dfloorratio{10258218}{7}}{2} \\ \| = 1709703 + \dmod{1465459}{2} = 1709704 \\ δ_5(a_1 − 1) \| = δ_5(4681) = 1709349 \\ δ_5(a_1 + 1) \| = δ_5(4683) = 1710087 \\ δ_5(a_1 + 2) \| = δ_5(4684) = 1710443 \\ L_2(a_1) \| = L_2(4682) = δ_5(a_1 + 1) − δ_5(a_1) \\ \| = δ_5(4683) − δ_5(4682) = 1710087 − 1709704 = 383 \\ L_2(a_1 − 1) \| = L_2(4681) = δ_5(4682) − δ_5(4681) = 1709704 − 1709349 = 355 \\ L_2(a_1 + 1) \| = L_2(4683) = δ_5(4684) − δ_5(4683) = 1710443 − 1710087 = 356 \\ d_1(a_1) \| = d_1(4682) = δ_5(a_1) + 2\dmod{\dfloorratio{L_2(a_1) + 19}{15}}{2} + \dmod{\dfloorratio{L_2(a_1 − 1) + 7}{15}}{2} \\ \| = δ_5(4682) + 2\dmod{\dfloorratio{L_2(4682) + 19}{15}}{2} + \dmod{\dfloorratio{L_2(4681) + 7}{15}}{2} \\ \| = 1709704 + 2\dmod{\dfloorratio{383 + 19}{15}}{2} + \dmod{\dfloorratio{355 + 7}{15}}{2} \\ \| = 1709704 + 2\dmod{\dfloorratio{402}{15}}{2} + \dmod{\dfloorratio{362}{15}}{2} \\ \| = 1709704 + 2×\dmod{26}{2} + \dmod{24}{2} = 1709704 \\ d_1(a_1 + 1) \| = d_1(4683) = δ_5(4683) + 2\dmod{\dfloorratio{L_2(4683) + 19}{15}}{2} + \dmod{\dfloorratio{L_2(4682) + 7}{15}}{2} \\ \| = 1710087 + 2\dmod{\dfloorratio{356 + 19}{15}}{2} + \dmod{\dfloorratio{383 + 7}{15}}{2} \\ \| = 1710087 + 2\dmod{\dfloorratio{375}{15}}{2} + \dmod{\dfloorratio{390}{15}}{2} \\ \| = 1710087 + 2×\dmod{25}{2} + \dmod{26}{2} \\ \| = 1710087 + 2×1 + 0 = 1710089 \\ L \| = d_1(a_1 + 1) − d_1(a_1) = d_1(4683) − d_1(4682) = 1710089 − 1709704 = 385 \\ d_2 \| = d_1(a_1) + \dfloorratio{384 m_1 + 10}{13} + \dmod{\dfloorratio{L + 1}{2}}{3} \dfloorratio{m_1 + 10}{12} \\ \| − \dmod{\dfloorratio{385 − L}{2}}{3} \dfloorratio{m_1 + 9}{12} \\ \| = d_1(4682) + \dfloorratio{384×2 + 10}{13} + \dmod{\dfloorratio{385 + 1}{2}}{3} \dfloorratio{2 + 10}{12} \\ \| − \dmod{\dfloorratio{385 − 385}{2}}{3} \dfloorratio{2 + 9}{12} \\ \| = 1709704 + \dfloorratio{778}{13} + \dmod{\dfloorratio{386}{2}}{3} \dfloorratio{12}{12} − \dmod{\dfloorratio{0}{2}}{3} \dfloorratio{11}{12} \\ \| = 1709704 + 59 + \dmod{193}{3}×1 − 0×0 \\ \| = 1709704 + 59 + 1×1 − 0×0 = 1709764 \\ J \| = d_2 + d + 347997 = 1709764 + 12 + 347997 = 2057773 \end{align*}

For calculations with 32-bit numbers you need detours for $$δ_3$$ and $$δ_5$$ because otherwise the intermediate results get too large to be 32-bit numbers. Without those detours you only get correct results for a period of about 450 years around the Jewish year 1, which corresponds roughly to the Julian year ―3759.

For $$δ_3$$, use

\begin{align} m_2 \| = \dfloorratio{235 a_1 − 234}{19} \\ \{ ω_4, μ_2 \} \| = \Div(m_2, 25920) \\ δ_3 \| = 29 m_2 + 13753 ω_4 + \dfloorratio{13753 μ_2 + 12084}{25920} \end{align}

$$δ_3 = \dfloorratio{765433 \dfloorratio{235 a_1 − 234}{19} + 12084}{25920}$$

and for $$δ_5$$ use

$$δ_5 = δ_3 + \dmod{\dfloorratio{6\dmod{δ_3}{7}}{7}}{2}$$

$$δ_5 = δ_3 + \dmod{\dfloorratio{6 δ_3}{7}}{2}$$

If you calculate using 32-bit numbers then the original formulas do not yield the correct CJDN because some intermediate results are then too large to fit in 32-bit numbers. Then we need the deviations. For $$a_1 = 4682$$ we find using the original formula for $$δ_3$$

\begin{align*} δ_3 \| = \dfloorratio{765433 \dfloorratio{235 a_1 − 234}{19} + 12084}{25920} = \dfloorratio{765433 \dfloorratio{235×4682 − 234}{19} + 12084}{25920} \\ \| = \dfloorratio{765433 \dfloorratio{1100036}{19} + 12084}{25920} = \dfloorratio{765433×57896 + 12084}{25920} \\ \| = \dfloorratio{44315521052}{25920} = 1709703 \end{align*}

The largest intermediate result is equal to 44'315'521'052 which is far too great to be a 32-bit number. With the detour formulas we find

\begin{align*} m_2 \| = \dfloorratio{235 a_1 − 234}{19} = \dfloorratio{235×4682 − 234}{19} \\ \| = \dfloorratio{1100036}{19} = 57896 \\ \{ ω_4, μ_2 \} \| = \Div(m_2, 25920) = \Div(57896, 25920) = \{ 2, 6056 \} \\ δ_3 \| = 29 m_2 + 13753 ω_4 + \dfloorratio{13753 μ_2 + 12084}{25920} \\ \| = 29×57896 + 13753×2 + \dfloorratio{13753×6056 + 12084}{25920} \\ \| = 1678984 + 27506 + \dfloorratio{83300252}{25920} = 1678984 + 27506 + 3213 = 1709703 \end{align*}

which yields the same result as before, but now the largest intermediate result is 83'300'252 which is small enough for a 32-bit number.

With $$δ_3 = 456789012$$ we find with the original formula for $$δ_5$$

\begin{align*} δ_5 \| = δ_3 + \dmod{\dfloorratio{6 δ_3}{7}}{2} = 456789012 + \dmod{\dfloorratio{6×456789012}{7}}{2} \\ \| = 456789012 + \dmod{\dfloorratio{2740734072}{7}}{2} = 456789012 + \dmod{391533438}{2} \\ \| = 456789012 + 0 = 456789012 \end{align*}

with the largest intermediate result equal to 2'740'734'072 which is too large to be a 32-bit number. With the detour we find

\begin{align*} δ_5 \| = δ_3 + \dmod{\dfloorratio{6\dmod{δ_3}{7}}{7}}{2} = 456789012 + \dmod{\dfloorratio{6\dmod{456789012}{7}}{7}}{2} \\ \| = 456789012 + \dmod{\dfloorratio{6×1}{7}}{2} = 456789012 + \dmod{\dfloorratio{6}{7}}{2} \\ \| = 456789012 + \dmod{0}{2} = 456789012 \end{align*}

so the same result as before but now the greatest intermediate result is 456'789'012 which is small enough for a 32-bit number.

### 10.2. From CJDN to Jewish Calendar

From CJDN $$J$$ we go to Jewish year $$a$$, month $$m$$, and day $$d$$ as follows.

For calculations with 32-bit numbers a detour is needed. See below.

\begin{align} s \| = J − 347998 \\ μ_3 \| = \dfloorratio{25920 s + 779268}{765433} \\ \{ α_3, ε_3 \} \| = \Div(19 μ_3 + 366, 235) \\ μ_4 \| = \dfloorratio{ε_3}{19} − 6 \\ δ_{14} \| = s − d_2(α_3, μ_4) \\ μ_5 \| = μ_3 + \dfloorratio{δ_{14}}{64} \\ \{ α_4, ε_4 \} \| = \Div(19 μ_5 + 366, 235) \\ μ_6 \| = \dfloorratio{ε_4}{19} − 6 \\ δ_{15} \| = s − d_2(α_4, μ_6) \\ μ_7 \| = μ_5 + \dfloorratio{δ_{15}}{64} \\ \{ a_1, ε_5 \} \| = \Div(19 μ_7 + 366, 235) \\ m_1 \| = \dfloorratio{ε_5}{19} − 6 \\ d_0 \| = s − d_2(a_1, m_0) \\ a \| = a_1 + \dfloorratio{m_1}{10} \\ m \| = m_1 + 7 \\ d \| = d_0 + 1 \end{align}

where $$d_2$$ is calculated as in the previous section (Eq. \eqref{eq:jewishd2}).

For CJDN 2057773 we find

\begin{align*} s \| = J − 347998 = 2057773 − 347998 = 1709775 \\ μ_3 \| = \dfloorratio{25920 s + 779268}{765433} = \dfloorratio{25920×1709775 + 779628}{765433} \\ \| = \dfloorratio{44318147628}{765433} = 57899 \\ \{ α_3, ε_3 \} \| = \Div(19 μ_3 + 366, 235) = \Div(19×57899 + 366, 235) \\ \| = \Div(1100447, 235) = \{ 4682, 177 \} \\ μ_4 \| = \dfloorratio{ε_3}{19} − 6 = \dfloorratio{177}{19} − 6 = 9 − 6 = 3 \\ δ_{14} \| = s − d_2(α_3, μ_4) = 1709775 − d_2(4682, 3) = 1709775 − 1709794 = −19 \\ μ_5 \| = μ_3 + \dfloorratio{δ_{14}}{64} = 57899 + \dfloorratio{−19}{64} = 57899 − 1 = 57898 \\ \{ α_4, ε_4 \} \| = \Div(19 μ_5 + 366, 235) = \Div(19×57898 + 366, 235) \\ \| = \Div(1100428, 235) = \{ 4682, 158 \} \\ μ_6 \| = \dfloorratio{ε_4}{19} − 6 = \dfloorratio{158}{19} − 6 = 8 − 6 = 2 \\ δ_{15} \| = s − d_2(α_4, μ_6) = 1709775 − d_2(4682, 2) = 1709775 − 1709764 = 11 \\ μ_7 \| = μ_5 + \dfloorratio{δ_{15}}{64} = 57898 + \dfloorratio{11}{64} = 57898 + 0 = 57898 \\ \{ a_1, ε_5 \} \| = \Div(19 μ_7 + 366, 235) = \Div(19×57898 + 366, 235) = \{ 4682, 158 \} \\ m_1 \| = \dfloorratio{ε_5}{19} − 6 = \dfloorratio{158}{19} − 6 = 2 \\ d_0 \| = s − d_2(a_1, m_0) = 1709775 − d_2(4682, 2) = 11 \\ a \| = a_1 + \dfloorratio{m_1}{10} = 4682 + \dfloorratio{2}{10} = 4682 + 0 = 4682 \\ m \| = m_1 + 7 = 2 + 7 = 9 \\ d \| = d_0 + 1 = 11 + 1 = 12 \end{align*}

so the date is day 12 of calendar month 9 (Kislev) of year 4682.

If you use 32-bit numbers then you need a detour for the calculation of $$μ_3$$, otherwise some intermediate results can be too large to be a 32-bit number. Without the detour you only get correct results for a period of about 450 years around the Jewish year 1, which corresponds roughly with Julian year −3759.

For $$μ_3$$, use

\begin{align} \{ ω_1, ε_1 \} \| = \Div(s, 33783) \\ μ_3 \| = 1144 ω_1 + \dfloorratio{8 ω_1 + 25920 ε_1 + 13835}{765433} + 1 \end{align}

$$μ_3 = \dfloorratio{25920 s + 779268}{765433}$$

For $$s = 1709775$$ we find, using the original formula

\begin{align*} μ_3 \| = \dfloorratio{25920 s + 779268}{765433} = \dfloorratio{25920×1709775 + 779268}{765433} \\ \| = \dfloorratio{44318147268}{765433} = 57899 \end{align*}

The greatest intermediate result is 44'318'147'268 which is far too great to be a 32-bit number. If you do this calculation using 32-bit numbers then you'll get a result that is a 32-bit result but it cannot be the correct result.

With the detour we find

\begin{align*} \{ ω_1, ε_1 \} \| = \Div(s, 33783) = \Div(1709775, 33783) = \{ 50, 20625 \} \\ μ_3 \| = 1144 ω_1 + \dfloorratio{8 ω_1 + 25920 ε_1 + 13835}{765433} + 1 \\ \| = 1144×50 + \dfloorratio{8×50 + 25920×20625 + 13835}{765433} + 1 \\ \| = 57200 + \dfloorratio{534614235}{765433} + 1 \\ \| = 57200 + 698 + 1 = 57899 \end{align*}

which is the same result as before, but now the largest intermediate result is 534'614'235 which is comfortably small enough to be a 32-bit number.

## 11. The Egyptian Calendar

For calculations with 32-bit numbers the below formulas are usable for Egyptian years −5'883'516 through 5'879'547.

See section 16.5 for the derivation of this algorithm.

The ancient Egyptians had a very simple calendar indeed, without leap years and with 30 days to every month, except that the last month had 5 days. In the calendar according to the Era of Nabonassar the first day (1 Thoth of year 1) was equivalent to 26 February −746 in the Julian calendar.

### 11.1. From Egyptian Date to CJDN

The algorithm to translate an Egyptian date (calendar year $$a$$, calendar month $$m$$, calendar day $$d$$) to CJDN $$J$$ is as follows:

$$J = 365 a + 30 m + d + 1448242$$

For example, which CJDN corresponds to day 7 of month 5 of year 218 in the Egyptian calendar? Then we find

\begin{align*} J \| = 365 a + 30 m + d + 1448242 \\ \| = 365×218 + 30×5 + 7 + 1448242 \\ \| = 79570 + 150 + 7 + 1448242 = 1527969 \end{align*}

so the answer is CJDN 1527969.

### 11.2. From CJDN to Egyptian Date

In the opposite direction, the calculations are simple as well.

\begin{align} \{ a, d_1 \} \| = \Div(J − 1448273, 365) \\ \{ m_0, d_0 \} \| = \Div(d_1, 30) \\ m \| = m_0 + 1 \\ d \| = d_0 + 1 \end{align}

What date in the Egyptian calendar corresponds to CJDN 1527969? Then

\begin{align*} \{ a, d_1 \} \| = \Div(J − 1448273, 365) = \Div(1527969 − 1448273, 365) \\ \| = \Div(79696, 365) = \{ 218, 126 \} \\ \{ m_0, d_0 \} \| = \Div(d_1, 30) = \Div(126, 30) = \{ 4, 6 \} \\ m \| = m_0 + 1 = 4 + 1 = 5 \\ d \| = d_0 + 1 = 6 + 1 = 7 \end{align*}

so it is day 7 of month 5 of year 218.

## 12. The Maya Calendar

### 12.1. From Maya Calendar to CJDN

The Maya from Anahuac (Central America) used three different calendars, of which two (the Tzolkin and Haab) were periodic with fairly short periods, and the third one (the Long Count) might have been intended to be periodic but has some periods that are so long that it can be considered to be continuous rather than repeating.

Different areas in Central America had slightly different versions of these calendars, with different names for days and months, and different ways to indicate years, and sometimes days were counted from 0 rather than from 1. Below we describe the calendars from the city of Tikal.

#### 12.1.1. From Haab to CJDN

The Haab has a day number and a month, but no year number. There are 18 months of 20 days, plus a 19th month of 5 days, which makes 365 days in total, which we call a Haab year. There are no leap years. The months have a name, and the days have a number beginning at 0.

We write a date in the Haab as $$\{ h_d, h_m \}$$ where $$h_d$$ is the day number (from 0 through 19) and $$h_m$$ is the month number (from 1 through 19).

There is no year number in the Haab, so a particular Haab date $$\{ h_d, h_m \}$$ returns every 365 days. We need to apply additional information to pick the right one. We can find the last CJDN $$J$$ on or before a particular CJDN $$J_0$$ that corresponds to this Haab date, as follows:

\begin{align} H \| = h_d + 20 (h_m − 1) \\ J \| = J_0 − \dmod{J_0 − H + 65}{365} \end{align}

What is the last CJDN in the year 1965 that corresponds to Haab date $$\{ 5, 13 \}$$? Then $$h_d = 5$$, $$h_m = 13$$, $$J_0 = 2439126$$ (which corresponds to 31 December 1965), so

\begin{align*} H \| = h_d + 20 (h_m − 1) = 5 + 20×(13 − 1) = 245 \\ J \| = J_0 − \dmod{J_0 − H + 65}{365} = 2439126 − \dmod{2439126 − 245 + 65}{365} \\ \| = 2439126 − \dmod{2438946}{365} = 2439126 − 16 = 2439110 \end{align*}

so the answer is CJDN 2439110.

#### 12.1.2. From Tzolkin to CJDN

The Tzolkin has a period of 20 days (the venteina) with a name for each day, and a period of 13 days (the trecena) with a number for each day (beginning at 1).

We write a date in the Tzolkin as $$\{ t_t, t_v \}$$, where $$t_t$$ is the day number in the trecena (from 1 through 13) and $$t_v$$ is the day number in the venteina (from 1 through 20).

The trecena and venteina increase simultaneously, so after day $$\{ 4, 7 \}$$ comes day $$\{ 5, 8 \}$$, and then $$\{ 6, 9 \}$$, and so on. Because 13 and 20 are relatively prime, all possible combinations of venteina and trecena occur in this calendar, so after 13×20 = 260 days the dates repeat again.

There is no year number in the Tzolkin so a particular Tzolkin date returns every 260 days. We can find the last CJDN $$J$$ that corresponds to Tzolkin date $$\{ t_t, t_v \}$$ on or before a particular CJDN $$J_0$$ as follows:

$$J = J_0 − \dmod{J_0 − 40 t_t + 39 t_v + 97}{260}$$

The last Tzolkin date $$\{ 4, 7 \}$$ that occurs on or before 31 December 1965 (= CJDN 2439126) is

\begin{align*} J \| = 2439126 − \dmod{2439126 − 40×4 + 39×7 + 97}{260} \\ \| = 2439126 − \dmod{2439336}{260} = 2439126 − 16 = 2439110 \end{align*}

so the answer is CJDN 2439110.

For the number of days $$T$$ since the last $$\{ 1, 1 \}$$ we have

$$T = \dmod{40 t_t + 221 t_v − 1}{260}$$

For CJDN 2439110 (with $$\{ t_t, t_v \} = \{ 4, 7 \}$$) we find

$T = \dmod{40×4 + 221×7 − 1}{260} = \dmod{1706}{260} = 146$

so the last day before then that had $$\{ 1, 1 \}$$ was CJDN $$J = 2439110 − 146 = 2438964$$, and that is correct because $$t_t = \dmod{J + 5}{13} + 1 = \dmod{2438969}{13} + 1 = 1$$ and $$t_v = \dmod{J + 16}{20} + 1 = \dmod{2438980}{20} + 1 = 1$$.

#### 12.1.3. From Tzolkin and Haab to CJDN

Sometimes a date is indicated in both Tzolkin and Haab. The CJDN $$J$$ of the last Tzolkin/Haab date $$\{ h_d, h_m, t_t, t_v \}$$ on or before CJDN $$J_0$$ is:

\begin{align} H \| = \dmod{h_d + 20 (h_m − 1)}{365} \\ T \| = \dmod{40t_t + 221 t_v − 1}{260} \\ J \| = J_0 − \dmod{J_0 − 365 T + 364 H − 7600}{18980} \end{align}

The Tzolkin and Haab together have a period of 18980 days, which is approximately 52 years.

Which CJDN is the last one before the end of 1965 that corresponds to $$\{t_t, t_v, h_d, h_m \} = \{ 4, 7, 5, 13\}$$? Then $$J_0 = 2439126$$ and

\begin{align*} H \| = \dmod{5 + 20×12}{365} = \dmod{245}{365} = 245 \\ T \| = \dmod{40×4 + 221×7 − 1}{260} = \dmod{1706}{260} = 146 \\ J \| = 2439126 − \dmod{2439126 − 365×146 + 364×245 − 7600}{18980} \\ \| = 2439126 − \dmod{2467416}{18980} \\ \| = 2439126 − 16 = 2439110 \end{align*}

Beware! Not all possible combinations of $$\{ h_d, h_m, t_t, t_v \}$$ occur in the calendar. You can fill in any combination you like in the preceding formulas, but you'll get useful results only for combinations that really occur in the calendar. Those are combinations for which $$H − T ≡ 65 − 96 ≡ 4 \pmod{5}$$.

In the example that we've been using we have $$H = 245$$ and $$T = 146$$, so $$H − T = 99 ≡ 4 \pmod{5}$$, so this combination indeed occurs in this calendar.

#### 12.1.4. From the Long Count to CJDN

The Long Count counts days and has a series of increasingly longer periods. The smallest period is 20 days, the next one is 18 times longer (i.e., 360 days), and after that each next period is 20 times longer than the previous one. The number for each period begins at 0. Often dates in the Long Count are given with five numbers, but even longer periods are known, up to nine numbers. The longest known period corresponds to about 63 million years. Here we assume that the Long Count has five numbers, and that the fifth number can get arbitrarily long.

The epoch 0.0.0.0.0 of the Long Count probably corresponds to CJDN $$J_0 = 584283$$ (6 September −3113 in the Julian calendar).

Translating a Long Count to CJDN goes as follows:

\begin{align} J \| = l_1 + 20×(l_2 + 18×(l_3 + 20×(l_4 + 20×l_5))) + J_0 \notag \\ \| = l_1 + 20×l_2 + 360×l_3 + 7200×l_4 + 144000×l_5 + 584283 \end{align}

Which CJDN corresponds to Long Count $$L = 12.17.12.5.7$$? Then

$J = 7 + 20×(5 + 18×(12 + 20×(17 + 20×12))) + 584283 = 2439110$

### 12.2. From CJDN to the Maya Calendar

#### 12.2.1. From CJDN to Haab

We calculate Haab date $$\{ h_d, h_m \}$$ from CJDN $$J$$ as follows:

\begin{align} H \| = \dmod{J + 65}{365} \\ h_m \| = \dfloorratio{H}{20} + 1 \\ h_d \| = \dmod{H}{20} \end{align}

$$H$$ is the number of days since the beginning of the current Haab year (with $$H = 0$$ for the first day of the Haab year).

For example, which Haab date corresponds to 15 December 1965 = CJDN 2439110? Then $$J = 2439110$$ and

\begin{align*} H \| = \dmod{J + 65}{365} = \dmod{2439175}{365} = 245 \\ h_m \| = \dfloorratio{245}{20} + 1 = 13 \\ h_d \| = \dmod{245}{20} = 5 \end{align*}

so that day is 245 days since the beginning of the current Haab year and corresponds to the 5th day of the 13th month, i.e., $$\{ 5, 13 \}$$.

#### 12.2.2. From CJDN to Tzolkin

We translate CJDN $$J$$ to a Tzolkin date $$\{ t_t, t_v \}$$ as follows:

\begin{align} t_t \| = \dmod{J + 5}{13} + 1 \label{eq:trecena} \\ t_v \| = \dmod{J + 16}{20} + 1 \label{eq:venteina} \end{align}

What is the Tzolkin date corresponding to CJDN 2439110? Then

\begin{align*} t_t \| = \dmod{2439110 + 5}{13} + 1 = 3 + 1 = 4 \\ t_v \| = \dmod{2439110 + 16}{20} + 1 = 6 + 1 = 7 \end{align*}

so that date is $$\{ 4, 7 \}$$.

#### 12.2.3. From CJDN to the Long Count

Translating CJDN $$J$$ to Long Count $$L ≡ l_5.l_4.l_3.l_2.l_1$$ goes as follows:

\begin{align} \{ l_5, ε_5 \} \| = \Div(J − 584283, 144000) \\ \{ l_4, ε_4 \} \| = \Div(ε_5, 7200) \\ \{ l_3, ε_3 \} \| = \Div(ε_4, 360) \\ \{ l_2, l_1 \} \| = \Div(ε_3, 20) \end{align}

Which Long Count $$L$$ corresponds to CJDN $$J = 2439110$$? Then

\begin{align*} \{ l_5, ε_5 \} \| = \Div(J − 584283, 144000) = \Div(2439110 − 584283, 144000) \\ \| = \Div(1854827, 144000) = \{ 12, 126827 \} \\ \{ l_4, ε_4 \} \| = \Div(ε_5, 7200) = \Div(126827, 7200) = \{ 17, 4427 \} \\ \{ l_3, ε_3 \} \| = \Div(ε_4, 360) = \Div(4427, 360) = \{ 12, 107 \} \\ \{ l_2, l_1 \} \| = \Div(ε_3, 20) = \Div(107, 20) = \{ 5, 7 \} \end{align*}

The answer is $$L = 12.17.12.5.7$$.

## 13. A LunisolarCalendar With Many Fixed Month Lengths

I've designed a lunisolar calendar in which nearly all months have the same number of days in every calendar year. The calendar follows the seasons by means of the Cycle of Meton, which lasts 19 years. Each year contains 12 or 13 months. The "shortest" years of 12 months contain 354 days. The "short" years of 12 months contain 355 days. The "long" years of 13 months contain 384 days. The year lengths are:

Year Months Days Type
1 12 354 shortest
2 12 355 short
3 13 384 long
4 12 354 shortest
5 12 354 shortest
6 13 384 long
7 12 355 short
8 13 384 long
9 12 354 shortest
10 12 354 shortest
11 13 384 long
12 12 355 short
13 12 354 shortest
14 13 384 long
15 12 354 shortest
16 12 355 short
17 13 384 long
18 12 354 shortest
19 13 384 long

All together there are 235 months (125 long, 110 short) and 6940 days in the cycle of 19 years.

All odd months (except for the 13th) contain 30 days, and all even months contain 29 days, except that in short and long years (of 355 and 384 days) the 12th month contains 30 days instead of 29.

Month 354 355 384
1 30 30 30
2 29 29 29
3 30 30 30
4 29 29 29
5 30 30 30
6 29 29 29
7 30 30 30
8 29 29 29
9 30 30 30
10 29 29 29
11 30 30 30
12 29 30 30
13 29

I linked this calendar to the Gregorian calendar such that

1. the calendar year in this calendar corresponds approximately with the Gregorian calendar year, so, for example, year 2022 in this calendar corresponds approximately with Gregorian calendar year 2022.

2. on average every month in this calendar begins at New Moon.

3. the calendar year in this calendar on average begins at the northern solstice (21 December in the Gregorian calendar).

4. this calendar follows the lunar cycle and seasons on average the closest in the 20th and 21st centuries. This calendar is based on the Cycle of Meton and will, as does every calendar that is based on a fixed cycle, eventually get more and more out of step with the lunar cycle and seasons.

For calculations with 32-bit numbers the below formulas are usable for years −309'435 through 309'434.

See Sec. 16.8 for the derivation of these formulas, and for how you can increase the usable range of the formulas to the maximum of (for 32-bit numbers) 11.8 million years.

### 13.1. From LunarCalendar to CJDN

Given year $$a$$, month $$m$$, and day $$d$$ in this lunar calendar, the CJDN $$J$$ can be calculated as follows:

$$J = 354 a + 30\dfloorratio{7 a + 2}{19} + \dfloorratio{4 a + 18}{19} + \dfloorratio{384 m − 377}{13} + d + 1721018$$

For example, which running day number corresponds to day 28 of month 7 of year 2022 in this calendar? Then

\begin{align*} J \| = 354 a + 30\dfloorratio{7 a + 2}{19} + \dfloorratio{4 a + 18}{19} \\ \| + \dfloorratio{384 m − 377}{13} + d + 1721018 \\ \| = 354×2022 + 30\dfloorratio{7×2022 + 2}{19} + \dfloorratio{4×2022 + 18}{19} \\ \| + \dfloorratio{384×7 − 377}{13} + 28 + 1721018 \\ \| = 715788 + 30\dfloorratio{14156}{19} + \dfloorratio{8106}{19} \\ \| + \dfloorratio{2311}{13} + 28 + 1721018 \\ \| = 715788 + 30×745 + 426 + 177 + 28 + 1721018 \\ \| = 715788 + 22350 + 426 + 177 + 28 + 1721018 = 2459787 \end{align*}

so the answer is CJDN 2459787, which corresponds to 26 July 2022.

Some more examples (with the corresponding Gregorian date in column "Greg."):

$${a}$$ $${m}$$ $${d}$$ $${•354 a}$$ $${•7 a}$$ $${•4 a}$$ $${•m}$$ $${J}$$ Greg.
2022 7 28 715788 22350 426 177 2459787 2022-07-26
2022 12 29 715788 22350 426 325 2459936 2022-11-22
2023 1 1 716142 22350 426 0 2459937 2022-11-23
2023 12 30 716142 22350 426 325 2460291 2022-12-12
2024 1 1 716496 22350 427 0 2460292 2022-12-13
2024 13 29 716496 22350 427 355 2460675 2024-12-30
2025 1 1 716850 22380 427 0 2460676 2024-12-31
2025 12 29 716850 22380 427 325 2461029 2031-12-13
2032 1 1 719328 22440 428 0 2463215 2031-12-14
2022 13 29 715788 22350 426 355 2459966 2032-12-31
2033 1 1 719682 22470 428 0 2463599 2033-01-01

### 13.2. From CJDN to LunarCalendar

Given CJDN $$J$$, we calculate year $$a$$, month $$m$$, and day $$d$$ in this lunar calendar as follows:

\begin{align} s \| = J − 1721019 \\ α_1 \| = \dfloorratio{19 s + 511}{6940} \\ δ_1 \| = s − 354 α_1 − 30 \dfloorratio{7 α_1 + 2}{19} − \dfloorratio{4 α_1 + 18}{19} \\ a \| = α_1 + \dfloorratio{δ_1}{385} \\ d_1 \| = s − 354 a − 30 \dfloorratio{7 a + 2}{19} − \dfloorratio{4 a + 18}{19} \\ \{ m, ε_1 \} \| = \Div(13 d_1 + 389, 384) \\ d \| = \dfloorratio{ε_1}{13} + 1 \end{align}

For example, which day in this calendar corresponds to CJDN 2459787? Then $$J = 2459787$$ and then

\begin{align*} s \| = J − 1721019 = 2459787 − 1721019 = 738768 \\ α_1 \| = \dfloorratio{19 s + 511}{6940} = \dfloorratio{19×738768 + 511}{6940} \\ \| = \dfloorratio{14037103}{6940} = 2022 \\ δ_1 \| = s − 354 α_1 − 30 \dfloorratio{7 α_1 + 2}{19} − \dfloorratio{4 α_1 + 18}{19} \\ \| = 738768 − 354×2022 − 30 \dfloorratio{7×2022 + 2}{19} − \dfloorratio{4×2022 + 18}{19} \\ \| = 738768 − 715788 − 30 \dfloorratio{14156}{19} − \dfloorratio{8106}{19} \\ \| = 22980 − 30×745 − 426 = 204 \\ a \| = α_1 + \dfloorratio{δ_1}{385} = 2022 + \dfloorratio{204}{385} = 2022 \\ d_1 \| = s − 354 a − 30 \dfloorratio{7 a + 2}{19} − \dfloorratio{4 a + 18}{19} = 204 \\ \{ m, ε_1 \} \| = \Div(13 d_1 + 389, 384) = \Div(13×204 + 389, 384) \\ \| = \Div(3041, 384) = \{ 7, 353 \} \\ d \| = \dfloorratio{ε_1}{13} + 1 = \dfloorratio{353}{13} + 1 = 27 + 1 = 28 \end{align*}

so the date is day 28 of month 7 of year 2022.

Some more examples:

$${ J }$$ $${ s }$$ $${α_1}$$ $${δ_1}$$ $${a}$$ $${d_1}$$ $${m}$$ $${ε_1}$$ $${d}$$
2459787 738768 2022 204 2022 204 7 353 28
2459936 738917 2023 −1 2022 353 12 370 29
2459937 738918 2023 0 2023 0 1 5 1
2460291 739272 2024 −1 2023 354 12 383 30
2460292 739273 2024 0 2024 0 1 5 1
2460675 739656 2025 −1 2024 383 13 376 29
2460676 739657 2025 0 2025 0 1 5 1
2463214 742195 2032 −1 2031 353 12 370 29
2463215 742196 2032 0 2032 0 1 5 1
2463598 742579 2033 −1 2032 383 13 376 29
2463599 742580 2033 0 2033 0 1 5 1

## 14. The Chinese Calendar

The Chinese calendar is a lunisolar calendar. The date of Chinese New Year depends on the position of the Sun and the Moon, but a precise method for calculating those positions has not been fixed. Here I discuss a few characteristics of the Chinese calendar.

### 14.1. The Year of the Monkey

In the traditional Chinese calendar, each year has a name from a cycle of 10 celestial stems and a name from a cycle of 12 terrestrial branches. For each next year both the celestial stem and terrestrial branch advance by one. The (untranslatable) celestial stems are 1. jiǎ, 2. yǐ, 3. bǐng, 4. dīng, 5. wù, 6. jǐ, 7. gēng, 8. xīn, 9. rén, 10. guǐ. The terrestrial branches are 1. zǐ (rat), 2. chǒu (ox), 3. yín (tiger), 4. mǎo (rabbit), 5. chén (dragon), 6. sì (snake), 7. wǔ (horse), 8. wèi (goat), 9. shēn (monkey), 10. yǒu (rooster), 11. xū (dog), 12. hài (pig).

You can calculate the celestial stem $$s$$ (1 through 10) and terrestrial branch $$b$$ (1 through 12) from the (astronomical) Gregorian year number $$a$$ as follows:

\begin{align} s \| = \dmod{a + 6}{10} + 1 \label{eq:jnaarchinees} \\ b \| = \dmod{a + 8}{12} + 1 \end{align}

The number $$n$$ in the combined cycle of 60 years is

$$n = \dmod{a + 56}{60} + 1$$

For example, for the year 2000 in the Gregorian calendar:

\begin{align*} s \| = \dmod{2000 + 6}{10} + 1 = 6 + 1 = 7 \\ b \| = \dmod{2000 + 8}{12} + 1 = 4 + 1 = 5 \\ n \| = \dmod{2000 + 56}{60} + 1 = 16 + 1 = 17 \end{align*}

so early in the Gregorian year 2000 a Chinese Year of the Metal Dragon began, of the gēng branch (gēngchén).

The years that have a particular celestial stem $$s$$ or terrestrial branch $$b$$ or combination $$n$$ are

\begin{align} a \| ≡ 1983 + s \pmod{10} \\ a \| ≡ 1983 + b \pmod{12} \\ a \| ≡ 1983 + n \pmod{60} \end{align}

The years that have celestial stem $$s$$ as well as terrestrial branch $$b$$ are

$$a ≡ 1983 + 25 b − 24 s \pmod{60} \label{eq:chineesnaarj}$$

For example, for $$s = 7$$ we find

$a ≡ 1983 + 7 = 1990 \pmod{10}$

so 1990 and every 10 years earlier or later, so 2000 fits, too.

For $$b = 5$$ we find

$a ≡ 1983 + 5 = 1988 \pmod{12}$

so 1988 and every 12 years earlier or later, so 2000 fits, too.

For $$s = 7$$ and $$b = 5$$ we find

$a ≡ 1983 + 25×5 − 24×7 = 1940 \pmod{60}$

so 1940 and every 60 years earlier or later, so 2000 fits, too.

Beware! Not every combination of $$s$$ and $$b$$ is valid! Only combinations for which $$s ≡ b \pmod{2}$$ are valid, so the difference between $$s$$ and $$b$$ must be even.

For example, the combination $$s = 3$$ and $$b = 6$$ does not occur in this calendar, so is not valid. If you enter that combination into equation \ref{eq:chineesnaarj} then you get an answer that looks reasonable: $$a ≡ 1983 + 25×6 − 24×3 = 2061 \pmod{60}$$, but if you enter $$a = 2061$$ into equations \ref{eq:jnaarchinees}ff then you get $$s = 8$$ and $$b = 6$$, a different (and valid) combination than the one that you started with.

### 14.2. HYSN

The HYSN system is a special way to assign a number to a year. The conversion of a Gregorian (or Julian proleptic) year number to a HYSN year number goes as follows:

\begin{align} \{ H − 1, a_2 \} \| = \Div(a + 67016, 10800) \\ \{ Y − 1, a_3 \} \| = \Div(a_2, 360) \\ \{ S − 1, N − 1 \} \| = \Div(a_3, 30) \end{align}

For example, which HYSN year corresponds approximately to our year 2016? Then

\begin{align*} a \| = 2016 \\ \{ H − 1, a_2 \} \| = \Div(a + 67016. 10000) = \Div(2016 + 67016, 10800) \\ \| = \Div(69032, 10800) = \{ 6, 4232 \} \\ \{ Y − 1, a_3 \} \| = \Div(a_2, 360) = \Div(4232, 360) = \{ 11, 272 \} \\ \{ S − 1, N − 1 \} \| = \Div(a_3, 30) = \Div(272, 30) = \{ 9, 2 \} \end{align*}

so $$H = 7$$, $$Y = 2$$, $$S = 10$$, $$N = 3$$, and the HYSN year number is 0712-1003.

In the other direction things are simpler. Given $$H$$, $$Y$$, $$S$$, and $$N$$, the Gregorian year is

$$a = 1000 H + 360 Y + 30 S + N − 78207$$

For example, HYSN 0712-1003 means

\begin{align*} H \| = 7 \\ Y \| = 12 \\ S \| = 10 \\ N \| = 3 \\ a \| = 7×10800 + 12×360 + 10×30 + 3 − 78207 \\ \| = 75600 + 4320 + 300 + 3 − 78207 = 2016 \end{align*}

## 15. Derivation of the General Algorithms

We can derive many calendar formulas by finding straight lines that, with rounding, yield the correct results.

### 15.1. Notation

We use special notation for some things.

• $$C(x)$$ has value 1 if test $$x$$ is satisfied, and 0 otherwise. For example, $$C(3 \gt 2) = 1, C(3 \lt 2) = 0$$.

• $$x∥y$$ asserts that $$x$$ is a multiple of $$y$$. For example, $$8 ∥ 4$$ because 8 is a multiple of 4.

• $$x⊥y$$ asserts that $$x$$ is not a multiple of $$y$$. For example, $$7 ⊥ 4$$ because 7 is not a multiple of 4.

• $$\dfloor{x}$$ is the floor function, which returns the nearest whole number not exceeding $$x$$ (i.e., in the direction of $$−∞$$). $$\dfloor{5.3} = 5, \dfloor{−2.8} = −3, \dfloor{7} = 7$$.

• $$\dmod{x}{p}$$:

$$\dmod{x}{p} ≡ x \bmod p ≡ x − p\dfloorratio{x}{p} \label{eq:mod} \qquad (p \gt 0)$$

is the modulus function that yields the non-negative difference between $$x$$ and the nearest multiple of positive $$p$$ not exceeding $$x$$. Always (if $$p \gt 0$$)

\begin{align} x \| = \dfloorratio{x}{p} + \dmod{x}{p} \\ x \| = \dfloor{x} + \dmod{x}{1} \\ \dmod{x}{p} \| = p\left\lfloor \frac{x}{p} \right\rceil_1 \label{eq:mod1top} \\ 0 \| \le \dmod{x}{p} \lt p \\ \dmod{x + np}{p} \| = (x + np) − p\dfloorratio{x + np}{p} \notag \\ \| = x + np − p\dfloor{\dfrac{x}{p} + n} \notag \\ \| = x + np − p\dparen{\dfloorratio{x}{p} + n} \| \quad (n∥1)\notag \\ \| = x − p\dfloorratio{x}{p} = \dmod{x}{p} \label{eq:modn} \end{align}

For example

$${x}$$ $${4\dfloorratio{x}{4}}$$ $${\dmod{x}{4}}$$
−2 −4 2
−1 −4 3
0 0 0
1 0 1
2 0 2
3 0 3
4 4 0
5 4 1

• $$\dceil{x}$$ is the ceiling function that yields the nearest whole number not less than $$x$$ (i.e., in the direction of $$+∞$$). For example, $$\dceil{5.3} = 6, \dceil{−2.8} = −2, \dceil{7} = 7$$.
• $$\ddom{x}{p}$$:

$$\ddom{x}{p} ≡ x \bdom p ≡ p\dceilratio{x}{p} − x \qquad (p \gt 0) \label{eq:dom}$$

is the domulus function that yields the non-negative difference between $$x$$ and the nearest multiple of positive $$p$$ not less than $$x$$. I made up the notation $$\bdom$$, which is $$\bmod$$ spelled backwards. And I invented the name "domulus", like "modulus" but with "dom" instead of "mod". Always (if $$p \gt 0$$)

\begin{align} x \| = p\dceilratio{x}{p} − \ddom{x}{p} \\ x \| = \dceil{x} − \ddom{x}{1} \\ \ddom{x}{p} \| = p\left\lceil \frac{x}{p} \right\rfloor_1 \label{eq:dom1top} \\ 0 \| \le \ddom{x}{p} \lt p \\ \ddom{x + np}{p} \| = p\dceilratio{x + np}{p} − (x + np) \notag \\ \| = p\dceil{\dfrac{x}{p} + n} − x − np \notag \\ \| = p\dparen{\dceil{\dfrac{x}{p}} + n} − x − np \| \quad (n∥1) \notag \\ \| = p\dceil{\dfrac{x}{p}} − x = \ddom{x}{p} \label{eq:domn} \end{align}

For example

$${x}$$ $${4\dceilratio{x}{4}}$$ $${\ddom{x}{4}}$$
−2 0 2
−1 0 1
0 0 0
1 4 3
2 4 2
3 4 1
4 4 0
5 8 3

• $$\{ m, n \} = \Div(x,y)$$ is a function that yields two values $$m, n$$ such that $$x = my + n$$ with $$m$$ a whole number, $$0 \le n \lt y \gt 0$$, and

\begin{align*} m \| = \dfloorratio{x}{y} \\ n \| = \dmod{x}{y} = x \bmod y \end{align*}

A few useful relationships (for $$p \gt 0$$):

1. $$\dceil{\dceil{x}} = \dfloor{\dceil{x}} = \dceil{x}$$
2. $$\dfloor{\dfloor{x}} = \dceil{\dfloor{x}} = \dfloor{x}$$
3. $$\dmod{\dmod{x}{p}}{p} = \ddom{\dmod{x}{p}}{p} = \dmod{x}{p} \label{eq:modmod}$$
4. $$\ddom{\ddom{x}{p}}{p} = \dmod{\ddom{x}{p}}{p} = \ddom{x}{p} \label{eq:domdom}$$
5. $$\dmod{x ± y}{p} = \dmod{\dmod{x}{p} ± \dmod{y}{p}}{p} \label{eq:dmod2}$$
6. $$\ddom{x ± y}{p} = \ddom{\ddom{x}{p} ± \ddom{y}{p}}{p} \label{eq:ddom2}$$
7. $$\dceil{x} − \dfloor{x} = C(x⊥1) \label{eq:ceilfloor}$$
8. $$\dmod{x}{p} + \ddom{x}{p} = pC(x⊥p)$$
9. $$\dfloor{−x} = −\dceil{x} = −\dfloor{x} − C(x⊥1) \label{eq:minusfloor}$$
10. $$\dceil{−x} = −\dfloor{x} = −\dceil{x} + C(x⊥1) \label{eq:minusceil}$$
11. $$\dmod{−x}{p} = \ddom{x}{p} = −\dmod{x}{p} + pC(x⊥p) \label{eq:minusmod}$$
12. $$\ddom{−x}{p} = \dmod{x}{p} = −\ddom{x}{p} + pC(x⊥p) \label{eq:minusdom}$$
13. $$\dfloor{x + y} = \dfloor{x} + \dfloor{y} + C\dparen{\dmod{x}{1} + \dmod{y}{1} ≥ 1} \label{eq:splitfloor}$$
14. $$\dfloor{x − y} = \dfloor{x} − \dfloor{y} − C\dparen{\dmod{x}{1} − \dmod{y}{1} \lt 0} \label{eq:floorm}$$
15. $$\dmod{x + y}{p} = \dmod{x}{p} + \dmod{y}{p} − pC\dparen{\dmod{x}{p} + \dmod{y}{p} ≥ p} \label{eq:modp}$$
16. $$\dmod{x − y}{p} = \dmod{x}{p} − \dmod{y}{p} + pC\dparen{\dmod{x}{p} − \dmod{y}{p} \lt 0}$$
17. $$\dceil{x + y} = \dceil{x} + \dceil{y} − C\dparen{\dmod{x}{1} + \dmod{y}{1} ≥ 1}$$
18. $$\dceil{x − y} = \dceil{x} − \dceil{y} + C\dparen{\dmod{x}{1} − \dmod{y}{1} \lt 0}$$
19. $$\ddom{x + y}{p} = \ddom{x}{p} + \ddom{y}{p} − pC\dparen{\ddom{x}{p} + \ddom{y}{p} ≥ p} \label{eq:domp}$$
20. $$\ddom{x − y}{p} = \ddom{x}{p} − \ddom{y}{p} + pC\dparen{\ddom{x}{p} − \ddom{y}{p} \lt 0} \label{eq:domm}$$
21. $$n\dmod{x}{1} − \dmod{nx}{1} = \dfloor{n\dmod{x}{1}} \qquad{(n ∥ 1)} \label{eq:dmoddiff1}$$

22. $$x − y − 1 \lt \dfloor{x} − \dfloor{y} \lt x − y + 1 \label{eq:floordiffrange}$$
23. $$\dceil{x − y} − 1 \le \dfloor{x} − \dfloor{y} \le \dfloor{x − y} + 1 \label{eq:floordiffrange2}$$
24. $$x − y − 1 \lt \dceil{x} − \dceil{y} \lt x − y + 1 \label{eq:ceildiffrange}$$
25. $$\dceil{x − y} − 1 \le \dceil{x} − \dceil{y} \le \dfloor{x − y} + 1 \label{eq:ceildiffrange2}$$
26. $$\dceilratio{x}{y} = \dfloorratio{x − 1}{y} + 1 \qquad (x, y ∥ 1) \label{eq:ceil2floor}$$
27. $$\ddom{x}{y} = y − 1 − \dmod{x − 1}{y} \qquad (x, y ∥ 1) \label{eq:ddom2dmod}$$
28. $$\dfloor{\dmod{x}{y}} = \dmod{\dfloor{x}}{y} \qquad (y ∥ 1) \label{eq:modfloor}$$

And their proofs:

1. $$\dceil{\dceil{x}} = \dfloor{\dceil{x}} = \dceil{x}$$ because $$\dceil{x}$$ is a whole number.
2. $$\dfloor{\dfloor{x}} = \dceil{\dfloor{x}} = \dfloor{x}$$ because $$\dfloor{x}$$ is a whole number.
3. $$\dmod{\dmod{x}{p}}{p} = \ddom{\dmod{x}{p}}{p} = \dmod{x}{p}$$ because $$0 \le \dmod{x}{p} \lt p$$.
4. $$\ddom{\ddom{x}{p}}{p} = \dmod{\ddom{x}{p}}{p} = \ddom{x}{p}$$ because $$0 \le \ddom{x}{p} \lt p$$.
5. $$\dmod{x ± y}{p} = \dmod{\dmod{x}{p} ± \dmod{y}{p}}{p}$$ because

\begin{align} \dmod{x ± y}{p} \| = p\dmod{\dfrac{x ± y}{p}}{1} \notag \eqavide{eq:mod1top} \\ \| = p\dmod{\dfrac{p\dfloorratio{x}{p} + \dmod{x}{p} ± \dparen{p\dfloorratio{y}{p} + \dmod{y}{p}}}{p}}{1} \eqavide{eq:mod} \notag \\ \| = p\dmod{\dfloorratio{x}{p} ± \dfloorratio{y}{p} + \dfrac{\dmod{x}{p} ± \dmod{y}{p}}{p}}{1} \notag \\ \| = p\dmod{\dfrac{\dmod{x}{p} ± \dmod{y}{p}}{p}}{1} \eqavide{eq:modn} \notag \\ \| = \dmod{\dmod{x}{p} ± \dmod{y}{p}}{p} \eqavide{eq:mod1top} \end{align}

6. $$\ddom{x ± y}{p} = \ddom{\ddom{x}{p} ± \ddom{y}{p}}{p}$$ because

\begin{align} \ddom{x ± y}{p} \| = p\ddom{\dfrac{x ± y}{p}}{1} \notag \eqavide{eq:dom1top} \\ \| = p\ddom{\dfrac{p\dceilratio{x}{p} − \ddom{x}{p} ± \dparen{p\dceilratio{y}{p} − \ddom{y}{p}}}{p}}{1} \eqavide{eq:dom} \notag \\ \| = p\ddom{\dceilratio{x}{p} ± \dceilratio{y}{p} − \dparen{\dfrac{\ddom{x}{p} ± \ddom{y}{p}}{p}}}{1} \notag \\ \| = p\ddom{−\dfrac{\ddom{x}{p} ± \ddom{y}{p}}{p}}{1} \eqavide{eq:domn} \label{eq:xpyp} \end{align}

so also

\begin{align} \ddom{\ddom{x}{p} ± \ddom{y}{p}}{p} \| = p\ddom{−\dfrac{\ddom{\ddom{x}{p}}{p} ± \ddom{\ddom{y}{p}}{p}}{p}}{1} \eqavide{eq:xpyp} \notag \\ \| = p\ddom{−\dfrac{\ddom{x}{p} ± \ddom{y}{p}}{p}}{1} \eqavide{eq:domdom} \notag \\ \| = \ddom{x ± y}{p} \eqavide{eq:xpyp} \end{align}

7. $$\dceil{x} − \dfloor{x} = C(x⊥1)$$ because when $$x$$ is a whole number (so $$x∥1$$) then $$\dceil{x}$$ and $$\dfloor{x}$$ are equal to $$x$$, and otherwise the next higher whole nuber ($$\dceil{x}$$) is one greater than the next lower whole number ($$\dfloor{x}$$).

8. $$\dmod{x}{p} + \ddom{x}{p} = pC(x⊥p)$$ because

\begin{align} \dmod{x}{p} + \ddom{x}{p} \| = x − p\dfloorratio{x}{p} + p\dceilratio{x}{p} − x \| \text{(vide \eqref{eq:mod}, \eqref{eq:dom})} \notag \\ \| = p \dparen{\dceilratio{x}{p} − \dfloorratio{x}{p}} \notag \\ \| = p C\dparen{\dfrac{x}{p} ⊥ 1} \notag \eqavide{eq:ceilfloor} \\ \| = p C\dparen{x ⊥ p} \end{align}

9. For $$\dfloor{−x} = −\dceil{x} = −\dfloor{x} − C(x⊥1)$$ the second $$=$$ follows from Equation \eqref{eq:ceilfloor}.

We prove the first $$=$$ as follows.

\begin{align} \dfloor{−x} \| = \dfloor{−\dfloor{x} − \dmod{x}{1}} \eqavide{eq:mod} \notag \\ \| = −\dfloor{x} + \dfloor{−\dmod{x}{1}} \\ \dceil{x} \| = \dceil{\dfloor{x} + \ddom{x}{1}} \eqavide{eq:dom} \notag \\ \| = \dfloor{x} + \dceil{\ddom{x}{1}} \\ \dfloor{−x} + \dceil{x} \| = \dfloor{−\dmod{x}{1}} + \dceil{\ddom{x}{1}} \end{align}

If $$x$$ is a whole number then $$\dmod{x}{1} = \ddom{x}{1} = 0$$ so $$\dfloor{−x} + \dceil{x} = 0$$.

And if $$x$$ is not a whole number then

$$0 \lt \dmod{x}{1} \lt 1 ⇒ \dceil{\dmod{x}{1}} = 1$$

and also

$$−1 \lt −\dmod{x}{1} \lt 0 ⇒ \dfloor{−\dmod{x}{1}} = −1$$

so then, too, $$\dfloor{−x} + \dceil{x} = \dceil{\dmod{x}{1}} + \dfloor{−\dmod{x}{1}} = 0$$ and so $$\dfloor{−x} = −\dceil{x}$$.

10. For $$\dceil{−x} = −\dfloor{x} = −\dceil{x} + C(x⊥1)$$, the second $$=$$ follows from Equation \eqref{eq:ceilfloor}.

The first $$=$$ follows from Equation \eqref{eq:minusfloor} if you replace every $$x$$ by $$−x$$.

11. For $$\dmod{−x}{p} = \ddom{x}{p} = −\dmod{x}{p} + pC(x⊥p)$$ the first $$=$$ follows from

\begin{align} \dmod{−x}{p} \| = −x − p\dfloorratio{−x}{p} \eqavide{eq:mod} \notag \\ \| = p\dceilratio{x}{p} − x \eqavide{eq:minusfloor} \notag \\ \| = \ddom{x}{p} \eqavide{eq:dom} \end{align}

and the second $$=$$ from

\begin{align} \dmod{x}{p} \| = x − p\dfloorratio{x}{p} \notag \eqavide{eq:mod} \\ \| = x − p\dparen{\dceilratio{x}{p} − C\dparen{\dfrac{x}{p} ⊥ 1}} \notag \eqavide{eq:ceilfloor} \\ \| = x − p\dceilratio{x}{p} + pC\dparen{x ⊥ p} \notag \\ \| = −\ddom{x}{p} + pC\dparen{x ⊥ p} \eqavide{eq:dom} \end{align}

12. $$\ddom{−x}{p} = \dmod{x}{p} = −\ddom{x}{p} + pC(x⊥p)$$ follows from the previous one if you replace every $$x$$ with $$−x$$.

13. $$\dfloor{x + y} = \dfloor{x} + \dfloor{y} + C\dparen{\dmod{x}{1} + \dmod{y}{1} ≥ 1}$$ because

\begin{align} \dfloor{x ± y} \| = x ± y − \dmod{x ± y}{1} \eqavide{eq:mod} \notag \\ \| = \dfloor{x} + \dmod{x}{1} ± \dparen{\dfloor{y} + \dmod{y}{1}} − \dmod{x ± y}{1} \eqavide{eq:mod} \notag \\ \| = \dfloor{x} ± \dfloor{y} + \dmod{x}{1} ± \dmod{y}{1} − \dmod{x ± y}{1} \notag \\ \| = \dfloor{x} ± \dfloor{y} + \dmod{x}{1} ± \dmod{y}{1} − \dmod{\dmod{x}{1} ± \dmod{y}{1}}{1} \eqavide{eq:dmod2} \label{eq:floorpm} \end{align}

We have

\begin{align} \dmod{\dmod{x}{1} + \dmod{y}{1}}{1} \| = \dmod{x}{1} + \dmod{y}{1} − C\dparen{\dmod{x}{1} + \dmod{y}{1} \ge 1} \\ \dmod{\dmod{x}{1} − \dmod{y}{1}}{1} \| = \dmod{x}{1} − \dmod{y}{1} + C\dparen{\dmod{x}{1} − \dmod{y}{1} \lt 0} \label{eq:mod1m} \end{align}

because $$0 \le \dmod{•}{1} \lt 1$$. So

$$\dfloor{x + y} = \dfloor{x} + \dfloor{y} + C\dparen{\dmod{x}{1} + \dmod{y}{1} \ge 1}$$

14. $$\dfloor{x − y} = \dfloor{x} − \dfloor{y} + C\dparen{\dmod{x}{1} − \dmod{y}{1} \lt 0}$$ follows from Eqs. \eqref{eq:floorpm} and \eqref{eq:mod1m}.
15. $$\dmod{x + y}{p} = \dmod{x}{p} + \dmod{y}{p} − pC\dparen{\dmod{x}{p} + \dmod{y}{p} ≥ p}$$ follows from

\begin{align} \dmod{x ± y}{p} \| = x ± y − p\dfloorratio{x ± y}{p} \eqavide{eq:mod} \notag \\ \| = p\dfloorratio{x}{p} + \dmod{x}{p} ± \dparen{p\dfloorratio{y}{p} + \dmod{y}{p}} \notag \\ \| − p\dfloorratio{p\dfloorratio{x}{p} + \dmod{x}{p} ± \dparen{p\dfloorratio{y}{p} + \dmod{y}{p}}}{p} \notag \eqavide{eq:mod} \\ \| = p\dfloorratio{x}{p} + \dmod{x}{p} ± p\dfloorratio{y}{p} ± \dmod{y}{p} \notag \\ \| − p\dfloorratio{x}{p} ∓ p\dfloorratio{y}{p} − p\dfloorratio{\dmod{x}{p} ± \dmod{y}{p}}{p} \notag \\ \| = \dmod{x}{p} ± \dmod{y}{p} − p\dfloorratio{\dmod{x}{p} ± \dmod{y}{p}}{p} \label{eq:i15a} \end{align}

We have

\begin{align} \dfloorratio{\dmod{x}{p} + \dmod{y}{p}}{p} \| = C\dparen{\dmod{x}{p} + \dmod{y}{p} \ge p} \label{eq:i15c} \\ \dfloorratio{\dmod{x}{p} − \dmod{y}{p}}{p} \| = −C\dparen{\dmod{x}{p} − \dmod{y}{p} \lt 0} \label{eq:i15b} \end{align}

because $$0 \le \dmod{•}{p} \lt p$$, so

$$\dmod{x}{p} + \dmod{y}{p} − p\dfloorratio{\dmod{x}{p} + \dmod{y}{p}}{p} = \dmod{x}{p} + \dmod{y}{p} − pC\dparen{\dmod{x}{p} + \dmod{y}{p} \ge p}$$

which completes the proof.

16. $$\dmod{x − y}{p} = \dmod{x}{p} − \dmod{y}{p} + pC\dparen{\dmod{x}{p} − \dmod{y}{p} \lt 0}$$ follows from Eqs. \eqref{eq:i15a} and \eqref{eq:i15b}.
17. $$\dceil{x + y} = \dceil{x} + \dceil{y} − C\dparen{\dmod{x}{1} + \dmod{y}{1} ≥ 1}$$ because

\begin{align} \dceil{x ± y} \| = x ± y + \ddom{x ± y}{p} \notag \eqavide{eq:dom} \\ \| = \dceil{x} − \ddom{x}{1} ± \dparen{\dceil{y} − \ddom{y}{1}} + \ddom{x ± y}{p} \notag \eqavide{eq:dom} \\ \| = \dceil{x} ± \dceil{y} − \ddom{x}{1} ∓ \ddom{y}{1} + \ddom{x ± y}{p} \label{eq:i17} \end{align}

\begin{align} \dceil{x + y} \| = \dceil{x} + \dceil{y} − \ddom{x}{1} − \ddom{y}{1} + \ddom{x + y}{p} \notag \\ \| = \dceil{x} + \dceil{y} − \ddom{x}{1} − \ddom{y}{1} + \ddom{x}{1} + \ddom{y}{1} \notag \\ \| − C\dparen{\ddom{x}{1} + \ddom{y}{1} ≥ 1} \eqavide{eq:domp} \notag \\ \| = \dceil{x} + \dceil{y} − C\dparen{\ddom{x}{1} + \ddom{y}{1} ≥ 1} \end{align}

18. $$\dceil{x − y} = \dceil{x} − \dceil{y} + C\dparen{\dmod{x}{1} − \dmod{y}{1} \lt 0}$$ because

\begin{align} \dceil{x − y} \| = \dceil{x} − \dceil{y} − \ddom{x}{1} + \ddom{y}{1} + \ddom{x − y}{p} \notag \eqavide{eq:i17} \\ \| = \dceil{x} − \dceil{y} − \ddom{x}{1} + \ddom{y}{1} + \ddom{x}{1} − \ddom{y}{1} \notag \\ \| + C\dparen{\ddom{x}{1} − \ddom{y}{1} \lt 0} \eqavide{eq:modp} \notag \\ \| = \dceil{x} − \dceil{y} + C\dparen{\ddom{x}{1} − \ddom{y}{1} \lt 0} \end{align}

19. $$\ddom{x + y}{p} = \ddom{x}{p} + \ddom{y}{p} − pC\dparen{\ddom{x}{p} + \ddom{y}{p} ≥ p}$$ because

\begin{align} \ddom{x ± y}{p} = \| p\dceilratio{x ± y}{p} − \dparen{x ± y} \notag \eqavide{eq:dom} \\ = \| p\dceilratio{p\dceilratio{x}{p} − \ddom{x}{p} ± \dparen{p\dceilratio{y}{p} − \ddom{y}{p}}}{p} \notag \\ \| − \dparen{p\dceilratio{x}{p} − \ddom{x}{p} ± \dparen{p\dceilratio{y}{p} − \ddom{y}{p}}} \notag \eqavide{eq:dom} \\ = \| p\dceilratio{x}{p} ± p\dceilratio{y}{p} + p\dceilratio{−\ddom{x}{p} ∓ \ddom{y}{p}}{p} \notag \\ \| − \dparen{p\dceilratio{x}{p} ± p\dceilratio{y}{p} − \dparen{\ddom{x}{p} ± \ddom{y}{p}}} \notag \\ = \| \ddom{x}{p} ± \ddom{y}{p} + p\dceilratio{−\ddom{x}{p} ∓ \ddom{y}{p}}{p} \label{eq:i19a} \end{align}

We have

\begin{align} \dceilratio{−\ddom{x}{p} − \ddom{y}{p}}{p} \| = −C\dparen{\ddom{x}{p} + \ddom{y}{p} \ge p} \\ \dceilratio{−\ddom{x}{p} + \ddom{y}{p}}{p} \| = C\dparen{\ddom{x}{p} − \ddom{y}{p} \lt 0} \label{eq:i19b} \end{align}

because $$0 \le \ddom{•}{p} \lt 1$$, so

$$\ddom{x}{p} + \ddom{y}{p} + p\dceilratio{\ddom{x}{p} + \ddom{y}{p}}{p} = \ddom{x}{p} + \ddom{y}{p} − pC\dparen{\ddom{x}{p} + \ddom{y}{p} \ge p}$$

which completes the proof.

20. $$\ddom{x − y}{p} = \ddom{x}{p} − \ddom{y}{p} + pC\dparen{\ddom{x}{p} − \ddom{y}{p} \lt 0}$$ follows from Eqs. \eqref{eq:i19a} and \eqref{eq:i19b}.

21. \begin{eqnarray} n\dmod{x}{1} − \dmod{nx}{1} \| = \| n\dmod{x}{1} − \dmod{n\dfloor{x} + n\dmod{x}{1}}{1} \notag \\ \| = \| n\dmod{x}{1} − \dmod{n\dmod{x}{1}}{1} \qquad{(n ∥ 1)} \eqavide{eq:modp} \notag \\ \| = \| \dfloor{n\dmod{x}{1}} \eqavide{eq:mod} \end{eqnarray}
22. \begin{align} \dfloor{x} − \dfloor{y} \| = \dparen{x − \dmod{x}{1}} − \dparen{y − \dmod{y}{1}} \notag \\ \| = x − y + \dmod{y}{1} − \dmod{x}{1} \end{align}

Then

$$x − y − 1 \lt \dfloor{x} − \dfloor{y} \lt x − y + 1$$

because

$$0 \le \dmod{•}{1} \lt 1$$

23. $$\dceil{x − y} − 1 \le \dfloor{x} − \dfloor{y} \le \dfloor{x − y} + 1$$

because

\begin{align} x − y − 1 \lt \dfloor{x} − \dfloor{y} \lt x − y + 1 \eqavide{eq:floordiffrange} \\ x − y \le \dceil{x − y} \| \quad (\dfloor{x} − \dfloor{y} ∥ 1) \end{align}

24. \begin{align} \dceil{x} − \dceil{y} \| = \dparen{x + \ddom{x}{1}} − \dparen{y + \ddom{y}{1}} \notag \\ \| = x − y + \ddom{x}{1} − \ddom{y}{1} \end{align}

Then

$$x − y − 1 \lt \dceil{x} − \dceil{y} \lt x − y + 1$$

because

$$0 \le \ddom{•}{1} \lt 1$$

25. $$\dceil{x − y} − 1 \le \dceil{x} − \dceil{y} \le \dfloor{x − y} + 1$$

because

\begin{align} x − y − 1 \lt \dceil{x} − \dceil{y} \lt x − y + 1 \eqavide{eq:ceildiffrange} \\ x − y \le \dceil{x − y} \| \quad (\dfloor{x} − \dfloor{y} ∥ 1) \end{align}

26. If $$y = 1$$:

\begin{align} \dceilratio{x}{y} \| = \dceilratio{x}{1} = x \| \qquad (x ∥ 1) \\ \| = (x − 1) + 1 = \dfloorratio{x − 1}{1} + 1 = \dfloorratio{x − 1}{y} + 1 \end{align}

If $$y \gt 1$$:

\begin{align} \dceilratio{x}{y} \| = \dfloorratio{x}{y} + C(x⊥y) \eqavide{eq:ceilfloor} \notag \\ \| = \dfloorratio{x}{y} + C\dparen{\dmod{x}{y} \ge 1} \| \qquad (x, y ∥ 1) \notag \\ \| = \dfloorratio{x}{y} + C\dparen{\dmod{\dfrac{x}{y}}{1} \ge \dfrac{1}{y}} \notag \\ \| = \dfloorratio{x}{y} + C\dparen{\dmod{\dfrac{x}{y}}{1} \ge \dmod{\dfrac{1}{y}}{1}} \| (y \gt 1) \notag \\ \| = \dfloorratio{x}{y} − \dfloorratio{1}{y} + C\dparen{\dmod{\dfrac{x}{y}}{1} − \dmod{\dfrac{1}{y}}{1} \ge 0} \| (y \gt 1) \notag \\ \| = \dfloorratio{x}{y} − \dfloorratio{1}{y} + 1 − C\dparen{\dmod{\dfrac{x}{y}}{1} − \dmod{\dfrac{1}{y}}{1} \lt 0} \notag \\ \| = \dfloorratio{x − 1}{y} + 1 \eqavide{eq:floorm} \end{align}

27. If $$y = 1$$:

$$\ddom{x}{y} = \ddom{x}{1} = 0 = y − 1 − \ddom{x − 1}{y} \qquad (x ∥ 1)$$

If $$y \gt 1$$:

\begin{align} \ddom{x}{y} \| = y\ddom{\dfrac{x}{y}}{1} \notag \\ \| = y\dparen{\dceil{\dfrac{x}{y}} − \dfrac{x}{y}} \eqavide{eq:dom} \notag \\ \| = y\dparen{\dfloorratio{x − 1}{y} + 1 − \dfrac{x}{y}} \eqavide{eq:ceil2floor} \notag \\ \| = y\dparen{\dfrac{x − 1}{y} − \dmod{\dfrac{x − 1}{y}}{1} + 1 − \dfrac{x}{y}} \eqavide{eq:mod} \notag \\ \| = x − 1 − y\dmod{\dfrac{x − 1}{y}}{1} + y − x \notag \\ \| = y − 1 − \dmod{x − 1}{y} \end{align}

28. Let

\begin{align} \{ k, α \} \| = \Div(x, y) \\ \{ m, β \} \| = \Div(α, 1) \end{align}

so

$$x = ky + α = ky + m + β$$

where

\begin{align} k, m, y \| ∥ 1 \\ 0 \| ≤ m ≤ y − 1 \\ 0 \| ≤ β \lt 1 \end{align}

then

\begin{align} \dfloor{\dmod{x}{y}} \| = \dfloor{\dmod{ky + m + β}{y}} \notag \\ \| = \dfloor{\dmod{m + β}{y}} \notag \\ \| = \dfloor{m + β} \| (0 ≤ m + β \lt y) \notag \\ \| = m \end{align}

and also

\begin{align} \dmod{\dfloor{x}}{y} \| = \dmod{\dfloor{ky + m + β}}{y} \notag \\ \| = \dmod{ky + m}{y} = m \end{align}

so

$$\dfloor{\dmod{x}{y}} = \dmod{\dfloor{x}}{y}$$

### 15.2. Large Intermediate Results

#### 15.2.1. Introduction

Many of the calendar calculations that are described below are of the type

\begin{align} y \| = \dfloorratio{f x + t}{g} \label{eq:template} \\ e \| = \dmod{f x + t}{g} \label{eq:template-e} \end{align}

i.e.,

$\{y, e\} = \Div(f x + t, g)$

with

$$f x + t = g y + e$$

where $$f$$, $$t$$, $$g$$ are fixed whole numbers with $$f ≥ 1$$, $$g \gt 1$$, $$0 ≤ e \lt g$$, and $$x$$, $$y$$ are variable but whole numbers. The intermediate result $$fx + t$$ is then usually much greater in magnitude than $$x$$ and than the end result.

This can lead to problems for computer programs that calculate with memory locations in which whole numbers can have a large but limited number of unique values. We here refer to that number of unique values as $$W$$ ("large W").

Another option is to calculate using so-called floating point numbers, numbers with a separate mantissa and exponent, like 1.234 × 1020, that can hold much smaller and larger values than a whole number that would fit in the same memory location, but floating point numbers have limited precision, and then you need to worry about round-off errors. Round-off errors are very bad for calendrical calculations, because then you can easily get a day, month, or year that is one too small or large, which you might not notice.

For that reason we only use whole numbers for our calculations. Then you cannot get round-off errors, but you can get overflow problems when an (intermediate) result is so large that it doesn't fit in the collection of $$W$$ unique values.

In almost all modern computer systems, $$W$$ is a power of 256, which is itself a power of 2. If $$W = 2^n$$ then $$n$$ is called the number of bits. A 32-bit number can hold $$2^{32} = 4294967296$$ unique values. Those unique values then usually run from $$−W/2 = −2^{31} = −2147483648$$ through $$W/2 − 1 = +2^{31} − 1 = +2147483647$$. We here call the greatest absolute value that both positive and negative whole numbers can have $$w$$ ("little w"). So $$+w$$ and $$−w$$ both fit, but $$+(w + 1)$$ and $$−(w + 1)$$ don't both fit. For the most often used type of 32-bit numbers, $$w = W/2 − 1 = 2147483647$$. Below we assume such 32-bit numbers.

Then the intermediate result $$f x + t$$ must remain smaller in magnitude than $$w$$, so to avoid problems we must have roughly $$\dabs{x} ≤ w/f$$, which is much smaller than $$w$$ is.

The methods described below extend the usable range of days to (nearly) $$W$$ instead of $$W/f$$ and are mathematically equivalent to Equation \eqref{eq:template} but take more calculation steps, hence more calculation time.

Nowadays 64-bit numbers are also widely available. For them $$w$$ and $$W$$ are so much greater than for 32-bit numbers that calendrical calculations in practice aren't troubled by overflow problems anymore. For example, we'll encounter an application of Equation \eqref{eq:template} for which, when using 32-bit numbers, overflow problems can be avoided for a period of only about 450 years. That is a very tough case. With 64-bit numbers that limit increases by a factor of over 4 thousand million, to about 1933 thousand million years. That is about 140 times longer than the age of the Universe.

64-bit numbers take twice as much memory as 32-bit numbers do, but when you've calculated the result using 64-bit numbers then you can store that result in a 32-bit memory location. Then you can handle a period of nearly 12 million years (corresponding to $$W$$ days).

I wrote a test program (in C++, with optimizations) that uses Equation \eqref{eq:template} for 64-bit numbers, and also the most appropriate detour that works for 32-bit numbers but takes more calculation steps. The program calculates for all running month numbers from 0 to 70 million what the running day number is of the 10th day in that month, and then for each of those running day numbers which month number and day number within the month correspond to it. The calculations with 32-bit numbers and the detour took about 2.1 times as much calculation time as the 64-bit numbers without the detour. That doesn't mean that calendrical calculations with 64-bit numbers are faster in every computing environment, but it does suggest that it may be worthwhile to investigate the use of 64-bit numbers, if you have them available.

On nearly all modern computer systems, overflow of whole numbers works in such a way that a value that would be just a bit greater than the greatest value that can fit gets stored as a value that is just a bit greater than the least (most negative) value that can fit, as if the collection of acceptable values keeps repeating itself. That has the advantage that the "wrong" overflowed value is very different from the correct value that didn't fit, so that the problem is much easier to notice than it would be for a round-off problem.

For example, if you keep incrementing a value by 1 and eventually reach the greatest positive 32-bit value 2147483647 then the next value that you get is the least (most negative) 32-bit value −2147483648 and then the value increments from there, as if the collection of acceptable values keeps repeating itself.

For the Gregorian Calendar we'll encounter a formula later that is roughly as follows:

$m = \dfloorratio{4800 s}{146097}$

where $$s$$ is a running day number and $$m$$ is a running month number. The intermediate result $$4800 s$$ must not exceed $$w$$, so we must have $$\dabs{s} ≤ w/4800$$, so the distance between the greatest and least $$s$$ is at most about $$W/4800 ≈ 894784$$ days, which corresponds to roughly 2449 years ― far too few to be practicable.

And in the other direction the calculation is something like

$s = \dfloorratio{146097 m}{4800}$

The intermediate result $$146097 m$$ must fit in the $$W$$ unique values, so $$m$$ must not exceed $$W/146097 ≈ 29398$$ months which correspond to about 2449 years, just like above. That is rather small for a calendar.

A third example (from the Jewish Calendar) is

$s = \dfloorratio{765433 m}{25920}$

Here the intermediate result $$765433 m$$ must fit in the $$W$$ unique values, so $$m$$ must not exceed $$W/765433 ≈ 5611$$ months, which are about 450 years. That is far too few to be useful.

What are the least and greatest values of $$x$$ for which you can calculate $$y$$ with the abovementioned formula, if the initial, final, and all intermediate values must lie between $$−w$$ and $$+w$$? We use $$𝔏$$ for the least allowed value of $$x$$, and $$𝔘$$ for the greatest allowed value of $$x$$.

Then we need

\begin{align*} −w \| ≤ x ≤ w \\ −w \| ≤ f x + t ≤ w \\ −w \| ≤ y ≤ w \end{align*}

$$\dceilratio{−w − t}{f} ≤ x ≤ \dfloorratio{w − t}{f}$$

The third conditions yields

\begin{align} −w \| ≤ \dfloorratio{f x + t}{g} ≤ w \notag \\ −w \| ≤ \dfrac{f x + t}{g} \lt w + 1 \notag \\ \dfrac{−g w − t}{f} \| ≤ x \lt \dfrac{g w + g − t}{f} \end{align}

\begin{align} 𝔘 \| = \min\left(w, \dfloorratio{w − t}{f}, \dfrac{g w + g − t}{f}\right) \\ 𝔏 \| = \max\left(−w, \dceilratio{−w − t}{f}, \dfrac{−g w − t}{f}\right) \end{align}

These formulas cannot be rearranged into simpler ones, so aren't very convenient for use. For that reason we estimate the range of $$x$$ while assuming that $$t = 0$$ (because in practice $$t$$ is much smaller than $$w$$) and we pretend that $$x$$ does not have to be a whole number. Then we find

\begin{align} 𝔘 \| ≈ \min\left(w, \dfrac{w}{f}, \dfrac{g w}{f}\right) = \dfrac{w}{f} \qquad ( g, f ≥ 1 ) \\ 𝔏 \| ≈ \max\left(−w, \dfrac{−w}{f}, \dfrac{−g w}{f}\right) = −𝔘 \end{align}

Here follows a summary of ways to make the range of $$x$$ larger. The derivation of the formulas follows after that.

#### 15.2.2. Summary

We want to calculate

\begin{align} y \| = \dfloorratio{f x + t}{g} \\ e \| = \dmod{f x + t}{g} \\ \{ y, e \} \| = \Div(f x + t, g) \end{align}

with only whole numbers, and with $$f$$ and $$g$$ greater than 0 in an environment in which all whole numbers must lie betwen $$−w$$ and $$+w$$. Then we must have roughly $$\dabs{f x} ≤ w$$, so $$\dabs{x} ≤ w/f$$, which is much smaller in magnitude than $$w$$ if $$f \gt 1$$.

$$y$$ must fit, too, so we must also have that $$\dabs{y} ≤ w$$ which means roughly $$(f/g) \dabs{x} ≤ w$$ so $$\dabs{x} ≤ gw/f$$. That limit is never lower than the $$w/f$$ that we found earlier, so the combined limit on $$x$$ is $$w/f$$.

You can rewrite the formulas as follows to make them work also for a larger range of $$x$$.

1. If $$f \gt g$$:

\begin{align} \{ f_1, f_0 \} \| = \Div(f, g) \\ \{ t_1, t_0 \} \| = \Div(t, g) \\ \{ \omega, e \} \| = \Div(f_0 x + t_0, g) \\ y \| = f_1 x + t_1 + ω \end{align}

This is usable if roughly $$\dabs{x} ≤ w \min(1/\dmod{f}{g}, g/f)$$. If $$g \dmod{f}{g} \lt f$$ then the limit on $$x$$ is roughly $$\dabs{x} ≤ w g/f$$, which is the highest achievable for any method. If $$g \dmod{f}{g} \gt f$$ then we need roughly $$\dabs{x} ≤ w/\dmod{f}{g} \gt w/f$$.

2. If $$g\dmod{f}{g} ≤ w$$:

\begin{align} \{ f_1, f_0 \} \| = \Div(f, g) \\ \{ t_1, t_0 \} \| = \Div(t, g) \\ \{ x_1, x_0 \} \| = \Div(x, g) \\ \{ ω, e \} \| = \Div(f_0 x_0 + t_0, g) \\ y \| = f_1 x + f_0 x_1 + ω + t_1 \end{align}

Then we need roughly $$\dabs{x} ≤ w \min(g/f, 1)$$, which is the highest achievable with any method.

3. If $$g\dmod{f}{g} \gt w$$:

If you have suitable $$\{ P, Q, R \}$$ (see below for how to find them) then

\begin{align} \{ f_1, f_0 \} \| = \Div(f, g) \\ \{ t_1, t_0 \} \| = \Div(t, g) \\ \{ x_1, x_0 \} \| = \Div(x, P) \\ \{ ω, e \} \| = \Div(x_1 R + f_0 x_0 + t_0, g) \\ y \| = f_1 x + x_1 Q + t_1 + ω \end{align}

That works if roughly $$\dabs{x} ≤ w \min(g/f, 1)$$, and no method can do better than that.

We seek suitable $$\{ P, Q, R \}$$ for our calendar formula. We need to do that only once for each such calendar formula (and $$w$$). Warning: It may be that for some $$f$$, $$g$$, and $$w$$ no suitable $$\{ P, Q, R \}$$ can be found.

Use the Extended Algorithm of Euclid to find a solution for $$x$$, $$y$$, $$R_1$$ in

$$f_0 x + g y = R_1 = \gcd(f_0, g )$$

Then

\begin{align} P_1 \| = \dmod{x}{(g/R_1)} \\ Q_1 \| = \dmod{−y}{(f_0/R_1)} \\ P_\text{max} \| = \dfloorratio{w}{f_0} \\ n_* \| = \dceilratio{W}{f_0 P_1} \\ m_P \| = n_* \dfrac{g}{R_1} \\ m_Q \| = n_* \dfrac{f_0}{R_1} \end{align}

There are $$m_P − 1$$ combinations of $$\{ P, Q, R \}$$ that could be suitable:

\begin{align} P \| = \dmod{n P_1}{m_P} \\ \{ ρ, R \} \| = \Div(n R_1, g) \\ Q \| = \dmod{n Q_1 + ρ}{m_Q} \end{align}

for $$n$$ from 1 through $$m_P − 1$$. Such a combination $$\{ P, Q, R \}$$ is suitable if $$0 \lt R ≤ P ≤ P_\text{max}$$.

If you do not need to find all suitable combinations but are already satisfied with one of them, then you can shorten the search by proceeding as follows. Stop when you've found a suitable combination.

1. Search for $$j$$ from 1 through $$(g/R_1) − 1$$.

2. For every $$j$$, search for $$k$$ from 0 through $$n_* − 1$$.

3. Calculate

\begin{align} P \| = \dmod{j P_1 + k \dmod{P_1}{n_*} \dfrac{g}{R_1}}{m_P} \\ \{ ρ, R \} \| = \Div(j R_1, g) \\ Q \| = \dmod{n Q_1 + ρ + k}{m_Q} \end{align}

(These equations correspond to the earlier ones based on $$n$$ if you take $$n = j + k (g/R_1)$$.)

4. If $$0 \lt R ≤ P ≤ P_\text{max}$$ then you've found a suitable combination of $$\{ P, Q, R \}$$.

Example 1: $$f = 4800$$, $$g = 146097$$. Method 2 applies here, because $$g\dmod{f}{g} = 146097×\dmod{4800}{146097} = 146097×4800 = 701265600 ≈ 0.33 w ≤ w$$.

Let $$x = w = 2147483647$$. Then the sought result is

\begin{align*} y \| = \dfloorratio{f x + t}{g} = \dfloorratio{4800×2147483647}{146097} \\ \| = \dfloorratio{10307921505600}{146097} = 70555326 \end{align*}

so the input and end result are small enough for a 32-bit number, but the greatest intermediate result is 10'307'921'505'600, which is much greater than $$w$$, so this calculation cannot be done directly like this with 32-bit numbers. Instead we do

\begin{align*} \{ f_1, f_0 \} \| = \Div(f, g) = \Div(4800, 146097) = \{ 0, 4800 \} \\ \{ x_1, x_0 \} \| = \Div(x, g) = \Div(2147483647, 146097) = \{ 14699, 3844 \} \\ \{ ω, e \} \| = \Div(f_0 x_0 + t_0, g) = \Div(4800×3844, 146097) \\ \| = \Div(18451200, 146097) = \{ 126, 42978 \} \\ y \| = f_1 x + f_0 x_1 + ω + t_1 = 0 + 4800×14699 + 126 + 0 = 70555326 \end{align*}

so with the same end result, but now the greatest intermediate result 70'555'326 is small enough for a 32-bit number.

The limit on $$x$$ is then about $$\dabs{x} ≤ w \min(1/f_1, g/f_0, 1) = w$$, because here $$f_1 = 0$$ and $$g \gt f_0 = f$$.

Example 2: $$f = 146097$$, $$g = 4800$$. Methods 1 and 2 apply here, because $$f ≥ g$$ and $$g\dmod{f}{g} = 4800×\dmod{146097}{4800} = 4800×2097 = 10065600 ≈ 0.0047 w ≤ w$$.

If you're satisfied with a limit on $$x$$ of size

\begin{align*} \| w \min\left( \dfrac{1}{\dmod{f}{g}}, \dfrac{g}{f} \right) \\ \| = w \min\left( \dfrac{1}{\dmod{146097}{4800}}, \dfrac{4800}{146097} \right) \\ \| ≈ w \min\left( \dfrac{1}{2097}, 0.0329 \right) \\ \| ≈ w \min\left( 0.00047687, 0.032855 \right) \\ \| ≈ 0.00047687 w ≈ 1024074 \end{align*}

then you can use method 1.

Let $$x = 1024074$$. Then the sought result is

\begin{align*} y \| = \dfloorratio{fx + t}{g} = \dfloorratio{146097×1024074 + 0}{4800} \\ \| = \dfloorratio{149614139178}{4800} = 31169612 \end{align*}

That input and end result are small enough for a 32-bit number, but the greatest intermediate result 149'614'139'178 is much greater than $$w$$, so this calculation cannot be done directly like this with 32-bit numbers. Instead we do

\begin{align*} \{ f_1, f_0 \} \| = \Div(f, g) = \Div(146097, 4800) = \{ 30, 2097 \} \\ \{ t_1, t_0 \} \| = \Div(t, g) = \Div(0, 4800) = \{ 0, 0 \} \\ y \| = f_1 x + t_1 + \dfloorratio{f_0 x + t_0}{g} = 30×1024074 + 0 + \dfloorratio{2097×1024074 + 0}{4800} \\ \| = 30722220 + \dfloorratio{2147483178}{4800} = 30722220 + 447392 = 31169612 \end{align*}

so with the same end result, but now the greatest intermediate result 2'147'483'178 is just small enough for a 32-bit number.

If you want a greater limit on $$x$$ then you can use method 2.

Example 3: $$f = 25920$$, $$g = 765433$$. Only method 3 is suitable for this, because $$g\dmod{f}{g} = 765433 \dmod{25920}{765433} = 765433×25920 = 19840023360 ≈ 9.2 w$$ which is greater than $$w$$.

\begin{align*} \{ f_1, f_0 \} \| = \Div(f, g) = \Div(25920, 765433) = \{ 0, 25920 \} \\ \{ t_1, t_0 \} \| = \Div(t, g) = \Div(0, 765433) = \{ 0, 0 \} \end{align*}

We seek suitable $$\{ P, Q, R \}$$. First we apply the Extended Algorithm of Euclid to find a solution for $$x$$, $$y$$, and $$R$$ in $$f_0 x + g y = R_1 = \gcd(f_0, g )$$, which means $$25920 x + 765433 y = R_1$$. We find $$25920×99902 − 765433×3383 = 1$$. Then

\begin{align*} P_1 \| = \dmod{x}{(g/R_1)} = \dmod{99902}{765433} = 99902 \\ Q_1 \| = \dmod{−y}{(f_0/R_1)} = \dmod{3383}{25920} = 3383 \\ P_\text{max} \| = \dfloorratio{w}{f_0} = \dfloorratio{2147483647}{25920} = 82850 \\ n_* \| = \dceilratio{w}{f_0 P_1} = \dfloorratio{2147483647}{25920×99902} = 1 \\ m_P \| = n_* \dfrac{g}{R_1} = 765433 \\ m_Q \| = n_* \dfrac{f_0}{R_1} = 25920 \end{align*}

We don't need to know all suitable combinations of $$\{ P, Q, R \}$$, so are satisfied with the first suitable one. We start seaching at $$j = 1$$. Because $$n_* = 1$$, also $$k = 0$$ and $$n = j$$. Then

\begin{align*} P \| = \dmod{j P_1}{m_P} = \dmod{99902 j}{765433} \\ \{ ρ, R \} \| = \Div(j R_1, g) = \Div(j, 25920) \\ Q \| = \dmod{j Q_1 + ρ}{m_Q} = \dmod{3383 j + ρ}{25920} \end{align*}

$${j}$$ $${P}$$ $${Q}$$ $${R}$$ $${P/R}$$ $${P/P_\text{max}}$$
1 99902 3383 1 99902 1.21
2 199804 6766 2 99902 2.41
3 299706 10149 3 99902 3.62
4 399608 13532 4 99902 4.82
5 499510 16915 5 99902 6.03
6 599412 20298 6 99902 7.23
7 699314 23681 7 99902 8.44
8 33783 1144 8 4222.9 0.41
 ✓ 

so the smallest $$j$$ for which $$0 \lt R ≤ P ≤ P_\text{max}$$ is $$j = 8$$. And then $$P = 33783$$, $$Q = 1141$$, $$R = 8$$.

Let $$x = w = 2147483647$$. Then the sought result is

\begin{align*} y \| = \dfloorratio{f x + t}{g} = \dfloorratio{25920×2147483647 + 0}{765433} \\ \| = \dfloorratio{55662776130240}{765433} = 72720638 \end{align*}

That input and result are small enough for a 32-bit number but the greatest intermediate result 55'662'776'130'240 is far too great for that. Instead we do

\begin{align*} \{ x_1, x_0 \} \| = \Div(x, P) = \Div(2147483647, 33783) = \{ 63566, 33469 \} \\ \{ ω, e \} \| = \Div(x_1 R + f_0 x_0 + t_0, g) = \Div(63566×8 + 25920×33469 + 0, 765433) \\ \| = \Div(868025008, 765433) = \{ 1134, 23986 \} \\ \| y = f_1 x + x_1 Q + t_1 + ω = 0 + 63566×1144 + 0 + 1134 = 72720638 \end{align*}

so with the same end result, but now the greatest intermediate result 868'025'008 is small enough for a 32-bit number.

#### 15.2.3. True Limits

For estimating the limit on $$x$$ we've so far assumed that $$t = 0$$ and that the intermediate results don't have to be whole numbers, which resulted in the lower limit $$𝔏$$ being just as large (but with a minus sign) as the upper limit $$𝔘$$, but in practice those assumptions (nearly) never hold, so the estimated limits on $$x$$ will be roughly but not exactly correct. And most calendars require multiple calculations with equations such as Eq. \eqref{eq:template}, each with its own values for $$f, g, t$$, that combine in a complicated way into the final limits on the input values. How do we find the true limits?

The calculations for every calendar usually go from a date (often year $$a$$, month $$m$$, day $$d$$) to a running day number $$J$$, or the other way around. We can indicate those calculations schematically like

\begin{eqnarray} \| J = D(\{ a, m, d \}) \\ \| \{ a, m, d \} = U(J) \end{eqnarray}

If you first do a calculation in the one direction and then immediately go in the opposite direction again then you ought to get your initial value back again. You want that

\begin{eqnarray} \| D(U(J)) = J \\ \| U(D(\{ a, m, d \})) = \{ a, m, d \} \end{eqnarray}

But if you enter a date or running day number that falls outside of the range of the calendrical calculations (so that at least one intermediate result doesn't fit in the chosen memory type) then at least one of the above conditions won't be met.

You can find those limits by starting at a date or running day number $$J_0$$ of which you're certain that the intermediate results remain small enough, and then go up to down from there until at least one of those conditions isn't satisfied anymore. Day 1 of month 1 of year 1 of the calendar is usually a suitable starting date.

That going up and down is for many calendars difficult to do based on the date. What date follows after $$\{ a, m, d \}$$? Usually it is $$\{ a, m, d + 1 \}$$, except at the end of the month, because then the next date is $$\{ a, m + 1, 1 \}$$ or perhaps $$\{ a + 1, 1, 1 \}$$, and it can be even more complicated. The calculations to determine if the end of the month or year have been reached can be so complicated that they have intermediate results that are too large to fit in the chosen memory type. Then you could incorrectly skip valid dates, or incorrectly accept invalid dates and then perhaps find the wrong limits.

And similarly if you go down to earlier dates. Which date comes before $$\{ a, m, 1 \}$$? Then you need to know how many days are in the preceding month, and then, too, you might get intermediate results that are too large.

It is much easier to go up and down based on the running day number, because every running day number is valid and every valid date has such a running day number.

The range of the calendrical calculations runs from running day number $$𝔏$$ through running day number $$𝔘$$. Those lower and upper limits are defined by

\begin{eqnarray} D(U(J)) \| = J \| \qquad (𝔏 ≤ J ≤ 𝔘) \\ D(U(𝔏 − 1)) \| ≠ 𝔏 − 1 \\ D(U(𝔘 + 1)) \| ≠ 𝔘 + 1 \\ 𝔏 \| ≤ J_0 \\ 𝔘 \| ≥ J_0 \end{eqnarray}

plus the condition that $$U(J)$$ must be the correct and valid date for every $$𝔏 ≤ J ≤ 𝔘$$, but that condition is difficult to check, especially near those limits, for the same reason that finding the date of the next or previous day is difficult.

You'd like to find those limits without having to check every $$J$$ in between those limits. You'd rather first go up from $$J_0$$ in big steps until things go wrong, and then take ever smaller steps between the greatest good and smallest bad $$J$$ until you've located the upper limit, and likewise for the lower limit. But then you have to take into account that there is a chance that also for some $$J$$ that are beyond the limits $$D(U(J)) = J$$ might hold. If while taking those big steps you happen to land on such a $$J$$ then you'll incorrectly think that you haven't gone beyond the limit yet.

The solution for these difficulties is to do these calculations not just for the $$w$$ for which you want to know the limits but also for a much bigger $$w$$, for example with both 32-bit numbers and 64-bit numbers. Then you can recognize a bad or invalid date by it being different when calculated with 32-bit numbers than when calculated with 64-bit numbers. With that extra check, the chance is much smaller that after a big step you incorrectly decide that you're still within the limits.

#### 15.2.4. Derivation of the Formulas

If $$f$$ and perhaps also $$\dabs{t}$$ are greater than or equal to $$g$$ then we can rewrite Equations \eqref{eq:template}ff to

\begin{align} \{ f_1, f_0 \} \| = \Div(f, g) \\ \{ t_1, t_0 \} \| = \Div(t, g) \\ f x + t \| = \dparen{f_1 g + f_0}x + t_1 g + t_0 \eqavide{eq:mod} \\ y \| = f_1 x + t_1 + \dfloorratio{f_0 x + t_0}{g} \\ e \| = \dmod{f_0 x + t_0}{g} \eqavide{eq:modmod} \end{align}

or

\begin{align} \{ f_1, f_0 \} \| = \Div(f, g) \\ \{ t_1, t_0 \} \| = \Div(t, g) \\ \{ ω, e \} \| = \Div(f_0 x + t_0, g) \label{eq:template2} \\ y \| = f_1 x + ω + t_1 \end{align}

We must have $$\dabs{f_0 x} = \dmod{f}{g} \dabs{x} ≤ w$$, and $$\dabs{f_1 x} = \dfloor{f/g} \dabs{x} ≈ f \dabs{x}/g ≤ w$$, so the limit on $$x$$ is roughly $$\dabs{x} ≤ w \min(1/\dmod{f}{g}, g/f)$$, which is greater than $$w/f$$. If $$g \dmod{f}{g} \lt f$$ then the limit on $$x$$ is roughly $$\dabs{x} ≤ w g/f$$ and that is the highest attainable range for any method.

For the first example (from $$s$$ to $$m$$) there is no gain to be had here because then $$f$$ is already less than $$g$$.

For the second example we find (from $$m$$ to $$s$$)

\begin{align*} \{ f_1, f_0 \} \| = \Div(146097, 4800) = \{ 30, 2097 \} \\ \{ t_1, t_0 \} \| = \Div(0, 4800) = \{ 0, 0 \} \\ \{ ω, e \} \| = \Div(2097m, 4800) \\ s \| = 30m + ω \end{align*}

Then the limit on $$x$$ is roughly $$\dabs{x} ≤ w \min(1/30, 1/2097) = w/2097 ≈ 1024074$$ months, which corresponds to roughly 85339 years. That is long enough.

For the third example there is no gain to be had here.

We can also split $$x$$ into a multiple of $$g$$ plus the remainder. Then we find

\begin{align} \{ x_1, x_0 \} \| = \Div(x, g) \\ fx + t \| = \dparen{f_1 g + f_0} \dparen{x_1 g + x_0} + t_1 g + t_0 \\ y \| = f_1 x + f_0 x_1 + t_1 + \dfloorratio{f_0 x_0 + t_0}{g} \\ e \| = \dmod{f_0 x_0 + t_0}{g} \end{align}

or

\begin{align} \{ x_1, x_0 \} \| = \Div(x, g) \\ \{ ω, e \} \| = \Div(f_0 x_0 + t_0, g) \label{eq:template3} \\ y \| = f_1 x + f_0 x_1 + ω + t_1 \end{align}

Then the numerator of the division can reach nearly the value $$g \dmod{f}{g}$$, so this method is only usable if $$g \dmod{f}{g} ≤ w$$. We then need $$\dabs{f_1 x} = \dfloor{f/g} \dabs{x} ≈ f \dabs{x}/g ≤ w$$, and $$\dabs{f_0 x_1} = \dmod{f}{g} \dabs{\dfloor{x/g}} ≈ (\dabs{x}/g) \dmod{f}{g} ≤ w$$, so the limit on $$x$$ is roughly $$\dabs{x} ≤ w \min(g/\dmod{f}{g}, g/f, 1) = w \min(g/f, 1)$$, which is the greatest that you can attain with any method.

For the first example we find from $$s$$ to $$m$$

\begin{align*} \{ s_1, s_0 \} \| = \Div(s, 146097) \\ \{ f_1, f_0 \} \| = \Div(4800, 146097) = \{ 0, 4800 \} \\ \{ ω, e \} \| = \Div(4800s_0, 146097) \\ m \| = 4800s_1 + ω \end{align*}

This method is usable here because $$g \dmod{f}{g} = g f_0 = 146097×4800 = 701265600 ≈ 0.33 w \lt w$$.

Then $$s$$ can have any value that fits in a 32-bit memory location. For example, if $$s = w = 2147483647$$ then

\begin{align*} \{ s_1, s_0 \} \| = \Div(2147483647, 146097) = \{ 14699, 3844 \} \\ \{ ω, e \} \| = \Div(4800×3844, 146097) = \Div(18451200, 146097) = \{ 126, 42978 \} \\ m \| = 4800×14699 + 126 = 70555326 \end{align*}

The greatest value that occurred in those calculations is the starting value of 2'147'483'647 which is not greater than $$w$$.

If we can handle intermediate results of arbitrary size then we could calculate directly

\begin{align*} \{ m, e \} \| = \Div(4800s, 146097) = \Div(4800×2147483647, 146097) \\ \| = \Div(10307921505600, 146097) = \{ 70555326, 42978 \} \end{align*}

which are the same results as before, but with an intermediate result that is far greater than $$w$$.

For the second example, from $$m$$ to $$s$$, we find

$g \dmod{f}{g} = 4800×2097 = 10065600 ≈ 0.0047 w \lt w$

so this method is usable.

\begin{align*} \{ m_1, m_0 \} \| = \Div(m, 4800) \\ \{ f_1, f_0 \} \| = \Div(146097, 4800) = \{ 30, 2097 \} \\ \{ ω, e \} \| = \Div(2097 m_0, 4800) \\ s \| = 30 m + 2097 m_1 + ω \end{align*}

and then the day number is the limiting factor, instead of the month number. $$s$$ cannot be greater than $$w$$ so $$m$$ cannot be greater than the 70'555'326 that we found above. For that $$m$$ we find

\begin{align*} \{ m_1, m_0 \} \| = \Div(70555326, 4800) = \{ 14699, 126 \} \\ \{ ω, e \} \| = \Div(2097×126, 4800) = \Div(264222, 4800) = \{ 55, 222 \} \\ s \| = 30×70555326 + 2097×14699 + 55 \\ \| = 2116659780 + 30823803 + 55 = 2147483638 \end{align*}

which is just below $$w$$, as expected. The greatest value that occurred in these calculations is the final value, which is less than $$w$$.

For the third example there is no gain to be had here, because $$m$$ had an upper limit of 82850 which is less than $$g = 765433$$. We can deduce the formulas:

\begin{align*} \{ m_1, m_0 \} \| = \Div(m, 765433) \\ \{ ω, e \} \| = \Div(2592 0m_0, 765433) \\ s \| = 25920m_1 + ω \end{align*}

but here $$m_0$$ can reach values up to and including 765432, and then the intermediate result $$25920m_0 = 25920×765432 = 19839997440 ≈ 9.3 w \gt w$$, so we still have the same problem as with the original formulas.

If $$g\dmod{f}{g} \gt w$$ then we have to try something else. Suppose we pick a whole number $$P \gt 1$$ and then calculate one time

\begin{align} \{ Q, R \} \| = \Div(f_0 P, g) \label{eq:PQR} \\ Q \| = \dfloorratio{f_0 P}{g} \\ R \| = \dmod{f_0 P}{g} \end{align}

so

$$f_0 P = g Q + R$$

Then, for each desired $$x$$, calculate

\begin{align} \{ x_1, x_0 \} \| = \Div(x, P) \\ x_1 \| = \dfloorratio{x}{P} \\ x_0 \| = \dmod{x}{P} \end{align}

so

$$x = x_1 P + x_0$$

and then

\begin{align} f x + t \| = (f_1 g + f_0)x + t_1 g + t_0 \notag \\ \| = (f_1 g + f_0)(x_1 P + x_0) + t_1 g + t_0 \notag \\ \| = f_1 g x_1 P + f_0 x_1 P + f_1 g x_0 + f_0 x_0 + t_1 g + t_0 \notag \\ \| = f_1 g x_1 P + x_1 (g Q + R) + f_1 g x_0 + f_0 x_0 + t_1 g + t_0 \notag \\ \| = f_1 g x_1 P + x_1 g Q + x_1 R + f_1 g x_0 + f_0 x_0 + t_1 g + t_0 \\ y \| = \dfloorratio{f x + t}{g} = f_1 x_1 P + x_1 Q + f_1 x_0 + t_1 + \dfloorratio{x_1 R + f_0 x_0 + t_0}{g} \notag \\ \| = f_1 x + x_1 Q + t_1 + \dfloorratio{x_1 R + f_0 x_0 + t_0}{g} \\ e \| = \dmod{f x + t}{g} = \dmod{x_1 R + f_0 x_0 + t_0}{g} \end{align}

The absolute values of $$x_1 R = \dfloor{x/P} R ≈ x R/P$$ and $$f_0 x_0 = f_0 \dmod{x}{P} \lt f_0 P$$ and $$f_1 x = \dfloor{f}{g} x ≈ f x/g$$ and $$x_1 Q = \dfloor{x}{P} Q ≈ x Q/P$$ must not exceed $$w$$, so the limit on $$x$$ is $$\dabs{x} ≤ w \min(P/R, g/f, P/Q, 1)$$ and in addition we must have $$f_0 P ≤ w$$.

If $$R = 0$$ then $$f$$ is a multiple of $$g$$ so then $$g\dmod{f}{g} = 0$$, and then we can use the method from the previous section. We therefore here assume that $$R ≠ 0$$.

If $$P = 1$$ then we get Equations \eqref{eq:template2}ff again, so we exclude that case.

The greatest range of $$x$$ that you can get with any method is $$W \min(g/f, 1)$$. We get that with the current method if $$P ≥ R$$ and $$P ≥ Q$$.

That last condition is always met, because

\begin{align*} f_0 P \| = g Q + R \\ P \| = \dfrac{g}{f_0} Q + \dfrac{R}{f_0} \end{align*}

and $$f_0 = \dmod{f}{g} \lt g$$, so $$P \gt Q$$.

Because we must have $$f_0 P ≤ w$$ we must also have $$P ≤ P_\text{max}$$, with

$$P_\text{max} ≜ \dfloorratio{w}{f_0}$$

so we only need to look at $$R ≤ P ≤ P_\text{max}$$.

The least possible value that $$R$$ can have is equal to the greatest common divisor $$\gcd(f_0, g)$$ of $$f_0$$ and $$g$$.

$$R = R_1 ≡ \gcd(f_0, g)$$

The Extended Algorithm of Euclid produces that value, and also numbers $$x$$ and $$y$$ such that

$$f_0 x + g y = R_1$$

The $$x$$ and $$y$$ that you get are in some sense the smallest, but the following values also work (with $$k$$ an arbitrary whole number):

$$f_0\dparen{x + k\dfrac{g}{R}} + g\dparen{y − k\dfrac{f_0}{R}} = R$$

Because $$R$$ is a divisor of $$g$$ and also of $$f_0$$, the divisions by $$R$$ in this formula always produces whole numbers.

The corresponding possible values of $$P$$ and $$Q$$ are then:

\begin{align} P \| = x + k\dfrac{g}{R} \\ Q \| = −y + k\dfrac{f_0}{R} \end{align}

for arbitrary whole $$k$$ for which $$P, Q \gt 0$$. The smallest usable positive $$P$$ and the corresponding value of $$Q$$ are

\begin{align} P_1 \| = \dmod{x}{(g/R_1)} \\ Q_1 \| = \dmod{−y}{(f_0/R_1)} \end{align}

These $$P_1, Q_1, R_1$$ comply with equations \eqref{eq:PQR}ff, because

$$\dfloorratio{f_0P_1}{g} = \dfloorratio{dQ_1 + R_1}{g} = Q_1 + \dfloorratio{R_1}{g} = Q_1$$

because $$\dfloor{R_1/g} = 0$$, because $$R_1 = \gcd(f_0,g) \lt g$$, because$$f_0 \lt g$$. And if $$Q_1$$ fits then $$R_1$$ fits, too.

If $$P_1 ≥ R_1$$ then we've already found a suitable combination of $$\{ P, Q, R \}$$. There are usually more suitable combinations of $$\{ P, Q, R \}$$. If you want to find all of them then you can do that as follows.

If $$P_1$$, $$Q_1$$, and $$R_1$$ belong together, then $$n P_1$$, $$n Q_1$$, and $$n R_1$$ also belong together, but $$\{ n P_1, n Q_1, n R_1 \}$$ is equally suitable or unsuitable as $$\{ P_1, Q_1, R_1 \}$$ is.

If $$P$$ and $$Q$$ belong with $$R$$ then also $$P + k g/R_1$$ and $$Q + k f_0/R_1$$ for arbitrary whole $$k$$ belong to that same $$R$$, because

\begin{align} f_0 \dparen{P + k\dfrac{g}{R_1}} − g \dparen{Q + k\dfrac{f_0}{R_1}} \notag \\ = f_0 P − g Q + k\dfrac{f_0 g}{R_1} − k \dfrac{f_0 g}{R_1} \notag \\ = f_0 P − g Q = R \end{align}

so we can add an arbitrary multiple of $$g/R_1$$ to $$P$$ if we add the corresponding multiple of $$f_0/R_1$$ to $$Q$$, and then that new $$P$$ and $$Q$$ belong to the same $$R$$ as the old $$P$$ and $$Q$$. That suggests something like $$P = \dmod{n P_1}{(g/R_1)}$$, but that always remains smaller than $$g/R_1$$ while larger $$P$$ up to $$w/f_0$$ may be interesting, too. For that reasone we use

\begin{align} P \| = \dmod{n P_1}{m_P} \\ m_P \| ≜ \dfrac{g n_*}{R_1} \\ m_Q \| ≜ \dfrac{f_0 n_*}{R_1} \\ n_* \| ≜ \dceilratio{w}{f_0 P_1} \end{align}

then

\begin{align} P \| = \dmod{n P_1}{m_P} \\ f_0 P \| = f_0 \dmod{n P_1}{m_P} = f_0 m_P \dmod{\dfrac{n P_1}{m_P}}{1} \notag \\ \| = g m_Q \dmod{\dfrac{n f_0 P_1}{f_0 m_P}}{1} = g m_Q \dmod{\dfrac{n \dparen{g Q_1 + R_1}}{g m_Q}}{1} \notag \\ \| = g m_Q \dmod{\dfrac{n \dparen{Q_1 + \dfrac{R_1}{g}}}{m_Q}}{1} = g \dmod{n Q_1 + \dfrac{n R_1}{g}}{m_Q} \\ Q \| = \dfloorratio{f_0 P}{g} = \dfloor{\dmod{n Q_1 + \dfrac{n R_1}{g}}{m_Q}} \notag \\ \| = \dmod{\dfloor{n Q_1 + \dfrac{n R_1}{g}}}{m_Q} \eqvide{eq:modfloor} \notag \\ \| = \dmod{n Q_1 + \dfloorratio{n R_1}{g}}{m_Q} \\ R \| = f_0 P − g Q = g \dmod{n Q_1 + \dfrac{n R_1}{g}}{m_Q} − g \dmod{n Q_1 + \dfloorratio{n R_1}{g}}{m_Q} \notag \\ \| = g \dmod{n Q_1 + \dfloorratio{n R_1}{g} + \dmod{\dfrac{n R_1}{g}}{1}}{m_Q} − g \dmod{n Q_1 + \dfloorratio{n R_1}{g}}{m_Q} \notag \\ \| = g \dparen{\dmod{a + b}{m_Q} − \dmod{a}{m_Q}} \\ a \| = n Q_1 + \dfloorratio{n R_1}{g} \\ b \| = \dmod{\dfrac{n R_1}{g}}{1} \\ \dmod{a + b}{m_Q} \| = \dmod{a}{m_Q} + \dmod{b}{m_Q} − m_Q C\dparen{\dmod{a}{m_Q} + \dmod{b}{m_Q} ≥ m_Q} \end{align}

We have $$m_Q ≥ 1$$ and $$0 ≤ b \lt 1$$ so $$\dmod{b}{m_Q} = b$$. We also have $$0 ≤ \dmod{a}{m_Q} ≤ m_Q − 1$$ (because $$a$$ and $$m_Q$$ are whole numbers), so $$0 ≤ \dmod{a}{m_Q} + \dmod{b}{m_Q} \lt m_Q$$ so the condition within $$C(•)$$ is never met, so that term drops away. All in all we find

\begin{align} \dmod{a + b}{m_Q} \| = \dmod{a}{m_Q} + b \\ R \| = g b = g \dmod{\dfrac{n R_1}{g}}{1} = \dmod{n R_1}{g} \end{align}

so

\begin{align} P \| = \dmod{nP_1}{m_P} \\ Q \| = \dmod{n Q_1 + \dfloorratio{n R_1}{g}}{m_Q} \\ R \| = \dmod{n R_1}{g} \end{align}

For calculating these numbers the following form is more convenient:

\begin{align} P \| = \dmod{n P_1}{m_P} \\ \{ ρ, R \} \| = \Div(n R_1, g) \\ Q \| = \dmod{n Q_1 + ρ}{m_Q} \end{align}

If you add $$m_P$$ to $$n$$ then you find the same $$P$$, $$Q$$, and $$R$$ as for $$n$$, because

\begin{align} \dmod{(n + m_P)P_1}{m_P} \| = \dmod{n P_1 + n m_P}{m_P} = \dmod{n P_1}{m_P} \\ \dmod{(n + m_P)R_1}{g} \| = \dmod{n R_1 + n_* \dfrac{g}{R_1} R_1}{g} = \dmod{n R_1 + n_* g}{g} = \dmod{n R_1}{g} \end{align} \begin{align} \| \dmod{(n + m_P)Q_1 + \dfloorratio{(n + m_P)R_1}{g}}{m_Q} \notag \\ \| = \dmod{n Q_1 + m_P Q_1 + \dfloor{\dfrac{n R_1}{g} + \dfrac{m_P R_1}{g}}}{m_Q} \notag \\ \| = \dmod{n Q_1 + m_P Q_1 + \dfloor{\dfrac{n R_1}{g} + n_*}}{m_Q} \notag \\ \| = \dmod{n Q_1 + \dfloor{\dfrac{n R_1}{g}} + m_P Q_1 + n_*}{m_Q} \qquad (n_* ∥ 1) \notag \\ \| = \dmod{n Q_1 + \dfloor{\dfrac{n R_1}{g}} + m_P \dparen{Q_1 + \dfrac{R_1}{g}}}{m_Q} \notag \\ \| = \dmod{n Q_1 + \dfloor{\dfrac{n R_1}{g}} + m_Q \dfrac{g}{f_0} \dfrac{f_0 P_1}{g}}{m_Q} \notag \\ \| = \dmod{n Q_1 + \dfloor{\dfrac{n R_1}{g}} + m_Q P_1}{m_Q} \notag \\ \| = \dmod{n Q_1 + \dfloor{\dfrac{n R_1}{g}}}{m_Q} \end{align}

With our example ($$f = f_0 = 25920$$, $$g = 765433$$, $$w = 2^{31} − 1 = 2147483647$$, $$P_1 = 99902$$, $$Q_1 = 3383$$, $$R_1 = 1$$) we find

\begin{align*} n_* \| = \dceilratio{w}{f_0 P_1} = \dceilratio{2147483647}{25920×99902} = 1 \\ P_\text{max} \| = \dfloorratio{w}{f_0} = \dfloorratio{2147483647}{25920} = 82850 \\ m_P \| = \dfrac{g n_*}{R_1} = 765433 \\ m_Q \| = \dfrac{f_0 n_*}{R_1} = 25920 \\ P \| = \dmod{n P_1}{m_P} = \dmod{99902n}{765433} \\ \{ ρ, R \} \| = \Div(n R_1, 765433) = \Div(n, 765433) \\ Q \| = \dmod{n Q_1 + ρ}{m_Q} = \dmod{3383n + ρ}{25920} \end{align*}

$${n}$$ $${P}$$ $${Q}$$ $${R}$$ $${P/R}$$ $${P/P_\text{max}}$$
1 99902 3383 1 99902 1.21
2 199804 6766 2 99902 2.41
3 299706 10149 3 99902 3.62
4 399608 13532 4 99902 4.82
5 499510 16915 5 99902 6.03
6 599412 20298 6 99902 7.23
7 699314 23681 7 99902 8.44
8 33783 1144 8 4222.9 0.41
 ✓ 
9 133685 4527 9 14853.9 1.61
10 233587 7910 10 23358.7 2.82
1064 665974 22552 1064 625.9 8.04
1065 443 15 1065 0.4 0.01
1066 100345 3398 1066 94.1 1.21
165698 307538 10414 165698 1.9 3.71
165699 407440 13797 165699 2.5 4.92
165700 507342 17180 165700 3.1 6.12

Only $$n$$ for which $$P/R ≥ 1$$ and $$P/P_\text{max} ≤ 1$$ and $$R ≠ 0$$ (which means $$0 \lt R ≤ P ≤ P_\text{max}$$) are good. There are 4485 good values, for $$n$$ between 1 and $$P_\text{max}$$. The smallest $$n$$ that yields a useful combination is $$n = 8$$.

A second case: $$f = f_0 = 4800$$, $$g = 146097$$. Then

\begin{align*} P_1 \| = 33511 \\ Q_1 \| = 1101 \\ R_1 \| = 3 \\ P_\text{max} \| = \dfloorratio{w}{f_0} = \dfloorratio{2147483647}{4800} = 447392 \\ n_* \| = \dceilratio{w}{f_0 P_1} = \dceilratio{2147483647}{4800×33511} = 14 \\ m_P \| = \dfrac{g n_*}{R_1} = \dfrac{146097×14}{3} = 681786 \\ m_Q \| = \dfrac{f_0 n_*}{R_1} = \dfrac{4800×14}{3} = 22400 \\ P \| = \dmod{n P_1}{m_P} = \dmod{33511 n}{681786} \\ \Div(ρ, R) \| = \Div(n R_1, g) = \Div(3 n, 146097) \\ Q \| = \dmod{n Q_1 + ρ}{m_Q} = \dmod{1101 n + ρ}{22400} \end{align*}

$${n}$$ $${P}$$ $${Q}$$ $${R}$$ $${P/R}$$ $${P/P_\text{max}}$$
1 33511 1101 3 11170.3 0.07
 ✓ 
2 67022 2202 6 11170.3 0.15
 ✓ 
3 100533 3303 9 11170.3 0.22
 ✓ 
12 402132 13212 36 11170.3 0.90
 ✓ 
13 435643 14313 39 11170.3 0.97
 ✓ 
14 469154 15414 42 11170.3 1.05
20 670220 22020 60 11170.3 1.50
 ✓ 
21 21945 721 63 348.3 0.05

$$n$$ from 1 through 13 provide good combinations (with $$P/R ≥ 1$$ and $$P/P_\text{max} \lt 1$$) and $$R ≠ 0$$, and after that the first good one is $$n = 21$$.

Here there are 374'336 values of $$n$$ between 1 and 681'785 that provide a good combination of $$\{ P, Q, R \}$$.

You can find suitable $$\{ P, Q, R \}$$ by trying all $$m_P − 1$$ unique values of $$n$$, but a more targeted search can be less work.

Start the search for good $$\{ P, Q, R \}$$ at the smallest $$R$$, because that yields the best chance of success. The least possible $$R = \dmod{n R_1}{g}$$ is $$R_1$$. That goes with $$n ≡ 1 \pmod{g/R_1}$$. We don't need to look at values of $$n$$ that are greater or equal to $$m_P$$ because then $$\{ P, Q, R \}$$ repeat again. We use

$$n = j + k \dfrac{g}{R_1}$$

for $$j$$ from 1 through $$(g/R_1) − 1$$ and $$k$$ from 0 through $$n_* − 1$$. $$k$$ must not be greater, because if $$k = n_*$$ then $$n = j + n_* (g/R_1) = m_P + j ≥ m_P$$ which is too large. And $$j$$ must not be greater, because if $$j = (g/R_1)$$ and $$k = n_* − 1$$ then $$n = (g/R_1) + (n_* − 1)(g/R_1) = m_P$$ which is too large as well.

The corresponding $$\{ P, Q, R \}$$ are

\begin{align} P \| = \dmod{n P_1}{m_P} = \dmod{j P_1 + k P_1 \dfrac{g}{R_1}}{m_P} = \dmod{j P_1 + k \dmod{P_1}{n_*} \dfrac{g}{R_1}}{m_P} \\ \{ ρ, R \} \| = \Div(j R_1, g) \\ Q \| = \dmod{n Q_1 + ρ + k}{m_Q} \end{align}

Notice that $$R$$ depends on $$j$$ but not on $$k$$, so if for a given value of $$j$$ you run through all values of $$k$$ then you'll get all values of $$P$$ that belong to that $$R$$.

If $$n_* = 1$$ then $$P$$ does not depend on $$k$$ so then there is only a single value of $$P$$ for each value of $$R$$.

If $$n_* \gt 1$$ then there are $$n_* \gt 1$$ values of $$P$$ to inspect for each $$j$$ (which means for each $$R$$). If a suitable $$P$$ is to be found, then $$j = 1$$ should usually yield such a suitable $$P$$.

We don't need to look at $$P \gt P_\text{max}$$, and we seek $$R ≤ P$$, so the greatest value of $$R$$ that we need to look at is $$P_\text{max}$$. It follows that the greatest value of $$j$$ that you need to look at is roughly equal to

$$\max(j) = \dfloorratio{P_\text{max}}{R_1} ≈ \dfloorratio{w}{f_0 R_1} \label{eq:maxj}$$

Our first case had $$f = 25920$$, $$g = 765433$$, $$R_1 = 1$$, $$P_\text{max} = 82850$$, and $$n_* = 1$$, so $$k = 0$$. Then we inspect $$j = n$$ from 1 through at most $$g/R_1 − 1 = 765432$$. Equation \eqref{eq:maxj} implies that the greatest $$j = n$$ that we need to look at is $$\dfloor{P_\text{max}/R_1} = 82850$$.

We looked at the first couple of values of $$n$$ before and found the first suitable results for $$n = 8$$.

Our second case had ($$f = 4800$$, $$g = 146097$$) and $$P_1 = 33511$$, $$Q_1 = 1101$$, $$R_1 = 3$$, $$n_* = 14$$, $$P_\text{max} = 447392$$, $$m_P = 681786$$, $$m_Q = 22400$$. Then the greatest value of $$j$$ to inspect is $$\dfloor{P_\text{max}/R_1} = \dfloor{447392/3} = 149130$$.

\begin{align*} n \| = j + k\dfrac{g}{R_1} = j + k \dfrac{146097}{3} = j + 48699 k \\ P \| = \dmod{j P_1 + k \dmod{P_1}{n_*} \dfrac{g}{R_1}}{m_P} = \dmod{33511 j + \dmod{33511}{14} \dfrac{146097}{3} k}{681786} \\ \| = \dmod{33511 j + k×9×48699}{681786} = \dmod{33511 j + 438291 k}{681786} \\ \{ ρ, R \} \| = \Div(j R_1, g) = \Div(3 j, 146097) \\ Q \| = \dmod{n Q_1 + ρ + k}{m_Q} = \dmod{1101 n + ρ + k}{22400} \end{align*}

For $$j = 1$$ we find

$${k}$$ $${n}$$ $${P}$$ $${Q}$$ $${R}$$ $${P/R}$$ $${P/P_\text{max}}$$
0 1 33511 1101 3 11170.3 0.07
 ✓ 
1 48700 471802 15501 3 157267.3 1.05
2 97399 228307 7501 3 76102.3 0.51
 ✓ 
3 146098 666598 21901 3 222199.3 1.49
4 194797 423103 13901 3 141034.3 0.95
 ✓ 
5 243496 179608 5901 3 59869.3 0.40
 ✓ 
6 292195 617899 20301 3 205966.3 1.38
7 340894 374404 12301 3 124801.3 0.84
 ✓ 
8 389593 130909 4301 3 43636.3 0.29
 ✓ 
9 438292 569200 18701 3 189733.3 1.27
10 486991 325705 10701 3 108568.3 0.73
 ✓ 
11 535690 82210 2701 3 27403.3 0.18
 ✓ 
12 584389 520501 17101 3 173500.3 1.16
13 633088 277006 9101 3 92335.3 0.62
 ✓ 
14 681787 33511 1101 3 11170.3 0.07
 ✓ 

We see that $$k = n_* = 14$$ produces the same $$\{ P, Q, R \}$$ as $$k = 0$$, which shows that we need to inspect $$k$$ only from 0 through $$n_* − 1$$. All 14 values yield $$P ≥ R$$ and 9 of those also yield $$P ≤ P_\text{max}$$ and so yield a good combination of $$\{ P, Q, R \}$$.

For $$j = 2$$ we find

$${k}$$ $${n}$$ $${P}$$ $${Q}$$ $${R}$$ $${P/R}$$ $${P/P_\text{max}}$$
0 2 67022 2202 6 11170.3 0.15
 ✓ 
1 48701 505313 16602 6 84218.8 1.13
2 97400 261818 8602 6 43636.3 0.59
 ✓ 
3 146099 18323 602 6 3053.8 0.04
 ✓ 
4 194798 456614 15002 6 76102.3 1.02
5 243497 213119 7002 6 35519.8 0.48
 ✓ 
6 292196 651410 21402 6 108568.3 1.46
7 340895 407915 13402 6 67985.8 0.91
 ✓ 
8 389594 164420 5402 6 27403.3 0.37
 ✓ 
9 438293 602711 19802 6 100451.8 1.35
10 486992 359216 11802 6 59869.3 0.80
 ✓ 
11 535691 115721 3802 6 19286.8 0.26
 ✓ 
12 584390 554012 18202 6 92335.3 1.24
13 633089 310517 10202 6 51752.8 0.69
 ✓ 
14 681788 67022 2202 6 11170.3 0.15
 ✓ 

Here, too, all $$k ≤ n_*$$ provide $$P ≥ R$$, and 9 of them also provide $$P ≤ P_\text{max}$$. The greatest value of $$P/R$$ is 108568, compared to 222199 for $$j = 1$$. This illustrates that a greater $$R$$ makes the ratio $$P/R$$ smaller, and so also the chance for a useful combination of $$\{ P, Q, R \}$$.

There can be multiple usable combinations of $$\{ P, Q, R \}$$, and all of them are good enough. Within that group, we prefer small $$P$$, $$Q$$, $$R$$, because that makes for calculations that are easier to perform and read.

For the first case there are usable combinations of $$\{ P, Q, R \}$$ for 4485 values of $$R$$ between 8 and 82'243. Within that group we search for the smallest value of $$PQR$$. We find

$${P}$$ $${Q}$$ $${R}$$ $${PQR}$$
1447 49 23 1.6 × 106
2894 98 46 1.3 × 107
945 32 544 1.6 × 107
4341 147 69 4.4 × 107
5788 196 92 1.0 × 108

We choose $$P = 1447$$, then $$R = 23$$ and $$Q = 49$$.

Now we calculate $$y$$, $$e$$ for $$x = 1710321$$. We find

\begin{align*} x_1 \| = \dfloorratio{x}{P} = \dfloorratio{1710321}{1447} = 1181 \\ x_0 \| = \dmod{x}{P} = \dmod{1710321}{1447} = 1414 \\ y \| = x_1 Q + \dfloorratio{x_1 R + f x_0 + t}{g} \\ \| = 1181×49 + \dfloorratio{1181×23 + 25920×1414 + 13835}{765433} \\ \| = 57869 + \dfloorratio{36691878}{765433} \\ \| = 57869 + 47 = 57916 \\ e \| = \dmod{36691878}{765433} = 716527 \end{align*}

The greatest intermediate result is 36'691'878, which is considerably less than $$w$$.

Had we been allowed arbitrarily large intermediate results, then we'd have found

\begin{align*} y \| = \dfloorratio{f x + t}{g} = \dfloorratio{25920×1710321 + 13835}{765433} = \dfloorratio{44331534155}{765433} = 57916 \\ e \| = \dmod{44331534155}{765433} = 716527 \end{align*}

which are the same results, but with the much greater intermediate result of 44'331'534'155 that is much greater than $$w$$.

For the second case ($$f = f_0 = 4800$$, $$g = 146097$$) there are 374'336 usable combinations. The usable combinations with the smallest $$PQR$$ are:

$${P}$$ $${Q}$$ $${R}$$ $${PQR}$$
487 16 48 3.7 × 105
3135 103 9 2.9 × 106
974 32 96 3.0 × 106
761 25 375 7.1 × 106
1461 48 144 1.0 × 107

We choose $$P = 487$$, then $$Q = 16$$ and $$R = 48$$. We calculate $$y$$, $$e$$ for $$x = 731767$$. Then

\begin{align*} x_1 \| = \dfloorratio{731767}{487} = 1502 \\ x_0 \| = \dmod{731767}{487} = 293 \\ y \| = 1502×16 + \dfloorratio{1502×48 + 4800×293 + 15793}{146097} \\ \| = 24032 + \dfloorratio{1494289}{146097} = 24032 + 10 = 24042 \\ e \| = \dmod{1494289}{146097} = 33319 \end{align*}

The greatest intermediate result is 1'494'289, which is comfortably smaller than $$w$$. With the original formula we'd have found

\begin{align*} y \| = \dfloorratio{4800×731767 + 15793}{146097} = \dfloorratio{3512497393}{146097} = 24042 \\ e \| = \dmod{3512497393}{146097} = 33319 \end{align*}

which are the same results as before but with the greatest intermediate result equal to 3'512'497'393, which is considerably larger than $$w$$.

### 15.3. The Simple Calendar

For convenience, we'll work with a calendar that has only "days" and "months", where the months are longer than the days, but the formulas also work for other units of time. Later, we'll discuss calendars with more than two time periods.

We'll indicate with $$m$$ the month number, with $$d$$ the day number within the month, and with $$s$$ the running day number that is the start or endpoint of the calculation.

#### 15.3.1. From Month and Day Number Within the Month to Running Day Number

In the simplest case, the average length of the month is equal to $$p$$ days, and all months are either $$⌊p⌋$$ or $$⌊p⌋ + 1$$ days long. We define $$q$$ as the length of the short months, and $$ψ$$ as the fraction of months that are long. Then

\begin{eqnarray} q \| = \| \dfloor{p} \\ p \| = \| q + ψ \end{eqnarray}

The running day number $$s$$ depends on the month number $$m$$ and the day number $$d$$ within the current month as follows:

\begin{eqnarray} σ \| ≡ \| ⌊pm + b⌋ \label{eq:sm} \\ s \| ≡ \| σ + d \label{eq:s} \end{eqnarray}

where $$m, d, s, σ$$ are whole numbers, and $$p ≥ 1$$ and $$b$$ are fixed values that depend on the calendar. The first month has $$m = 0$$ and the first day of the month has $$d = 0$$, for easier calculation. $$σ$$ is the running day number of the beginning of the month. If values of $$σ$$ for multiple months are of interest then we write $$σ[m]$$ for the value of $$σ$$ that goes with month $$m$$.

The first day ($$d = 0$$) of the first month ($$m = 0$$) has running day number $$s = 0$$, so

$$⌊b⌋ = 0 ⇔ 0 ≤ b \lt 1$$

So $$b$$ must be between 0 and 1 (0 is allowed, 1 is not).

#### 15.3.2. Month Length

The length $$L(m)$$ of month $$m$$ is

\begin{eqnarray} L(m) \| = \| σ(m + 1) − σ(m) \notag \\ \| = \| \dfloor{q (m + 1) + ψ (m + 1) + b} − \dfloor{qm + ψm + b} \notag \\ \| = \| q + \dfloor{ψm + ψ + b} − \dfloor{ψm + b} \notag \\ \| = \| q + \dfloor{ψm + b} + C\dparen{\dmod{ψm + b}{1} + ψ ≥ 1} − \dfloor{ψm + b} \eqavide{eq:splitfloor} \notag \\ \| = \| q + C\dparen{\dmod{ψm + b}{1} + ψ ≥ 1} \end{eqnarray}

All months are $$q$$ or $$q + 1$$ days long. Month $$m$$ is a long month (with $$q + 1$$ days) if $$\dmod{ψx + b}{1} ≥ 1 − ψ$$. On average there is a long month after every

$$Q = \frac{1}{ψ} \label{eq:Q}$$

months, but that isn't always a whole number, so in practice the number of months between two successive long months is equal to $$⌊Q⌋$$ or $$⌈Q⌉$$.

Also

\begin{align} L(m) \| = q + \dfloor{ψm + ψ + b} − \dfloor{ψm + b} \notag \\ \| = q + ψm + ψ + b − \dmod{ψm + b + ψ}{1} − \dparen{ψm + b − \dmod{ψm + b}{1}} \notag \\ \| = q + ψ + \dmod{ψm + b}{1} − \dmod{ψm + b + ψ}{1} \notag \\ \| = p + \dmod{ψm + b}{1} − \dmod{ψm + b + ψ}{1} \end{align}

#### 15.3.3. Shifting the Pattern of Months

With this we get a certain pattern of long and short months. Suppose that that pattern would be exactly right if only it were shifted by $$∆m$$ months. So if $$σ_*$$ goes with the old calendar (with $$b_*$$) and $$σ$$ goes with the new calendar (with $$b = b_* + ∆b$$) then we want that the following holds for all values of $$m$$:

$$σ(m + 1) − σ(m) = σ_*(m + ∆m + 1) − σ_*(m + ∆m)$$

We have

\begin{align} \| σ(m + 1) − σ(m) \notag \\ \| = \dfloor{p(m + 1) + b} − \dfloor{pm + b} \notag \\ \| = \dfloor{pm + b + p} − \dfloor{pm + b} \notag \\ \| = \dfloor{\dfloor{pm + b} + \dmod{pm + b}{1} + p} − \dfloor{pm + b} \notag \\ \| = \dfloor{pm + b} + \dfloor{\dmod{pm + b}{1} + p} − \dfloor{pm + b} \notag \\ \| = \dfloor{\dmod{pm + b}{1} + p} \end{align}

and also

\begin{align} \| σ_*(m + ∆m + 1) − σ_*(m + ∆m) \notag \\ \| = \dfloor{p(m + ∆m + 1) + b_*} − \dfloor{p(m + ∆m) + b_*} \notag \\ \| = \dfloor{pm + p∆m + b_* + p} − \dfloor{pm + p∆m + b_*} \notag \\ \| = \dfloor{\dfloor{pm + p∆m + b_*} + \dmod{pm + p∆m + b_*}{1} + p} − \dfloor{pm + p∆m + b_*} \notag \\ \| = \dfloor{pm + p∆m + b_*} + \dfloor{\dmod{pm + p∆m + b_*}{1} + p} − \dfloor{pm + p∆m + b_*} \notag \\ \| = \dfloor{\dmod{pm + b_* + p∆m}{1} + p} \end{align}

so we get what we want if

$$b = \dmod{b_* + p∆m}{1}$$

#### 15.3.4. From Running Day Number to Month and Day Number Within the Month

We go from running month number $$m$$ and day number $$d$$ within the month to running day number $$s$$ via a formula like

$$s = \dfloor{pm + v} + d = σ + d \label{eq:sv}$$

where $$v$$ is an arbitrary number. Equation \eqref{eq:s} is like Eq. \eqref{eq:sv} if $$v = b$$. For finding $$m$$ from $$s$$ we look for a formula like:

$$m = \dceilratio{s + u − p}{p} = \dceilratio{s + u}{p} − 1$$

What should $$u$$ be to make this work?

\begin{align} m \| = \dceilratio{s + u − p}{p} \notag \\ \| = \dceilratio{\dfloor{pm + v} + d + u − p}{p} \eqavide{eq:s} \notag \\ \| = \dceilratio{d + u + pm + v − \dmod{pm + v}{1} − p}{p} \notag \\ \| = m + \dceilratio{d + u + v − \dmod{pm + v}{1} − p}{p} \end{align}

so then we need

\begin{eqnarray} \dceilratio{d + u + v − \dmod{pm + v}{1} − p}{p} = 0 \notag \\ −1 \lt \dfrac{d + u + v − \dmod{pm + v}{1} − p}{p} ≤ 0 \notag \\ −p \lt d + u + v − \dmod{pm + v}{1} − p ≤ 0 \notag \\ \dmod{pm + v}{1} − v − d \lt u ≤ \dmod{pm + v}{1} − v − d + p \end{eqnarray}

This must hold for all values of $$d$$ and $$m$$ that can occur in the calendar. For the left-hand inequality $$… \lt u$$ this means that we should substitute the least value that $$d$$ can have, because greater values of $$d$$ meet the inequality more easily than lesser values do. So we can substitute $$d = 0$$.

For the right-hand inequality $$u ≤ …$$ we should substitute the greatest value of $$d$$ that can occur, because lesser values of $$d$$ meet the inequality more easily than greater values do. So we can substitute $$d = L(m) − 1$$, the day number (since the beginning of the month) of the last day in month $$m$$. We rewrite it into a more form that is more convenient here.

\begin{align} L(m) \| = σ(m + 1) − σ(m) \notag \\ \| = \dfloor{p(m + 1) + v} − \dfloor{pm + v} \notag \\ \| = \dparen{pm + v + p − \dmod{pm + v + p}{1}} − \dparen{pm + v − \dmod{pm + v}{1}} \notag \\ \| = p + \dmod{pm + v}{1} − \dmod{pm + v + p}{1} \end{align}

Then we find

\begin{equation*} \dmod{pm + v}{1} − v \lt u ≤ \dmod{pm + v}{1} − v − \dparen{p + \dmod{pm + v}{1} − \dmod{pm + v + p}{1} − 1} + p \end{equation*}

$$\dmod{pm + v}{1} − v \lt u ≤ \dmod{pm + v + p}{1} − v + 1$$

For the left-hand inequality $$… \lt u$$ we should substitute the greatest possible value of $$\dmod{pm + v}{1}$$. That value is just less than 1, so if we substitute 1 then we can change the $$\lt$$ to $$≤$$. For the right-hand inequality $$u ≤ …$$ we should substitute the least possible value of $$\dmod{pm + v + p}{1}$$, which is 0. Then we find

$$1 − v ≤ u ≤ 1 − v$$

Those inequalities have exactly one solution:

$$u = 1 − v$$

so

$$m = \dceilratio{s + 1 − v − p}{p} = \dceilratio{s + 1 − v}{p} − 1 \label{eq:svtom}$$

In the above derivation it was necessary to use the inequality $$d ≤ L(m) − 1$$. If we had instead used $$d \lt L(m)$$ then we would not have found a solution. That means that you may get the wrong answer if $$s$$ is a decimal number that belongs to a moment of time during the last day of the month.

The transition from one value of $$m$$ to the next happens when

$\dfrac{s + 1 − v − p}{p}$

is exactly a whole number (which we'll call $$μ$$), so when

$s = pμ + p + v − 1 = p(μ + 1) + v − 1$

$$p$$ and $$v$$ need not be whole numbers, so the value of $$s$$ at which Equation \eqref{eq:svtom} switches to a new month need not be a whole number, either.

So Equation \eqref{eq:svtom} requires $$s$$ to be a whole number, otherwise you may get the wrong month number $$m$$.

With $$p = 30.6$$ and $$v = b = 0$$ we find

$s = \dfloor{pm + b} + d = \dfloor{30.6m} + d$

so month $$m = 2$$ begins on day

$s = \dfloor{30.6×2} + 0 = \dfloor{61.2} = 61$

From day $$s$$ to month $$m$$ goes via

$m = \dceilratio{s + 1 − b − p}{p} = \dceilratio{s − 29.6}{30.6}$

That yields, for a few moments between $$s = 60$$ and $$s = 61$$:

$${s}$$ $${\dfrac{s−29.6}{30.6}}$$ $${m}$$
60 0.99346405 1
60.2 1. 1
60.21 1.0003268 2
61 1.0261438 2

so for $$s$$ equal to or just below 60.2 we find $$m = 1$$ as desired, but for $$s$$ greater than 60.2 and less than 61 we find $$m = 2$$ while that part, too, of day $$s = 60$$ still belongs to month $$m = 1$$.

And then we can also find $$d$$.

\begin{align} pm \| = p\dceilratio{s + 1 − v}{p} − p \notag \\ \| = p\dparen{\dfrac{s + 1 − v}{p} + \ddom{\dfrac{s + 1 − v}{p}}{1}} − p \eqavide{eq:dom} \notag \\ \| = s + 1 − v − p + \ddom{s + 1 − v}{p} \\ d \| = s − \dfloor{pm + v} \notag \\ \| = s − \dfloor{s + 1 − p + \ddom{s + 1 − v}{p}} \notag \\ \| = −\dfloor{1 − p + \ddom{s + 1 − v}{p}} \eqavide{eq:minusfloor} (s ∥ 1) \notag \\ \| = \dceil{p − 1 − \ddom{s + 1 − v}{p}} \eqavide{eq:minusceil} \end{align}

So if we split $$s + 1 − v$$ into

$$s + 1 − v = pμ − δ = p\dceilratio{s + 1 − v}{p} − \ddom{s + 1 − v}{p}$$

then

\begin{align} m \| = μ − 1 \label{eq:mviaμ} \\ d \| = \dceil{p − 1 − δ} \label{eq:dviaδ} \end{align}

We can rewrite this so we can use the $$\Div$$ function, through

$$\{−μ,δ\} = \Div(−(s + 1 − v), p)$$

For the simple calendar $$v = b$$ so then

\begin{align} \{−μ,δ\} \| = \Div(−(s + 1 − b), p) \\ m \| = μ − 1 = \dceilratio{s + 1 − b}{p} − 1 \label{eq:ynaarx} \\ d \| = \dceil{p − 1 − δ} = \dceil{p − 1 − \ddom{s + 1 − b}{p}} \end{align}

An example, with $$p = 30.6$$ and $$b = 0$$. We get

\begin{align*} σ \| = \dfloor{pm + b} = \dfloor{30.6 m} \\ L(m) \| = q + C\dparen{\dmod{ψm + b}{1} + ψ ≥ 1} = 30 + C\dparen{\dmod{0.6m}{1} ≥ 0.4} \\ μ \| = \dceilratio{s + 1 − b}{p} = \dceilratio{s + 1}{30.6} \\ m \| = μ − 1 = \dceilratio{s − 29.6}{30.6} \\ δ \| = \ddom{s + 1 − b}{p} = \ddom{s + 1}{30.6} \\ d \| = \dceil{p − 1 − δ} = \dceil{29.6 − δ} = \dceil{29.6 − \ddom{s + 1}{30.6}} \end{align*}

And then, for the first few months

$${m}$$ $${pm}$$ $${σ(m)}$$ $${L(m)}$$
−1 −30.6 −31 31
0 0 0 30
1 30.6 30 31
2 61.2 61 30
3 91.8 91 31
4 122.4 122 31
5 153 153 30
6 183.6 183 31
7 214.2 214 30
8 244.8 244 31
9 275.4 275 31
10 306 306

Because $$5p = 153$$ is a whole number, the pattern of month lengths repeats itself after 5 months. We see here the pattern 31-30-31-30-31 that in the Gregorian calendar describes the months March - July and August - December.

Now we go in the opposite direction, for a few running day numbers:

$${s}$$ $${μ}$$ $${δ}$$ $${m}$$ $${d}$$
−2 0 1. −1 29
−1 0 0. −1 30
0 1 29.6 0 0
1 1 28.6 0 1
90 3 0.8 2 29
91 4 30.4 3 0
120 4 1.4 3 29
121 4 0.4 3 30
122 5 30. 4 0
123 5 29. 4 1

### 15.4. With Whole Numbers Only

Calculating machines often work with a limited number of decimals behind the decimal mark, so you can get into trouble with round-off errors. If $$(s + 1 − b)/p = 6.99999999998$$ but because of a very small round-off error your calculating machine thinks that $$(s + 1 − b)/p = 7.00000000001$$, then your calculating machine thinks that $$\dceil{(s + 1 − b)/p} = 7$$ rather than 6, and then you find the wrong month.

Converting equations with $$⌈•⌉$$ or $$⌈•⌋_1$$ into equations with $$⌊•⌋$$ or $$⌊•⌉_1$$ or $$\Div$$ is easier when only whole numbers are used, because for arbitrary whole numbers $$x$$ and $$y$$ ($$y \gt 0$$)

\begin{align} \dceilratio{x}{y} \| = \dfloorratio{x − 1}{y} + 1 \eqavide{eq:ceil2floor} \\ \ddom{x}{y} \| = y − 1 − \dmod{x − 1}{y} \eqavide{eq:ddom2dmod} \end{align}

If the average length $$p$$ is a ratio (of whole numbers), then we can avoid round-off errors by rewriting the formulas based on ratios. We define

\begin{align} p \| = \dfrac{f}{g} = q + \dfrac{h}{g} \\ q \| = \dfloorratio{f}{g} \\ h \| = \dmod{f}{g} \end{align}

with $$f$$, $$g$$ whole numbers greater than zero. Then we find, for an arbitrary value $$x$$,

$$\dmod{x}{(f/g)} = \dmod{x}{p} = p\dmod{\dfrac{x}{p}}{1} = \dfrac{f \dmod{\dfrac{gx}{f}}{1}}{g} = \dfrac{\dmod{gx}{f}}{g} \label{eq:gmodp}$$

and likewise

$$\ddom{x}{(f/g)} = \dfrac{\ddom{gx}{f}}{g} \label{eq:gdomp}$$

Then we go from month $$m$$ and day $$d$$ to running day number $$s$$ through

$$t ≡ vg$$

\begin{align} s \| = \dfloor{pm + v} + d \notag \\ \| = \dfloor{\dfrac{fm + vg}{g}} + d \notag \\ \| = \dfloor{\dfrac{fm + t}{g}} + d \end{align}

where we demand that $$t$$ is a whole number, too. If $$v$$ is a ratio then you can always achieve that by a suitable choice of $$g$$.

For the month length we find

$$L(m) = q + C\dparen{\dmod{hm + t}{g} ≥ g − h}$$

For the calculation of $$m$$ and $$d$$ from $$s$$ we find:

\begin{align} m \| = \dceilratio{s + 1 − v}{p} − 1 = \dceilratio{gs + g − t}{f} − 1 \notag \\ \| = \dfloorratio{gs + g − t − 1}{f} \eqvide{eq:ceil2floor} (t,g,s,f ∥ 1) \label{eq:ynaarx2} \\ d \| = \dceil{p − 1 − \ddom{s + 1 − v}{p}} \notag \\ \| = \dceilratio{f − g − \ddom{gs + g − t}{f}}{g} \eqvide{eq:gdomp} \notag \\ \| = \dfloorratio{f − g − \ddom{gs + g − t}{f} − 1}{g} + 1 \eqvide{eq:ceil2floor} (t,g,s,f ∥ 1) \notag \\ \| = \dfloorratio{f − g − (f − 1 − \dmod{gs + g − t − 1}{f}) − 1}{g} + 1 \eqvide{eq:ddom2dmod} \notag \\ \| = \dfloorratio{\dmod{gs + g − t − 1}{f}}{g} \eqvide{eq:ddom2dmod} \end{align}

Summarizing, from running month number $$m$$ and day number $$d$$ in the month to running day number $$s$$:

$$s = \dfloorratio{fm + t}{g} + d$$

and from $$s$$ to $$m$$ and $$d$$:

\begin{align} w \| = gs + g − t − 1 \\ m \| = \dfloorratio{w}{f} \label{eq:ynaarxr} \\ d \| = \dfloorratio{\dmod{w}{f}}{g} \end{align}

Now you can do all calculations with ratios, which have no numbers after the decimal mark and hence no round-off errors.

For the same calendar as before we have $$p = 30.6 = 153/5, b = 0$$, so $$f = 153, g = 5, t = 0$$. We then find

\begin{align*} s \| = \dfloorratio{153m}{5} + d \\ w \| = 5s + 4 \\ m \| = \dfloorratio{5s + 4}{153} \\ d \| = \dfloorratio{\dmod{5s + 4}{153}}{5} \end{align*}

and for the beginning of the first few months

$${m}$$ $${σ}$$ $${L(m)}$$
0 0 30
1 30 31
2 61 30
3 91 31
4 122 31
5 153 30
6 183 31
7 214 30
8 244 31
9 275 31
10 306 30
11 336 31
12 367

Now we go in the opposite direction, for a few running day numbers:

$${s}$$ $${w}$$ $${m}$$ $${\dmod{w}{f}}$$ $${d}$$
−2 −6 −1 147 29
−1 −1 −1 152 30
0 4 0 4 0
1 9 0 9 1
120 604 3 145 29
121 609 3 150 30
122 614 4 2 0
123 619 4 7 1

### 15.5. Very Unequal Months

So far we have assumed that a long month was only one day longer than a short month, but that difference can be larger. Suppose that short months are $$q$$ days long and that long months are $$q + r$$ days long, with $$q$$, $$r$$ whole numbers greater than 0, and that a fraction $$ψ$$ (between 0 and 1) of all months is long. Then the average length of a month is equal to

$$p = q + rψ$$

days. The formula to calculate the running day number $$σ$$ of the first day of month $$m$$ is then

$$σ = qm + r\dfloor{ψm + b} \label{eq:sm2}$$

If we substitute $$r = 1$$ then we find

\begin{eqnarray} σ \| = \| qm + \dfloor{ψm + b} \notag \\ \| = \| \dfloor{(q + ψ)m + b} \notag \\ \| = \| \dfloor{pm + b} \end{eqnarray}

which is the same result as Eq. \eqref{eq:sm}.

With Eq. \eqref{eq:sm2}, the length $$L(m)$$ of month $$m$$ is

\begin{eqnarray} L(m) \| = \| σ(m + 1) − σ(m) \notag \\ \| = \| q(m + 1) + r\dfloor{ψ(m + 1) + b} − (qm + r\dfloor{ψm + b}) \notag \\ \| = \| q + rC\dparen{\dfloor{ψm + ψ + b} − \dfloor{ψm + b}} \notag \\ \| = \| q + rC\dparen{\ddom{ψm + b}{1} + ψ ≥ 1} \eqavide{eq:splitfloor} \end{eqnarray}

so the long months are those for which $$\ddom{ψm + b}{1} + ψ ≥ 1$$, just like we found earlier for the simple calendar.

The formula to calculate the running day number $$s$$ from month number $$m$$ and day number $$d$$ in the current month is then

\begin{eqnarray} s \| = \| σ + d \notag \\ \| = \| qm + r⌊ψm + b⌋ + d \label{eq:xnaary3} \end{eqnarray}

How do we go in the opposite direction? To figure that out we compare the running day number that comes from equation \eqref{eq:xnaary3} for the first day ($$d = 0$$) of month $$m$$ with the running day number that follows for the same $$m$$ from the most similar simplest calendar. We write the outcome for the desired calendar as $$σ$$ and for the simpler comparison calendar as $$σ_*$$.

\begin{align} σ \| = qm + r\dfloor{ψm + b} \\ σ_* \| = qm + \dfloor{r(ψm + b)} = \dfloor{pm + rb} \label{eq:σ*} \\ ∆σ ≡ σ_* − σ \| = \dfloor{r(ψm + b)} − r\dfloor{ψm + b} \notag \\ \| = r(ψm + b) − \dmod{r(ψm + b)}{1} − \dparen{r(ψm + b) − r\dmod{ψm + b}{1}} \notag \\ \| = r\dmod{ψm + b}{1} − \dmod{r(ψm + b)}{1} \notag \\ \| = r\dmod{ψm + b}{1} − \dmod{r\dmod{ψm + b}{1}}{1} \notag \\ \| = \dfloor{r\dmod{ψm + b}{1}} \end{align}

This difference satisfies

$$0 \le σ_* − σ \le r − 1$$

so the beginning of month $$m$$ in the target calendar is between $$0$$ and $$r − 1$$ days (inclusive) before the beginning of month $$m$$ in the simple calendar.

For example, let $$q = 30, ψ = 0.12, r = 5, b = 0.1$$. Then $$p = q + rψ = 30.6$$ is the average length of a month. We find for the first 10 months

$${m}$$ $${σ_*}$$ $${σ}$$ $${σ_* − σ}$$ $${ψm + b}$$ $${r\dmod{ψm + b}{1}}$$
0 0 0 0 0.1 0.5
1 31 30 1 0.22 1.1
2 61 60 1 0.34 1.7
3 92 90 2 0.46 2.3
4 122 120 2 0.58 2.9
5 153 150 3 0.7 3.5
6 184 180 4 0.82 4.1
7 214 210 4 0.94 4.7
8 245 245 0 1.06 0.3
9 275 275 0 1.18 0.9

and $$σ_* − σ$$ varies between 0 and $$r − 1 = 5 − 1 = 4$$ as expected.

For that simpler calendar based on $$σ_*$$ we have Equation \eqref{eq:svtom} to calculate the month number from the running day number:

$m_*(s) = \dceilratio{s + 1 − v}{p} − 1$

That means that

$$m_↑ = m_*(s + \max(∆σ)) = \dceilratio{s + \max(∆σ) + 1 − v}{p} − 1$$

is greater than or equal to the correct month number. And

$$m_↓ = m_*(s + \min(∆σ)) = \dceilratio{s + \min(∆σ) + 1 − v}{p} − 1$$

is less than or equal to the correct month number.

With $$m_↑$$ we find

$$d_↑ = s − σ(m_↑)$$

If $$d_↑ \lt 0$$ then $$m_↑$$ is too great. If $$d_↑ \ge 0$$ then we have the correct month number but $$d_↑$$ is probably not the correct day number.

Can we find a recipe to calculate $$d$$ with a fixed number of steps? Something like

\begin{align} m_↑ \| ≡ \dceilratio{s + \max(∆σ) + 1 − v}{p} − 1 \\ d_↑ \| = s − σ(m_↑) \\ m \| = m_↑ + ξ \\ d \| = s − σ(m) \end{align}

where $$ξ$$ is the correction to apply to $$m_↑$$ to get $$m$$. We cannot always find $$ξ$$ in one go, but can sometimes find it if $$ξ = 0$$ or $$ξ = 1$$, i.e., when the difference between $$m_↑$$ and $$m$$ is at most 1.

We then need $$ξ = 0$$ if $$d_↑ ≥ 0$$, and $$ξ = −1$$ if $$d_↑ \lt 0$$. That suggests something like

$$ξ = \dfloorratio{d_↑}{Ξ}$$

because that yields $$ξ = 0$$ if $$0 \le d_↑ \lt Ξ$$ and yields $$ξ = −1$$ if $$−Ξ \le d_↑ \lt 0$$. What value should we use for $$Ξ$$? That depends on the least and greatest value that $$d_↑$$ can have, so let's deduce those first.

\begin{align} s \| = σ(m) + d \notag \\ \| = σ_*(m) − ∆σ(m) + d \notag \\ \| = \dfloor{pm + v} − ∆σ(m) + d \notag \\ \| = pm + v − \dmod{pm + v}{1} − ∆σ(m) + d \end{align}

so

\begin{align} m_↑ − m \| = \dceilratio{s + \max(∆σ) + 1 − v}{p} − 1 − m \notag \\ \| = \dceilratio{pm + v − \dmod{pm + v}{1} − ∆σ(m) + d + \max(∆σ) + 1 − v}{p} − 1 − m \notag \\ \| = \dceilratio{1 − \dmod{pm + v}{1} + \max(∆σ) − ∆σ(m) + d}{p} − 1 \end{align}

Always $$0 \lt 1 − \dmod{•}{1} \le 1$$, and $$\max(∆σ) − ∆σ(m) \ge 0$$, and $$d ≥ 0$$, so the part between $$\dceil{}$$ is always greater than 0, so $$m_↑ − m ≥ 0$$ as desired. When is certainly $$m_↑ − m ≤ 1$$? Then we must have

\begin{align*} \dceilratio{1 − \dmod{pm + v}{1} + \max(∆σ) − ∆σ(m) + d}{p} ≤ 2 \\ \dfrac{1 − \dmod{pm + v}{1} + \max(∆σ) − ∆σ(m) + d}{p} ≤ 2 \\ 1 − \dmod{pm + v}{1} + \max(∆σ) − ∆σ(m) + d ≤ 2p \end{align*}

The greatest value that $$d$$ can have is $$\max(L) − 1$$, so we certainly have $$m_↑ − m \le 1$$ if

$$ρ ≡ \max(∆σ) − \min(∆σ) + \max(L) − 2p ≤ 0 \label{eq:singlepass}$$

If $$m_↑ = m$$ then the least value of $$d_↑$$ is 0 and the greatest value is $$\max(L) − 1$$.

If $$m_↑ = m + 1$$ then

\begin{align} d_↑ \| = s − σ(m_↑) \notag \\ \| = s − σ(m + 1) \notag \\ \| = \dparen{pm + v − \dmod{pm + v}{1} − ∆σ(m) + d} \notag \\ \| − \dparen{pm + v + p − \dmod{pm + v + p}{1} − ∆σ(m + 1)} \notag \\ \| = d − p + \dparen{\dmod{pm + v + p}{1} − \dmod{pm + v}{1}} + ∆σ(m + 1) − ∆σ(m) \notag \\ \| \gt 0 − p + \min\dparen{\dmod{pm + v + p}{1} − \dmod{pm + v}{1}} \notag \\ \| + \min(∆σ(m + 1) − ∆σ(m)) \notag \\ \| = −p + (\dmod{p}{1} − 1) + \min(∆σ(m + 1) − ∆σ(m)) \eqvide{eq:domp} \notag \\ \| = −p + \dmod{p}{1} − 1 + \min(L_*(m) − L(m)) \notag \\ \| = −\dfloor{p} − 1 + \min(L_*(m) − L(m)) \eqvide{eq:mod} \notag \\ \| ≥ −\dfloor{p} − 1 + \min(L_*) − \max(L) \notag \\ \| = −\dfloor{p} − 1 + \dfloor{p} − \max(L) \notag \\ \| = −1 − \max(L) \notag \\ d_↑ \| \gt −1 − \max(L) \\ d_↑ \| ≥ −\max(L) \end{align}

so

$$−\max(L) ≤ d_↑ ≤ \max(L) − 1$$

For

$ξ = \dfloorratio{d_↑}{Ξ}$

we then need both of the following conditions satisfied:

\begin{align*} \dfloorratio{−\max(L)}{Ξ} = −1 \\ \dfloorratio{\max(L) − 1}{Ξ} = 0 \end{align*}

Both those conditions are equivalent to

$$Ξ ≥ \max(L)$$

So if we use

$$Ξ = \max(L)$$

(or a greater value) then we meet both constraints.

Summarizing, if

$ρ = \max(∆σ) − \min(∆σ) + \max(L) − 2p ≤ 0$

then

\begin{align} m_↑ \| = \dceilratio{s + \max(∆σ) + 1 − v}{p} − 1 \\ d_↑ \| = s − σ_↑ = s − σ(m_↑) \\ ξ \| = \dfloorratio{d_↑}{\max(L)} \\ m \| = m_↑ + ξ \\ d \| = s − σ(m) \end{align}

With

\begin{align*} v \| = rb \\ \max(∆σ) \| = r − 1 \\ \min(∆σ) \| = 0 \\ \max(L) \|= q + r \\ p \| = q + rψ \end{align*}

we find

\begin{align} m_↑ \| = \dceilratio{s + r − rb}{p} − 1 \label{eq:ynaarx3} \\ d_↑ \| = s − σ_↑ = s − σ(m_↑) \\ ρ \| = 2r(1 − ψ) − 1 − q \\ ξ \| = \dfloorratio{d_↑}{q + r} \\ m \| = m_↑ + ξ \\ d \| = s − σ(m) \end{align}

so $$ρ ≤ 0$$ corresponds to

$$r ≤ \dfrac{1}{2} \dfrac{q + 1}{1 − ψ} ≥ q + 1$$

If $$ρ \gt 0$$ then the recipe doesn't always work so then you shouldn't use it. Then see Section 15.7.

For the calendar from the previous example we find

\begin{align*} m_↑ \| = \dceilratio{s + r − rb}{p} − 1 = \dceilratio{s − 26.1}{30.6} \\ ρ \| = 2r(1 − ψ) − q − 1 = 2×5×(1 − 0.12) − 1 − 30 = −22.2 ≤ 0 \end{align*}

Because $$ρ ≤ 0$$ we can use the recipe with the fixed number of steps.

$${s}$$ $${m}$$ $${\dfrac{s-26.1}{30.6}}$$ $${m_↑}$$ $${m_↑-m}$$ $${d_↑}$$ $${ξ}$$ $${m}$$ $${d}$$
−5 −1 −1.0163399 −1 0 30 0 −1 30
−4 −1 −0.98366013 0 1 −4 −1 −1 31
0 0 −0.85294118 0 0 0 0 0 0
1 0 −0.82026144 0 0 1 0 0 1
29 0 0.094771242 1 1 −1 −1 0 29
30 1 0.12745098 1 0 0 0 1 0
59 1 1.0751634 2 1 −1 −1 1 29
60 2 1.1078431 2 0 0 0 2 0
89 2 2.0555556 3 1 −1 −1 2 29
90 3 2.0882353 3 0 0 0 3 0
119 3 3.0359477 4 1 −1 −1 3 29
120 4 3.0686275 4 0 0 0 4 0
148 4 3.9836601 4 0 28 0 4 28
149 4 4.0163399 5 1 −1 −1 4 29
150 5 4.0490196 5 0 0 0 5 0
153 5 4.1470588 5 0 3 0 5 3
154 5 4.1797386 5 0 4 0 5 4
209 6 5.9771242 6 0 29 0 6 29
210 7 6.0098039 7 0 0 0 7 0
214 7 6.1405229 7 0 4 0 7 4
215 7 6.1732026 7 0 5 0 7 5

and there indeed $$m_↑ ≥ m$$.

If $$p = f/g$$, $$ψ = h/g$$ and $$b = t/g$$ are ratios of whole numbers ($$f, g, h, t$$ are whole numbers with $$f \gt g \gt 0$$, $$0 \le h, t \lt g$$), then we find

\begin{align} s \| = σ + d = qm + r\dfloorratio{hm + t}{g} + d \label{eq:xnaary3r} \\ m_↑ \| = \dceilratio{s + \max(∆σ) + 1 − v}{p} − 1 \notag \\ \| = \dceilratio{gs + g\max(∆σ) + g − gv}{f} − 1 \notag \\ \| = \dceilratio{gs + g\max(∆σ) + g − t}{f} − 1 \notag \\ \| = \dfloorratio{gs + g\max(∆σ) + g − t − 1}{f} \eqavide{eq:ceil2floor} \\ ρ \| = 2r\dparen{1 − \dfrac{h}{g}} − 1 − q \\ d_↑ \| = s − qm_↑ − r\dfloorratio{hm_↑ + t}{g} \\ ξ \| = \dfloorratio{d_↑}{q + r} \\ m \| = m_↑ + ξ \\ d \| = s − qm − r\dfloorratio{hm + t}{g} \end{align}

For the calendar from the previous examples we find (with $$q = 30, ψ = 0.12 = 3/25, r = 5, b = 0.1 = 1/10$$) $$f = 1530, g = 50, h = 6, t = 5$$ and then

\begin{align*} σ \| = 30m + 5\dfloorratio{6m + 5}{50} \\ s \| = 30m + 5\dfloorratio{6m + 5}{50} + d \\ m_↑ \| = \dfloorratio{50s + 50×4 + 50 − 5 − 1}{1530} = \dfloorratio{50s + 244}{1530} \\ d_↑ \| = s − 30m_↑ − 5\dfloorratio{6m_↑ + 5}{50} \\ ξ \| = \dfloorratio{d_↑}{35} \\ m \| = m_↑ + ξ \\ d \| = s − 30m − 5\dfloorratio{6m + 5}{50} \end{align*}

$${m}$$ $${σ}$$
0 0
1 30
2 60
3 90
4 120
5 150
6 180
7 210
8 245
9 275

$${s}$$ $${m_↑}$$ $${d_↑}$$ $${ξ}$$ $${m}$$ $${d}$$
−5 −1 30 0 −1 30
−4 0 −4 −1 −1 31
−1 0 −1 −1 −1 34
0 0 0 0 0 0
1 0 1 0 0 1
148 4 28 0 4 28
149 5 −1 −1 4 29
150 5 0 0 5 0
209 6 29 0 6 29
210 7 0 0 7 0

### 15.6. Many Kinds of Unequal Months

We now allow there to be more than two kinds of months with different month lengths. In equation \eqref{eq:xnaary3}, $$\dfloor{ψm + b}$$ gave the pattern of long months (with a shift as desired). We now allow an arbitrary number of such pattern, each with its own length difference $$r_i$$ (that can be positive or negative), relative frequency $$0 \lt ψ_i \lt 1$$, and pattern shift $$b_i$$. Then we find

\begin{align} σ \| = qm + \sum_{i}r_i \dfloor{ψ_im + b_i} \\ s = σ + d \| = qm + \sum_{i}r_i \dfloor{ψ_im + b_i} + d \label{eq:xnaary4} \end{align}

The derivation of the formulas for the opposite direction goes analogous to that of equation \eqref{eq:ynaarx3}. We find

\begin{align} σ_* \| = qm + \dfloor{\sum_i r_i (ψ_i m + b_i)} \notag \\ \| = \dfloor{pm + \sum_i r_i b_i} \notag \\ \| = pm + \sum_i r_i b_i − \dmod{\sum_i r_i \dparen{ψ_i m + b_i}}{1} \label{eq:σ*∑} \eqavide{eq:mod} \\ ∆σ = σ_* − σ \| = \dfloor{\sum_{i}r_{i}(ψ_{i}m + b)} − \sum_{i} r_{i}\dfloor{ψ_{i}m + b_{i}} \notag \\ \| = \dfloor{\sum_{i} r_{i}\dmod{ψ_{i}m + b_{i}}{1}} \eqavide{eq:dmoddiff1} \notag \end{align}

so

\begin{align} v \| = \sum_i r_ib_i \\ \max(L) \| ≤ q + \sum_{r_i \gt 0} r_i \\ \max(∆σ) \| ≤ \dparen{\sum_{r_i \gt 0} r_i} − 1 \\ \min(∆σ) \| ≥ \sum_{r_i \lt 0} r_i \\ ρ \| = \max(∆σ) − \min(∆σ) + \max(L) − 2p \notag \\ \| ≤ 2\dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_{r_i \lt 0} r_i} − q − 1 − 2\dparen{\sum_i r_i ψ_i} \end{align}

It is permissible to use a higher value for $$\max(L)$$ in the below formulas, such as the value given above at the right hand side of $$\max(L) ≤$$, and similarly for the other inequalities. For convenience, we pretend that those inequalities are equalities.

And so

\begin{align} m_↑ \| = \dceilratio{s + \max(∆σ) + 1 − v}{p} − 1 \notag \\ \| = \dceilratio{s + \dparen{\sum_{r_i \gt 0} r_i} − \sum_i r_i b_i}{p} − 1 \label{eq:ynaarx4} \\ d_↑ \| = s − qm_↑ − \sum_i r_i\dfloor{ψ_i m_↑ + b_i} \\ ρ \| = 2\dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_{r_i \lt 0} r_i} − q − 1 − 2\dparen{\sum_i r_i ψ_i} \end{align}

If $$ρ ≤ 0$$ then $$m$$ and $$m_↑$$ differ by at most 1. That condition corresponds to

\begin{align} 2\dparen{\sum_{r_i \gt 0} r_i} \| − \dparen{\sum_{r_i \lt 0} r_i} − q − 1 − 2\dparen{\sum_i r_i ψ_i} ≤ 0 \notag \\ \dparen{\sum_{r_i \gt 0} r_i} \| + \dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_{r_i \lt 0} r_i} − q − 1 − 2\dparen{\sum_i r_i ψ_i} ≤ 0 \notag \\ \dparen{\sum_{r_i \gt 0} r_i} \| + \dparen{\sum_{i} |r_i|} − q − 1 − 2\dparen{\sum_i r_i ψ_i} ≤ 0 \notag \\ \sum_{r_i \gt 0} r_i \| ≤ q + 1 + 2\dparen{\sum_i r_i ψ_i} − \dparen{\sum_{i} |r_i|} \eqavide{eq:singlepass} \end{align}

Then

\begin{align} ξ \| = \dfloorratio{d_↑}{q + \sum_{r_i \gt 0} r_i} \\ m \| = m_↑ + ξ \label{eq:xζ4} \\ d \| = s − qm − \sum_i r_i\dfloor{ψ_i m + b_i} \end{align}

If all $$ψ_i = h_i/g_i$$ and $$b_i = t_i/g_i$$ are ratios of whole numbers, and if condition \eqref{eq:singlepass} is met, then we find

\begin{align} p \| = q + \sum_i r_iψ_i = q + \sum_i \dfrac{r_i h_i}{g_i} \\ g \| = \lcm(g_i) \\ γ_i \| = \dfrac{g}{g_i} \\ f \| = pg = gq + \sum_i γ_i r_i h_i \\ s \| = qm + \sum_i r_i\dfloorratio{h_im + t_i}{g_i} + d \label{eq:xnaary4r} \\ m_↑ \| = \dceilratio{s + \dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_i r_i b_i}}{f/g} − 1 \notag \\ \| = \dceilratio{gs + g\dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_i γ_i r_i t_i}}{f} − 1 \notag \\ \| = \dfloorratio{gs + g\dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_i γ_i r_i t_i} − 1}{f} \label{eq:ynaarx4r} \\ d_↑ \| = s − qm_↑ − \sum_i r_i\dfloorratio{h_im_↑ + t_i}{g_i} \\ ρ \| = 2\dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_{r_i \lt 0} r_i} − q − 1 − 2\dparen{\sum_i \dfrac{r_i h_i}{g_i}} \\ ξ \| = \dfloorratio{d_↑}{q + \sum_{r_i \gt 0} r_i} \\ m \| = m_↑ + ξ \\ d \| = s − qm − \sum_i r_i\dfloorratio{h_im + t_i}{g_i} \end{align}

$$g$$ is the least common multiple of the denominators of all $$ψ_i$$ and $$b_i$$.

Suppose we want a calendar in which each month has 17 days, with each 3rd month getting 2 days extra, and each 5th month getting 3 days extra. Then the first couple of months contain the following number of days: 17, 17, 19, 17, 20, 19, 17, 17, 19, 20, 17, 19, 17, 17, 22.

Then we have $$q = 17$$ and

$${i}$$ $${r_i}$$ $${ψ_i}$$ $${g_i}$$ $${h_i}$$ $${t_i}$$ $${γ_i}$$
1 2 1/3 3 1 0 5
2 3 1/5 5 1 0 3

and $$g = 15$$ (the product of denominators 3 and 5). Then

\begin{align*} p \| = 17 + 2×\dfrac{1}{3} + 3×\dfrac{1}{5} = 18 + \dfrac{4}{15} \\ f \| = pg = 15×\dparen{18 + \dfrac{4}{15}} = 274 = 15×17 + 5×2×1 + 3×3×1 \\ s \| = 17m + 2\dfloorratio{m}{3} + 3\dfloorratio{m}{5} \\ m_↑ \| = \dfloorratio{15s + 15×5 − 0 − 1}{274} = \dfloorratio{15s + 74}{274} \\ d_↑ \| = s − 17m_↑ − 2\dfloorratio{m_↑}{3} − 3\dfloorratio{m_↑}{5} \\ ρ \| = 2×5 − 0 − 17 − 1 − 2×\dparen{\dfrac{2×1}{3} + \dfrac{3×1}{5}} = −10 − \dfrac{8}{15} \\ ξ \| = \dfloorratio{d_↑}{22} \\ m \| = m_↑ + ξ \\ d \| = s − 17m − 2\dfloorratio{m}{3} − 3\dfloorratio{m}{5} \end{align*}

The following table shows the results that you get when you calculate for certain calendar dates $$m$$, $$d$$ what the corresponding running day number $$s$$ is, and then calculate from that $$s$$ what the month number $$m$$ is.

$${m}$$ $${d}$$ $${s}$$ $${m_↑}$$ $${d_↑}$$ $${ξ}$$ $${m_↑+ξ}$$
0 0 0 0 0 0 0
0 16 16 1 −1 −1 0
1 0 17 1 0 0 1
1 16 33 2 −1 −1 1
2 0 34 2 0 0 2
2 18 52 3 −1 −1 2
3 0 53 3 0 0 3
3 16 69 4 −1 −1 3
4 0 70 4 0 0 4
4 19 89 5 −1 −1 4
5 0 90 5 0 0 5
5 18 108 6 −1 −1 5
6 0 109 6 0 0 6
6 16 125 7 −1 −1 6
7 0 126 7 0 0 7
7 16 142 8 −1 −1 7
8 0 143 8 0 0 8
8 18 161 9 −1 −1 8
9 0 162 9 0 0 9
9 19 181 10 −1 −1 9
10 0 182 10 0 0 10
10 16 198 11 −1 −1 10
11 0 199 11 0 0 11
11 18 217 12 −1 −1 11
12 0 218 12 0 0 12
12 16 234 13 −1 −1 12
13 0 235 13 0 0 13
13 16 251 14 −1 −1 13
14 0 252 14 0 0 14
14 21 273 15 −1 −1 14
15 0 274 15 0 0 15
15 16 290 16 −1 −1 15

### 15.7. Very Unequal Month Lengths

The preceding methods for calculating the calendar date from the running day number for calendars with very unequal month lengths assumed that the variation in month lengths is sufficiently small that the month number calculated with the corresponding simple calendar is at most one off: $$2\dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_{r_i \lt 0} r_i} − q − 1 − 2\dparen{\sum_i r_iψ_i} ≤ 0$$. What to do if that condition is not met?

In that case you'll have to find the correct month by searching for it. First try month number $$m_↑$$ and calculate the corresponding $$d_↑$$ and $$ξ$$. Is that $$ξ \lt 0$$? Then subtract 1 from $$m_↑$$ and try again, until $$ξ = 0$$: then you have found the correct $$m$$.

Warning! In previous sections we added $$ξ$$ to $$m_↑$$ to correct the month number, but here we are not certain that that could never produce a month number that is too small. A month number that is too large is easy to detect (then $$d_↑ \lt 0$$) but a month number that is too small is not easy to detect. So we must not add $$ξ$$. If $$ξ \lt 0$$, then subtract 1 from the month number and try again with that new month number, and repeat until $$ξ = 0$$.

Let $$q = 3$$, $$r = 7$$, $$ψ = 1/3$$, then $$h = 1$$, $$g = 3$$, $$f = 16$$, $$p = q + rψ = 3 + 5/3 = 5 \frac{2}{3}$$, and $$ρ = \dfloor{2×5\frac{2}{3}} + 1 − 10 = 2$$ so the condition $$r ≤ ρ$$ is not satisfied. In this calendar the first three months have length $$3, 3, 10$$ days, and that pattern repeats every three months. For this calendar, we have

\begin{align*} m_↑ \| = \dfloorratio{3s + 20}{16} \\ σ \| = 3m + 7\dfloorratio{m}{3} \end{align*}

We find

$${s}$$ $${m_↑}$$ $${σ_↑}$$ $${d₁}$$ $${ξ₁}$$ $${m₂}$$ $${σ₂}$$ $${d₂}$$ $${ξ₂}$$ $${m₃}$$ $${σ₃}$$ $${d₃}$$ $${ξ₄}$$ $${m}$$ $${d}$$
0 1 3 −3 −1 0 0 0 0 0 0
1 1 3 −2 −1 0 0 1 0 0 1
2 1 3 −1 −1 0 0 2 0 0 2
3 1 3 0 0 1 0
4 2 6 −2 −1 1 3 1 0 1 1
5 2 6 −1 −1 1 3 2 0 1 2
6 2 6 0 0 2 0
7 2 6 1 0 2 1
8 2 6 2 0 2 2
9 2 6 3 0 2 3
10 3 16 −6 −1 2 6 4 0 2 4
11 3 16 −5 −1 2 6 5 0 2 5
12 3 16 −4 −1 2 6 6 0 2 6
13 3 16 −3 −1 2 6 7 0 2 7
14 3 16 −2 −1 2 6 8 0 2 8
15 4 19 −4 −1 3 16 −1 −1 2 6 9 0 2 9
16 4 19 −3 −1 3 16 0 0 3 0

For example: for $$s = 11$$ we find

\begin{align*} m_1 \| = m_↑ = \dfloorratio{3×11 + 20}{16} = 3 \\ σ_1 \| = σ(m_1) = 3×3 + 7\dfloorratio{3}{3} = 16 \\ d_1 \| = s − σ_1 = 11 − 16 = −5 \end{align*}

That $$d_1$$ is negative, so we decrement $$m$$ by one ($$m_2 = m_1 − 1 = 2$$) and try again. With the new $$m$$ we find

\begin{align*} σ_2 \| = 3×2 + 7\dfloorratio{2}{3} = 6 \\ d_2 \| = s − σ_2 = 11 − 6 = 5 \end{align*}

which is no longer negative, so we're done. For $$s = 11$$ we find $$m = 2$$ and $$d = 5$$.

If you want to, then you can use this procedure also if condition \eqref{eq:singlepass} is met.

The greatest number of months that you may have to try before you find the right one is equal to the greatest value that $$m_↑ − m_↓$$ can attain, plus 1.

\begin{align} m_↑ − m_↓ \| = \dceilratio{s + \max(∆σ) + 1 − v}{p} − \dceilratio{s + \min(∆σ) + 1 − v}{p} \\ \| ≤ \dceilratio{\max(∆σ) − \min(∆σ)}{p} + 1 \eqvide{eq:ceildiffrange} \end{align}

so the number of months that you have to try at most is

$$N = \dceilratio{\max(∆σ) − \min(∆σ)}{p} + 2$$

For a calendar with two month lengths this means

$$N = \dceilratio{r − 1}{p} + 2$$

and for a calendar with more month lengths

\begin{align} N \| ≤ \dceilratio{\dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_{r_i \lt 0} r_i}}{p} + 2 \\ \| = \dceilratio{\sum_i |r_i|}{p} + 2 \end{align}

### 15.8. Month Lengths Without Internal Patterns

Previously we looked at calendars of which the month lengths can be expressed as the sum of various patterns, for example with an extra day every second month and two additional days every third month, so that each sixth month gets three extra days in total. But what if the months repeat after some time but show no other discernable pattern?

As an example we use a calendar with the following month lengths, that keep repeating themselves indefinitely: 7, 13, 5, 11, 4 days. The "year" is 7 + 13 + 5 + 11 + 4 = 40 days long. The relationship between running day number $$s$$, running month number $$m$$, and day number $$d$$ in the current month (all starting at 0) is then

$${s}$$ $${m}$$ $${d}$$
0 0 0
1 0 1
6 0 6
7 1 0
19 1 12
20 2 0
24 2 4
25 3 0
35 3 10
36 4 0
39 4 3

The calendar has $$f$$ days in $$g$$ months, for an average month length of $$p = f/g$$ days. The relationship between the running day number $$s$$ and the running month number $$m$$ is a step function: after a (varying) number of days, the month number increases by one. Such a step of 1 that occurs just before day $$a$$ and repeats itself every $$f$$ days can be obtained through the formula

$$\dfloorratio{s − a}{f} + 1 = \dfloorratio{s + f − a}{f}$$

The $$+ 1$$ arranges that the result is 0 for $$s \lt a$$ and 1 for $$s ≥ a$$.

For the example calendar we have $$f = 40$$ and $$g = 5$$ and there is (amongst others) a step just before day $$a = 7$$. We get that with

$m = \dfloorratio{s − 7}{40} + 1 = \dfloorratio{s + 33}{40}$

$${s}$$ $${s−7}$$ $${m}$$
0 −7 0
1 −6 0
6 −1 0
7 0 1
8 1 1
46 39 1
47 40 2
48 41 2

When there are $$g$$ months, each with its own $$a_i$$ (for $$i$$ from 0 through $$g − 1$$), then their combined effect is

$$\sum_{i=0}^{g−1} \dparen{\dfloorratio{s − a_i}{f} + 1} = g + \sum_{i=0}^{g−1} \dfloorratio{s − a_i}{f} = \sum_{i=0}^{g−1} \dfloorratio{s + f − a_i}{f}$$

As usual we want that month $$m = 0$$ begins when $$s = 0$$, so then we must have $$a_0 = 0$$.

If the successive month lengths are $$L_i$$, then the first step is at $$a_0 = 0$$, the second one is at $$a_1 = a_0 + L_0 = L_0$$, the third one is at $$a_2 = a_1 + L_1 = L_0 + L_1$$, and in general

$$a_i = \sum_{j=0}^{i-1} L_j$$

Then

$$m = \sum_{i=0}^{g−1} \dfloorratio{s + f − \sum_{j=0}^{i−1} L_j}{f} \label{eq:willekeurigynaarx}$$

For the example calendar we have $$f = 40$$, $$g = 5$$, and

$${i}$$ $${L_i}$$ $${a_i}$$
1 7 0
2 13 7
3 5 20
4 11 25
5 4 36

and so

\begin{align*} m \| = \dfloorratio{s + 40 − 0}{40} + \dfloorratio{s + 40 − 7}{40} + \dfloorratio{s + 40 − 20}{40} + \dfloorratio{s + 40 − 25}{40} + \dfloorratio{s + 40 − 36}{40} \\ \| = \dfloorratio{s + 40}{40} + \dfloorratio{s + 33}{40} + \dfloorratio{s + 20}{40} + \dfloorratio{s + 15}{40} + \dfloorratio{s + 4}{40} \end{align*}

For example, if $$s = 21$$ then

$m = \dfloorratio{61}{40} + \dfloorratio{54}{40} + \dfloorratio{41}{40} + \dfloorratio{36}{40} + \dfloorratio{25}{40} = 1 + 1 + 1 + 0 + 0 = 3$

If we go in the other direction then we also have a staircase, but now days and months exchange roles as length and height of the steps. With that, the formula for the running day number $$σ$$ of the first day of month $$m$$ is:

$$σ = \sum_{i=0}^{g−1} L_i \dfloorratio{m + g − 1 − i}{g}$$

With again the same calendar, we find

$σ = 7 \dfloorratio{m + 4}{5} + 13 \dfloorratio{m + 3}{5} + 5 \dfloorratio{m + 2}{5} + 11 \dfloorratio{m + 1}{5} + 4 \dfloorratio{m}{5}$

$${x}$$ $${7⌊(x+4)/5⌋}$$ $${{13⌊(x+3)/5⌋}}$$ $${5⌊(x+2)/5⌋}$$ $${11⌊(x+1)/5⌋}$$ $${4⌊x/5⌋}$$ $${c}$$
0 0 0 0 0 0 0
1 7 0 0 0 0 7
2 7 13 0 0 0 20
3 7 13 5 0 0 25
4 7 13 5 11 0 36
5 7 13 5 11 4 40

The formula to go from running month number $$m$$ and day number $$d$$ in the current month to running day number $$s$$ (all beginning at 0) is then (with $$i$$ running from 0 through $$g − 1$$)

$$s = σ + d = \sum_{i=0}^{g−1} m_i \dfloorratio{m + g − 1 − i}{g} + d \label{willekeurigxnaary}$$

These formulas are, if you write out the summation, a lot longer than the formulas that we found earlier for calendars with internal patterns, so it is convenient if you recognize such patterns for a calendar, but not every calendar has such patterns.

The simple calendar from section 15.3 has $$s = \dfloor{pm + v} + d$$. To have that calendar begin month $$m$$ at running day $$s$$ we need $$s = \dfloor{pm + v}$$, from which follows $$s ≤ pm + b \lt s + 1$$, hence (for $$m \gt 0$$) $$(s − b)/m ≤ p \lt (s + 1 − b)/m$$. We know that $$0 ≤ b \lt 1$$, so

$\frac{s − 1}{m} \lt \frac{s − b}{m} \le p \lt \frac{s + 1 − b}{p} \le \frac{s + 1}{p}$

so

$$\frac{s − 1}{m} \lt p \lt \frac{s + 1}{m} \label{eq:beperkp}$$

Not every $$p$$ that meets these restrictions yields a simple calendar, but if a $$p$$ does not meet these restrictions for at least one of its months, then there is certainly no simple calendar for these month lengths.

Our example calendar does not meet the restrictions that are necessary for the simple formulas from section 15.3 to apply, because there are more than two different month lengths, even if we leave the last month out of consideration.

We can also see this using equation \eqref{eq:beperkp}. The first day of month $$m = 1$$ has $$s = 7$$, so we must have $$6 \lt p \lt 8$$. The first day of month $$m = 2$$ has $$s = 20$$ so we need $$9\frac{1}{2} = 19/2 \lt p \lt 21/2 = 10\frac{1}{2}$$, and already we're in trouble, because to have the beginning of month $$x = 1$$ in the right place $$p$$ must be less than 8, but to have the beginning of month $$x = 2$$ in the right place $$p$$ must be greater than 9½, and those restrictions cannot be met at the same time.

### 15.9. Combinations of straight lines

It is rare for a calendar to be fully defined by just one period $$p$$, so usually you have to combine several periods. Let's assume that we have formulas for two periods:

\begin{align} y_1 \| = D_1(\{ x_1, z_1 \}) \\ y_2 \| = D_2(\{ x_2, z_2 \}) \end{align}

We don't use $$m$$, $$d$$, and $$s$$ here because we may want to use different units of time than months and days. $$x$$ counts the larger unit, and $$y$$ and $$z$$ count the smaller unit. $$y$$ is the running number of smaller units, and $$z$$ is the number of smaller units since the first one in the most recent larger unit. Mapping $$D_1$$ says that you can calculate $$y_1$$ from $$x_1$$ and $$z_1$$, and likewise for mapping $$D_2$$.

In the other direction we have

\begin{align} \{ x_1, z_1 \} \| = U_1(y_1) \\ \{ x_2, z_2 \} \| = U_2(y_2) \end{align}

where $$U$$ and $$D$$ are each other's inverse:

\begin{align} y \| = D(U(y)) \\ \{ x, z \} \| = U(D(\{ x, z \})) \end{align}

To go from calendar date to running day number we first apply $$D_1$$ and then $$D_2$$. There are two ways to combine these: We can equate $$y_1$$ to $$z_2$$ or to $$x_2$$. In the first case, the two periods have the same leap unit, for example days. In the second case, the two periods have different leap units (for example, sometimes an extra day for the first period, and sometimes an extra month for the second period). If the larger period needs no leap rules at all, then you can choose which combination method to use.

Let's call the first case the "flat" combination, because the leap units remain the same. Let's call the second case the "stepped" combination, because the leap unit goes a step higher.

The combination of months and years in most (perhaps all) solar calendars (such as the Gregorian calendar, the Julian calendar, and the Egyptian calendar) is flat, i.e. of the first kind. A month can be a day shorter or longer than another month (and exactly one month can be a lot shorter), and a year can be a day shorter or longer than another year. The number of days in a year does not depend on the months, because the rules to calculate the length of the year depend on the year number but not on the month number.

The combination of months and years in a lunisolar calendar (such as the Hebrew and Babylonian calendars) can be flat with very unequal year lengths ($$r \gt 1$$) or stepped (then usually $$r = 1$$). A month can be a day longer or shorter than another month, and a year can be a month shorter or longer than another month. (For the flat combination, one month of the year can be much shorter.) In this way you can follow two separate (astronomical) cycles: the motion of the Sun (with the year) and the motion of the Moon (with the month). If the combination is stepped, then the length of the year depends on the length of the months, because the year is then defined in terms of a fixed number of months, not a fixed number of days.

Lunar calendars that are not lunisolar (such as the administrative Islamic calendar) usually do not have any leap rules, so then both methods can be used.

If a calendar has more than two important large periods with leap rules (for example, not just for the month and the year, but also for the century), then it is possible that some combinations are flat and others are stepped.

If we have to deal with more than one period, then it is important for translating a running day number into a calendar date to have the running numbers begin at 0 for each of those periods.

As an example we'll take for the first calendar a simple one with $$p_1 = 7/3 = 2 \frac{2}{3}$$ and for the second calendar a simple one with $$p_2 = 37/5 = 7 \frac{2}{5}$$. Then we have

\begin{align*} y_1 \| = \dfloorratio{7x_1}{3} + z_1 = σ_1 + z_1 \\ x_1 \| = \dfloorratio{3y_1 + 2}{7} \\ z_1 \| = \dfloorratio{⌊3y_1 + 2⌉_7}{3} \end{align*}

\begin{align*} y_2 \| = \dfloorratio{37x_2}{5} + z_2 = σ_2 + z_2 \\ x_2 \| = \dfloorratio{5y_2 + 4}{37} \\ z_2 \| = \dfloorratio{⌊5y_2 + 4⌉_{37}}{5} \end{align*}

and also

\begin{align*} \{x_1, r_1\} \| = \Div(3y_1 + 2, 7) \\ z_1 \| = \dfloorratio{r_1}{3} \\ \{x_2, r_2\} \| = \Div(5y_2 + 4, 37) \\ z_2 \| = \dfloorratio{r_2}{5} \end{align*}

#### 15.9.1. Flat combination

In this case $$z_2 = y_1$$, so

\begin{align} y_1 \| = D_1\dparen{\{x_1, z_1\}} \\ y_2 \| = D_2\dparen{\{x_2, z_2\}} = D_2\dparen{\{x_2, D_1\dparen{\{x_1, z_1\}}\}} \label{eq:vlak} \end{align}

and in the other direction

\begin{align} \{ x_2, z_2 \} \| = U_2(y_2) \label{eq:vlakr} \\ \{ x_1, z_1 \} \| = U_1(z_2) \end{align}

or, with a diagram

  x₂ ──────────┐
x₁ ┐         │
z₁ ┴ y₁ = z₂ ┴ y₂


The lowest row has the smallest calendar unit, usually days. Higher rows have greater calendar units, for example months and years. $$x_2$$ could be the year number, $$x_1$$ the month number within the year, $$z_1$$ the day number within the month, $$y_1$$ the day number within the year, and $$y_2$$ the running day number.

To calculate the calendar date from the running day number, we must first calculate the larger period ($$x_2$$, $$z_2$$), and then the smaller period ($$x_1$$, $$z_1$$).

The two example calendars then yield, for the calculation of $$x_2, x_1, z_1$$ from $$y_2$$ for the first 20 days:

$${y_2}$$ $${x_2}$$ $${r_2}$$ $${z_2=y_1}$$ $${x_1}$$ $${r_1}$$ $${z_1}$$ $${\{x_2,x_1,z_1\}}$$
0 0 4 0 0 2 0 {0, 0, 0}
1 0 9 1 0 5 1 {0, 0, 1}
2 0 14 2 1 1 0 {0, 1, 0}
3 0 19 3 1 4 1 {0, 1, 1}
4 0 24 4 2 0 0 {0, 2, 0}
5 0 29 5 2 3 1 {0, 2, 1}
6 0 34 6 2 6 2 {0, 2, 2}
7 1 2 0 0 2 0 {1, 0, 0}
8 1 7 1 0 5 1 {1, 0, 1}
9 1 12 2 1 1 0 {1, 1, 0}
10 1 17 3 1 4 1 {1, 1, 1}
11 1 22 4 2 0 0 {1, 2, 0}
12 1 27 5 2 3 1 {1, 2, 1}
13 1 32 6 2 6 2 {1, 2, 2}
14 2 0 0 0 2 0 {2, 0, 0}
15 2 5 1 0 5 1 {2, 0, 1}
16 2 10 2 1 1 0 {2, 1, 0}
17 2 15 3 1 4 1 {2, 1, 1}
18 2 20 4 2 0 0 {2, 2, 0}
19 2 25 5 2 3 1 {2, 2, 1}

Running day number $$y_2 = 16$$ corresponds to day $$z_1 = 0$$ of month $$x_1 = 1$$ of year $$x_2 = 2$$.

#### 15.9.2. Stepped combination

In this case $$x_2 = y_1$$, so

\begin{align} y_1 \| = D_1\dparen{\{x_1, z_1\}} \\ y_2 \| = D_2\dparen{\{x_2, z_2\}} = D_2\dparen{D_1\dparen{\{x_1, z_1\}, z_2}} \end{align}

and in the other direction

\begin{align} \{x_2, z_2\} \| = U_2(y_2) \\ \{x_1, z_1\} \| = U_1(x_2) \end{align}

or, with a diagram

  x₁ ┐
z₁ ┴ y₁ = x₂ ┐
z₂ ──────────┴ y₂


Here $$x_1$$ could be the year number, $$z_1$$ the month number within the year, $$z_2$$ the day number within the month, $$y_1$$ the running month number, and $$y_2$$ the running day number.

With our two example calendars we find

$${y_2}$$ $${x_2=y_1}$$ $${r_2}$$ $${z_2}$$ $${x_1}$$ $${r_1}$$ $${z_1}$$ $${\{x_1,z_1,z_2\}}$$
0 0 4 0 0 2 0 {0, 0, 0}
1 0 9 1 0 2 0 {0, 0, 1}
2 0 14 2 0 2 0 {0, 0, 2}
3 0 19 3 0 2 0 {0, 0, 3}
4 0 24 4 0 2 0 {0, 0, 4}
5 0 29 5 0 2 0 {0, 0, 5}
6 0 34 6 0 2 0 {0, 0, 6}
7 1 2 0 0 5 1 {0, 1, 0}
8 1 7 1 0 5 1 {0, 1, 1}
9 1 12 2 0 5 1 {0, 1, 2}
10 1 17 3 0 5 1 {0, 1, 3}
11 1 22 4 0 5 1 {0, 1, 4}
12 1 27 5 0 5 1 {0, 1, 5}
13 1 32 6 0 5 1 {0, 1, 6}
14 2 0 0 1 1 0 {1, 0, 0}
15 2 5 1 1 1 0 {1, 0, 1}
16 2 10 2 1 1 0 {1, 0, 2}
17 2 15 3 1 1 0 {1, 0, 3}
18 2 20 4 1 1 0 {1, 0, 4}
19 2 25 5 1 1 0 {1, 0, 5}

Running day number $$y_2 = 16$$ corresponds to day $$z_2 = 2$$ of month $$z_1 = 0$$ of year $$x_1 = 1$$.

### 15.10. Simultaneous Cycles

Most calendars have higher and lower periods, and the number of a higher period changes much less often than the number of a lower period. After the 7th day of the 3rd month follows the 8th day of the 3rd month − the month number changes less often than the day number.

Some calendars have different periods that change simultaneously. The most common calendars often have such a case, too, in the form of weekdays and days of the month. When the next day arrives, then the day number of the month changes, but the weekday changes, too. After Monday the 7th we get Tuesday the 8th − the weekday and the day number change equally fast.

We don't need the weekday to be able to point to a unique day (30 August 2011 indicates exactly one day; for that we do not need to know that that day was a Tuesday), so the weekday does not usually play a role in calendar calculations. However, there are calendars (for example the calendars of Central America) which do use simultaneous cycles to point at particular days. We look at this type of calendar below.

Suppose that a calendar uses simultaneous periods $$p_i$$ (all of them whole numbers greater than 1) for $$i$$ from 1 through $$n$$. The day number in each period begins at 0. We write a date in that calendar as $$\{x\} = \{x_1,x_2,…,x_n\}$$, where $$x_i$$ is the day number from period $$i$$. If $$x_i$$ is equal to $$p_i − 1$$, then the next day has $$x_i = 0$$ again.

For example, in a calendar with $$p_1 = 13$$ and $$p_2 = 20$$, we get after day $$\{11,8\}$$ the following days: $$\{12,9\}$$, $$\{0,10\}$$, $$\{1,11\}$$, …, $$\{9,19\}$$, $$\{10,0\}$$, $$\{11,1\}$$.

#### 15.10.1. From Running Day Number to Date

To translate running day number $$s$$ into $$\{x\}$$ we can use the following formula:

$$x_i = ⌊s + a_i⌉_{p_i} = (s + a_i) \bmod p_i \label{eq:cycli}$$

Here $$a_i$$ is the value of $$x_i$$ when $$s = 0$$. That value depends on the calendar.

Suppose that in the calendar from the previous example $$s = 0$$ corresponds to $$\{11, 8\}$$. Then $$a_1 = 11$$ and $$a_2 = 8$$, and then

\begin{align*} x_1 = \dmod{s + 11}{13} \\ x_2 = \dmod{s + 8}{20} \end{align*}

Day $$s = 11$$ then corresponds to

\begin{align*} x_1 \| = \dmod{11 + 11}{13} = \dmod{22}{13} = 9 \\ x_2 \| = \dmod{11 + 8}{20} = \dmod{19}{20} = 19 \end{align*}

so the date is $$\{9, 19\}$$.

A few more examples:

$${s}$$ $${x_1}$$ $${x_2}$$
0 11 8
1 12 9
2 0 10
3 1 11
10 8 18
11 9 19
12 10 0
13 11 1

#### 15.10.2. From Date to Running Day Number

It is a lot more difficult to go in the other direction. Then we have to find a $$s$$ for which equation \eqref{eq:cycli} is satisfied for all $$i$$, i.e.,

$$s ≡ x_i − a_i \pmod{p_i}$$

We define

$$c_i = x_i − a_i$$

We first look at the case $$n = 2$$. Then we need to solve $$s$$ from

\begin{align} s \| ≡ c_1 \pmod{p_1} \label{eq:c1} \\ s \| ≡ c_2 \pmod{p_2} \label{eq:c2} \end{align}

There are only solutions if

$$c_1 ≡ c_2 \pmod{g}$$

where

$$g = \gcd(p_1, p_2)$$

is the greatest common divisor of $$p_1$$ and $$p_2$$, so we assume that that condition is met. Then there are numbers $$n_1, n_2$$ for which

$$g = n_1 p_1 + n_2 p_2$$

and then the solutions are

$$s ≡ \dfrac{c_1 n_2 p_2 + c_2 n_1 p_1}{g} \pmod{\dfrac{p_1 p_2}{g}} \label{eq:cyclitoj}$$

The numerators of these ratios have a divisor equal to $$g$$ so these divisions always yield whole numbers.

We again use the calendar from the previous example, with $$p_1 = 13$$, $$p_2 = 20$$, $$a_1 = 11$$ and $$a_2 = 8$$. The greatest common divisor of 13 and 20 is 1, so $$g = 1$$. Now we seek a solution of

$1 = 13 n_1 + 20 n_2$

You can find $$g, n_1, n_2$$ using the Extended Euclidean Algorithm. You can also find $$n_1, n_2$$ by trying successive values of $$n_1$$ (or $$n_2$$) until you find one that fits. You've found a correct $$n_1$$ when

$\dmod{13 n_1 − 1}{20} = 0$

If you begin with $$n_1 = 1$$ and increment it in steps of 1 then you need to try at most $$n_2 − 1$$ different values.

$${n_1}$$ $${\dmod{13n_1 − 1}{20}}$$
1 12
2 5
3 18
4 11
5 4
6 17
7 10
8 3
9 16
10 9
11 2
12 15
13 8
14 1
15 14
16 7
17 0
18 13
19 6
20 19
21 12

We see that $$n_1 = 17$$ is a solution. Then

$n_2 = \dfrac{1 − 13 n_1}{20} = \dfrac{1 − 13×17}{20} = −11$

so

$1 = 17×13 − 11×20 = 221 − 220$

Then the running day numbers are

\begin{align*} s \| ≡ \dfrac{c_1n_2p_2 + c_2n_1p_1}{g} \pmod{\dfrac{p_1p_2}{g}} \\ \| ≡ \dfrac{(x_1 − 11)×(−220) + (x_2 − 8)×221}{1} \pmod{\dfrac{13×20}{1}} \\ \| ≡ −220 x_1 + 221 x_2 + 11×220 − 8×221 \\ \| ≡ −220 x_1 + 221 x_2 + 652 \pmod{260} \end{align*}

Because the preceding formula has $$\pmod{260}$$ you can add an arbitrary multiple of 260 to every term, so if you don't want negative numbers in the formula then you can rewrite it to

\begin{align*} s \| ≡ (260 − 220) x_1 + 221 x_2 + (652 − 2×260) \\ \| ≡ 40 x_1 + 221 x_2 + 132 \pmod{260} \end{align*}

For date $$\{9,19\}$$ we then find

$s ≡ 40×9 + 221×19 + 132 ≡ 4691 ≡ 11 \pmod{260}$

so day $$s = 11$$ and every 260 days earlier or later correspond to date $$\{9, 19\}$$.

Warning! Formula \eqref{eq:cyclitoj} only gives useful results for $$\{x\}$$ that really occur in the calendar. If $$g$$ is not equal to 1, then not all possible $$\{x\}$$ can occur. If you enter an $$\{x\}$$ that does not occur in the calendar, then you get a reasonable-looking result from the formula, but that result then still won't be valid.

Now we look at a calendar for which the greatest common divisor $$g$$ of the periods is not 1, with $$p_1 = 10$$, $$p_2 = 15$$, $$a_1 = a_2 = 0$$. Then

\begin{align*} x_1 = \dmod{s}{10} \\ x_2 = \dmod{s}{15} \end{align*}

A solution for

$g = n_1 p_1 + n_2 p_2$

is

$5 = −1×10 + 1×15$

so

$s ≡ \dfrac{15x_1 − 10x_2}{5} ≡ 3x_1 − 2x_2 \pmod{30}$

$${s}$$ $${x_1}$$ $${x_2}$$ $${3x_1−2x_2}$$ $${\dmod{3x_1−2x_2}{30}}$$
0 0 0 0 0
9 9 9 9 9
10 0 10 −20 10
14 4 14 −16 14
15 5 0 15 15
19 9 4 19 19
20 0 5 −10 20
29 9 14 −1 29
30 0 0 0 0

Because $$g$$ is not equal to 1, many combinations of $$x_1$$ and $$x_2$$ do not occur in this calendar. Only combinations for which $$x_1 − x_2$$ is evenly divisible by 5 occur in this calendar. For example, $$\{3, 7\}$$ does not occur. If we apply the equation for $$s$$ to that date, then we find $$s ≡ 3×3 − 2×7 ≡ −5 ≡ 25 \pmod{30}$$, but for $$s = 25$$ we find $$x_1 = \dmod{25}{10} = 5$$ and $$x_2 = \dmod{25}{15} = 10$$, so $$\{5, 10\}$$ and not $$\{3, 7\}$$. For impossible $$\{x\}$$ we still get nice-looking $$s$$ out of the formula.

#### 15.10.3. More than Two Periods

Using equation \eqref{eq:cyclitoj}, $$s ≡ c_1 \pmod{p_1}$$ and $$s ≡ c_2 \pmod{p_2}$$ lead to another equation $$s ≡ C_2 \pmod{P_2}$$ with

\begin{align} C_2 \| ≡ \dfrac{c_1n_2p_2 + c_2n_1p_1}{\gcd(p_1, p_2)} \\ P_2 \| ≡ \dfrac{p_1p_2}{\gcd(p_1, p_2)} \end{align}

That formula has the same form as the two formulas that we started with, so we can combine that formula in the same manner with $$s ≡ c_3 \pmod{p_3}$$, and so on until we've handled all $$p_i$$. We end up with a formula that again has the same form $$s ≡ C_n \pmod{P_n}$$, and that is the solution of the $$n$$ equations.

The procedure is then as follows. Given $$x_i$$, $$p_i$$, $$a_i$$ for $$i$$ from 1 through $$n$$,

1. Assign

\begin{align*} C_1 \| = x_1 − a_1 \\ P_1 \| = p_1 \end{align*}

2. For $$i$$ from 2 through $$n$$:

1. Determine $$g_i = \gcd(P_{i−1}, p_i)$$, the greatest common divisor of $$P_{i−1}$$ and $$p_i$$.

2. Find $$n_i, m_i$$ such that

$g_i = n_i P_i + m_i p_i$

3. Assign

\begin{align*} C_i \| = \dfrac{C_{i−1} m_i p_i + c_i n_i P_{i−1}}{g_i} \\ P_i \| = \dfrac{P_{i−1}p_i}{g_i} \end{align*}

3. The solution is

$$s ≡ C_n \pmod{P_n} \label{eq:cycle}$$

Let's look at a calendar with the following characteristics:

$${i}$$ $${p_i}$$ $${a_i}$$
1 4 3
2 5 1
3 6 2

You translate running day number $$s$$ to calendar date $$\{x\}$$ as follows:

\begin{align*} x_1 \| = \dmod{s + 3}{4} \\ x_2 \| = \dmod{s + 1}{5} \\ x_3 \| = \dmod{s + 2}{6} \end{align*}

In the opposite direction we find:

\begin{align*} P_1 \| = 4 \\ C_1 \| ≡ x_1 − 3 \pmod{P_1 = 4} \\ c_2 \| = x_2 − 1 \\ g_2 \| = \gcd(4, 5) = 1 = −1×4 + 1×5 = m_2P_1 + n_2p_2 \\ P_2 \| = \dfrac{P_1p_2}{g_2} = \dfrac{4×5}{1} = 20 \\ C_2 \| ≡ \dfrac{C_1 n_2 p_2 + c_2 m_2 P_1}{g_2} \\ \| ≡ 5 (x_1 − 3) − 4 (x_2 − 1) \\ \| ≡ 5 x_1 − 4 x_2 − 11 \\ \| ≡ 5 x_1 + 16 x_2 + 9 \pmod{P_2 = 20} \\ g_3 \| = \gcd(20, 6) = 2 = 1×20 − 3×6 = m_3P_2 + n_3p_3 \\ P_3 \| = \dfrac{P_2p_3}{g_3} = \dfrac{20×6}{2} = 60 \\ C_3 \| ≡ \dfrac{C_2 n_3 p_3 + c_3 m_3 P_2}{g_3} \\ \| ≡ −9 (5 x_1 + 16 x_2 + 9) + 10 (x_3 − 2) \\ \| ≡ ―45 x_1 − 144 x_2 + 10 x_3 − 101 \\ \| ≡ 15 x_1 + 36 x_2 + 10 x_3 + 19 \pmod{P_3 = 60} \end{align*}

The solution is

$s ≡ C_3 ≡ 15x_1 + 36x_2 + 10x_3 + 19 \pmod{60}$

$${s}$$ $${x_1}$$ $${x_2}$$ $${x_3}$$ $${C_2}$$ $${C_3}$$
0 3 1 2 0 0
1 0 2 3 1 1
2 1 3 4 2 2
3 2 4 5 3 3
4 3 0 0 4 4
5 0 1 1 5 5
6 1 2 2 6 6
7 2 3 3 7 7
8 3 4 4 8 8
9 0 0 5 9 9
10 1 1 0 10 10
11 2 2 1 11 11
12 3 3 2 12 12
13 0 4 3 13 13
14 1 0 4 14 14
27 2 3 5 7 27
28 3 4 0 8 28
29 0 0 1 9 29
30 1 1 2 10 30
31 2 2 3 11 31
654 1 0 2 14 54

For example, if $$s = 654$$, then $$x_1 = \dmod{654 + 3}{4} = 1$$, $$x_2 = \dmod{654 + 1}{5} = 0$$, $$x_3 = \dmod{654 + 2}{6} = 2$$. And from $$\{x\}$$ to $$s$$ we find

$s ≡ 15×1 + 36×0 + 10×2 + 19 ≡ 54 \pmod{60}$

which is correct, because $$54 ≡ 654 \pmod{60}$$.

#### 15.10.4. To One Solution

Because the date $$\{x\}$$ is given as a collection of positions in repeating periods, there is an infinite number of days that fit that date. For the running day number $$s$$ that corresponds to date $$\{x\}$$ we find formula \eqref{eq:cycle}, which gives a solution $$\bmod P_n$$. If you have found a running day number $$s$$ that fits date $$\{x\}$$, then you can add or subtract arbitrary multiples of $$P_n$$ and then you find another $$s$$ that belongs to date $$\{x\}$$. How do we pick the right one?

To pick the right solution out of an infinite collection of solutions, we need to use additional information. One appropriate way is to pick the solution that is closest to a date $$J_0$$ chosen by us. One can interpret "closest to" in at least four different ways:

• the last one at or before $$s_0$$
• the first one at or after $$s_0$$
• the last one before $$s_0$$
• the first one after $$s_0$$

We investigate these cases one by one, for $$s ≡ C_n \pmod{P_n}$$.

##### 15.10.4.1. The last one at or before

We seek the last $$s$$ at or before $$s_0$$ that satisfies $$s ≡ C_n \pmod{P_n}$$. Then, with $$k$$ a whole number,

\begin{align} s_0 − P_n \| \lt s ≤ s_0 \\ s_0 − P_n \| \lt C_n + kP_n ≤ s_0 \\ \frac{s_0 − C_n}{P_n} − 1 \| \lt k ≤ \frac{s_0 − C_n}{P_n} \end{align}

There is only one whole number $$k$$ that satisfies this inequality, and that is

$$k = \dfloorratio{s_0 − C_n}{P_n}$$

so

\begin{align} s \| = C_n + P_n \dfloorratio{s_0 − C_n}{P_n} \notag \\ \| = C_n + P_n \dparen{\frac{s_0 − C_n}{P_n} − \mod1ratio{s_0 − C_n}{P_n}} \notag \\ \| = C_n + (s_0 − C_n) − P_n \mod1ratio{s_0 − C_n}{P_n} \notag \\ \| = s_0 − \dmod{s_0 − C_n}{P_n} \notag \\ \| = s_0 − ((s_0 − C_n) \bmod P_n) \label{eq:nearestle} \end{align}

For example, what is the last day at or before $$s_0 = 700$$ that corresponds to date $$\{1,0,2\}$$ in the calendar from the previous example?

There we found $$C_n = 15x_1 + 36x_2 + 10x_3 + 19$$ and $$P_n = 60$$, so $$C_n = 15×1 + 36×0 + 10×2 + 19 = 54$$. With formula \eqref{eq:nearestle} we then find $$s = 700 − \dmod{700 − 54}{60} = 700 − \dmod{646}{60} = 700 − 46 = 654$$ which is correct: 654 + 60 = 714 is greater than 700, so 654 is the last $$s$$ that is less than or equal to $$s_0$$ and that fits date $$\{1,0,2\}$$.

We should find $$s = 654$$ for all $$s_0$$ from 654 through 654 + 60 − 1 = 713, and we do:

$${s_0}$$ $${s_0−C_n}$$ $${\dmod{s_0−C_n}{P_n}}$$ $${s}$$
653 599 59 594
654 600 0 654
712 658 58 654
713 659 59 654
714 660 0 714

##### 15.10.4.2. The first at or after

We seek the first $$s$$ at or after $$s_0$$ that satisfies $$s ≡ C_n \pmod{P_n}$$. Then, with $$k$$ a whole number,

\begin{align} s_0 \| ≤ s \lt s_0 + P_n \\ s_0 \| ≤ C_n + kP_n \lt s_0 + P_n \\ \dfrac{s_0 − C_n}{P_n} \| ≤ k \lt \dfrac{s_0 − C_n}{P_n} + 1 \end{align}

There is only one whole number $$k$$ that satisifies this inequality, and that number is

$$k = \dceilratio{s_0 − C_n}{P_n}$$

so

\begin{align} s \| = C_n + P_n \dceilratio{s_0 − C_n}{P_n} \notag \\ \| = C_n + P_n \dparen{\dfrac{s_0 − C_n}{P_n} + \dom1ratio{s_0 − C_n}{P_n}} \notag \\ \| = C_n + (s_0 − C_n) + P_n \dom1ratio{s_0 − C_n}{P_n} \\ \| = s_0 + \ddom{s_0 − C_n}{P_n} \\ \| = s_0 + \dmod{C_n − s_0}{P_n} \\ \| = s_0 + ((C_n − s_0) \bmod P_n) \label{eq:nearestge} \end{align}

For example, what is the first day at or after $$s_0 = 700$$ that corresponds to date $$\{1,0,2\}$$ in the calendar from the previous example?

We had $$C_n = 54$$. With formula \eqref{eq:nearestge} we then find $$s = 700 + \dmod{54 − 700}{60} = 700 + \dmod{−646}{60} = 700 + 14 = 714$$ which is correct: 714 − 60 = 654 is less than 700, so 714 is the first $$s$$ that is greater than or equal to $$s_0$$ and that fits date $$\{1,0,2\}$$.

We should find $$s = 714$$ for all $$s_0$$ from 714 − 60 + 1 = 655 through 714, and we do:

$${s_0}$$ $${s_0−C_n}$$ $${\dmod{C_n−s_0}{P_n}}$$ $${s}$$
654 600 0 654
655 601 59 714
656 602 58 714
713 659 1 714
714 660 0 714
715 661 59 774

##### 15.10.4.3. The last one before

The last $$s$$ before $$s_0$$ is one $$P_n$$ before the first $$s$$ at or after $$s_0$$, so

$$s = s_0 + \dmod{C_n − s_0}{P_n} − P_n \label{eq:laatste}$$

With $$C_n = 54$$ and $$P_n = 60$$:

$${s_0}$$ $${C_n−s_0}$$ $${\dmod{C_n−s_0}{P_n}}$$ $${s}$$
654 −600 0 594
655 −601 59 654
656 −602 58 654
713 −659 1 654
714 −660 0 654
715 −661 59 714

##### 15.10.4.4. The first one after

The first $$s$$ after $$s_0$$ is one $$P_n$$ after the last $$s$$ at or before $$s_0$$, so

$$s = s_0 − \dmod{s_0 − C_n}{P_n} + P_n$$

With $$C_n = 54$$ and $$P_n = 60$$:

$${s_0}$$ $${s_0−C_n}$$ $${\dmod{s_0−C_n}{P_n}}$$ $${s}$$
653 599 59 654
654 600 0 714
656 602 2 714
713 659 59 714
714 660 0 774
715 661 1 774

### 15.11. Summary

This summary is in terms of days and months, but holds also for other units of time. We distinguish four different degrees of difficulty: from 1 to 4 the formulas get more complicated but also more capable.

1. The simplest calendar has two different month lengths, with the greatest being one greater than the smallest, and allows no shifting of the pattern of month lengths. Month 0 is always a short month, and month $$g − 1$$ (the last month before everything repeats itself) is always a long month.

2. Calendar type 2 is equal to type 1, except that shifting of the pattern of month lengths is allowed.

3. Calendar type 3 is equal to type 2, but now the difference between the month lengths can be more than one.

4. Calendar type 4 is equal to type 3, but allows more than two month lengths.

The following table summarizes the calendar formulas, and uses the following definitions:

• $$q$$ is the number of days in the shortest month. $$q$$ is a whole number greater than 0.

• $$p$$ is the average length of the infinite number of months that this calendar provides (even if in practice the calendar is used in a flat combination with another calendar so that only a limited number of months actually get used). $$p$$ is greater than zero, but is usually not a whole number.

• $$f$$, $$g$$ are the numerator and denominator from $$p = f/g$$. They are whole numbers greater than zero.

• $$h/g$$, $$h_i/g_i$$ is the fraction of the infinite number of months that has the non-basic month length (unequal to $$q$$). $$h, h_i, g_i$$ are whole numbers greater than zero.

• $$r$$, $$r_i$$ is the difference between a month length and the basic month length $$q$$. They are whole numbers greater than zero.

• $$t/g$$, $$t_i/g_i$$ indicate by how many months the pattern of month lengths should be shifted compared to the simplest case. They are a whole numbers. Only the values from 0 through $$g − 1$$ are important: value $$t + g$$ has the same effect as value $$t$$.

• $$γ_i = g/g_i$$ is a factor that is needed when not all $$g_i$$ are equal.

• $$m$$ is the running month number. It is a whole number, and can be negative, zero, or positive.

• $$σ$$ is the running day number of the beginning of month $$m$$. It is a whole number, and can be negative, zero, or positive.

• $$ξ$$ is a correction to be added to month number $$m$$ to get a better estimate for the month number. This is only relevant for calendar types 3 and 4.

• $$d$$ is the number of days since the beginning of the current month, $$d = s − σ$$.

 #     
2 3 4
$${p}$$ $${q + \dfrac{h}{g}}$$ $${q + r\dfrac{h}{g}}$$ $${q + \sum_i \dfrac{r_i h_i}{g_i}}$$
$${f}$$ $${qg + h}$$ $${qg + rh}$$ $${qg + \sum_i γ_i r_i h_i}$$
$${σ}$$ $${\dfloorratio{fm + t}{g}}$$ $${qm + r\dfloorratio{hm + t}{g}}$$ $${qm + \sum_i r_i\dfloorratio{h_i m + t_i}{g_i}}$$
$${ρ}$$ $${2r(1 − ψ) − 1 − q}$$ $${2\dparen{\sum_{r_i\gt0}r_i} − \dparen{\sum_{r_i\lt0}r_i} − q − 1 − 2\sum_i \dfrac{r_ih_i}{g_i}}$$
$${w}$$ $${gs + g − t − 1}$$ $${gs + gr − rt − 1}$$ $${gs + g\dparen{\sum_{r_i \gt 0}r_i} − \dparen{\sum_i γ_i r_i t_i} − 1}$$
$${m}$$ $${\dfloorratio{w}{f}}$$ $${\dfloorratio{w}{f}}$$ $${\dfloorratio{w}{f}}$$
$${d}$$ $${\dfloorratio{\dmod{w}{f}}{g}}$$ $${s-qm-r\dfloorratio{hm+t}{g}}$$ $${s−qm−\dparen{\sum_ir_i\dfloorratio{h_im+t_i}{g_i}}}$$
$${ξ}$$ $${\dfloorratio{d}{q+r}}$$ $${\dfloorratio{d}{q+\sum_{r_i \gt 0} r_i}}$$

Calendar type 1 is like calendar type 2 but with $$t = 0$$.

For calendar types 3 and 4, the formula for $$m$$ yields an upper boundary for the month number. The general procedure for finding the right month number is then:

Try the $$m$$ from the formula in the table. Calculate the corresponding $$σ$$ and then $$d = s − σ$$ and $$ξ$$. If $$ξ$$ is equal to 0, then you're done. Otherwise, subtract 1 from $$m$$ and try again.

If $$ρ ≤ 0$$ then you need to calculate $$ξ$$ at most once. Otherwise you may need to do it more often.

If there are more that two relevant units of time, then different calendar levels must be combined.

## 16. Derivation for Specific Calendars

Almost all calendars distinguish between three basic periods: days, months, and years. One calendar level (straight line) links two periods, so at least two calendar levels are needed to link three periods.

In the next sections we give a diagram for each calendar calculation. We explain those diagrams based on the following example:

  a ═══════════╗ ╔═ a₁ ══════════╗
(1)               ║
m ─(−1)─ m₀ ─┘ └─ m₁ ─┐        ║
d ─(−1)─ d₀ ─────────(2)─ d₁ ─[3]⇒═ s ═(+J₀)═ J


• a, m, and d are the year number, month number, and calendar number, together the calendar date, and are at the far left of the diagram.

• J is the CJDN and is at the far right of the diagram.

• (1): numbers between parentheses indicate a transformation that is explained later. The transformation usually corresponds to a calendar level, and is simple in both directions.

• [3]: numbers between square brackets are like numbers between parentheses but in this case the calculation is only simple in one direction, indicated by an arrow like .

• (+J₀), (−1): things with a + or − in front of them between parentheses indicate that that value should be added or subtracted, if you go from left to right. For example, (−1) means: subtract 1 if you go from left to right (from date to CJDN). If you go from right to left (from CJDN to date) then it is exactly the opposite, so then (−1) means that you should add 1.

• Other letters (with a subscript) indicate intermediate results. The intermediate results with names including an a (like a₁) are measured in years, those with m are measured in months, those with d, s, or J are measured in days, and those with c are measured in units of multiple years.

• The single and double lines between the symbols indicate which transformation have which input and output. The double lines indicate running quantities that can in principle have any whole number for value, such as the year number or CJDN. The single lines indicate quantities that have a very limited range of values, such as the day number within the month.

• Transformations with greater units are shown higher in the diagram than those with smaller units.

Let's look at the month $$m$$. Going from left to right, we first encounter (−1) so 1 is subtracted and yields $$m_0$$. That goes into transformation 1 together with $$a$$ which yield $$a_1$$ (measured in years) and $$m_1$$ (measured in months). $$m_1$$ and $$d_0$$ go into transformation 2 and yield $$d_1$$. That one goes into transformation 3 together with $$a_1$$ and yields $$s$$. Then $$J_0$$ is added, and we find the end result $$J$$.

You can also read the diagram from right to left. We begin with CJDN $$J$$ on the right-hand side. Going toward the left we first encounter (+J₀) so we must subtract $$J_0$$ (because we're going from right to left) and get $$s$$. That goes into transformation 3 which yields $$a_1$$ and $$d_1$$. That $$d_1$$ goes into transformation 2, yielding $$d_0$$ and $$m_1$$. $$m_1$$ and $$a_1$$ go into transformation 1 which yield $$m_0$$ and $$a$$. Then we reach (−1) so we must add 1 (because we're going from right to left) and then we find $$m$$.

In the calculations that follow we sometimes use intermediate results that aren't shown in the diagrams. We indicate them using $$α_i$$ if they are measured in years, $$μ_i$$ if they are measured in months, $$δ_i$$ if they are measured in days, and $$ε_i$$ or $$ω_i$$ if they are measured in a different unit. Those names can be used for different things in the opposite calendar directions, so $$α_1$$ in the description of how to calculate the running day number from the calendar date can refer to something different than $$α_1$$ in the description of how to calculate the calendar date from the running day number.

### 16.1. The Julian Calendar

In the Julian calendar, every three regular years of 365 days are followed by a leap year of 366 days. This period of four years contains 3×365 + 366 = 1461 days. Each period of four years has the same sequence of months with their month lengths.

All months have 30 or 31 days, except for February which has 28 or (in a leap year) 29 days. That extra-short month February is a bit of a problem; because of it, we have to deal not with two but with four different month lengths.

There are various ways to handle this problem:

1. We can regard February as the last month of the calculation year. Then March is calculation month 0 of the calculation year, and the following February is calculation month 11 of the same calculation year. With a flat combination of calendar levels between years and days and between months and days only the year/day level determines the length of the year, and we can use that to shorten the length of the last month of the year as much as we want. In the calculation year, February is that last month. Then all calendar levels are of type 2 ― which means relatively simple. Then the calculations are schematically as follows:

      a ═╗ ╔═ a₁ ══════════╗
(1)               ║
m ─┘ └─ m₁ ─┐        ║
d ─────────(2)─ d₁ ─(3)═ J


Transformation 1 converts calendar year/month into calculation year/month. Transformation 2 yields the day number within the calculation year. Transformation 3 yields the running day number.

2. We can also use a stepped combination of calendar levels, in which we calculate a running month number from the year number and the month number within the year, and then calculate the running day number from the running month number and the day number within the month. Then the length of the year isn't determined by only the calendar level involving the year, so we cannot shorten the last month of the year through that calendar level, so no need to use a calculation year. The disadvantage is that we must then go to extra trouble to make February shorter than the other months, and that can only be done using a calendar level of type 4, which is a lot more difficult when calculating the date from the running day number. The calculations are schematically as follows:

      a ══╗
m ─(1)═ m₁ ═╗
d ─────────[2]⇒═ J


Transformation 1 goes from year/month to running month number. Transformation 2 goes from running month number and day number within the month to running day number.

Calendar types 3 and 4 take (from CJDN to date) a lot more calculations than calendar types 1 and 2 do, so a method that has calendar types 1 or 2 as maximum type is more desirable in practice than a method that has calendar types 3 or 4 as maximum. So we prefer the first method above (with the flat combination) in practice.

#### 16.1.1. From Julian Date to CJDN (1)

The calculations are schematically as shown in the following diagram.

  a ═══════════╗ ╔═ a₁ ══════════╗
(1)               ║
m ─(−1)─ m₀ ─┘ └─ m₁ ─┐        ║
d ─(−1)─ d₀ ─────────(2)─ d₁ ─(3)═ s ═(+J₀)═ J


The summary of the calculation levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$
1 1 12 0 1 −2 0.08333
2 153 5 30 3 2 30.6
3 1461 4 365 1 0 365.3

1. First we shift months and days such that the first ones have number 0. January 1 then corresponds to $$m_0 = 0, d_0 = 0$$.

\begin{align} m_0 \| = m − 1 \\ d_0 \| = d − 1 \end{align}

2. Transformation 1 shifts the month number and year number such that March instead of January is the first calculation month (month $$m_1 = 0$$) of the calculation year $$a_1$$.

\begin{align} \{ α_1, m_1 \} \| = \Div(m_0 − 2, 12) \\ a_1 \| = a + α_1 \end{align}

$${a}$$ $${m}$$ $${α_1}$$ $${m_1}$$ $${a_1}$$
0 1 −1 10 −1
0 2 −1 11 −1
0 3 0 0 0
0 10 0 7 0
0 11 0 8 0
0 12 0 9 0
1 1 −1 10 0
1 2 −1 11 0
1 3 0 0 1

3. Transformation 2 calculates the day number $$d_1$$ within the calculation year from the calculation month $$m_1$$ and the day number $$d_0$$ within the calculation month:

$$d_1 = \dfloorratio{153 m_1 + 2}{5} + d_0$$

This is a calendar level of type 2, with $$f = 153, g = 5, q = 30, h = 3, t = 2$$.

$${m}$$ $${d}$$ $${m_1}$$ $${d_0}$$ $${d_1}$$ $${L}$$
1 1 10 0 306 31
1 2 10 1 307
1 31 10 30 336
2 1 11 0 337
     ? 
2 2 11 1 338
2 28 11 27 364
2 29 11 28 365
3 1 0 0 0 31
4 1 1 0 31 30
5 1 2 0 61 31
6 1 3 0 92 30
7 1 4 0 122 31
8 1 5 0 153 31
9 1 6 0 184 30
10 1 7 0 214 31
11 1 8 0 245 30
12 1 9 0 275 31
12 31 9 30 305 30

In the preceding table, $$L$$ indicates the length of the month. The length of the last calculation month (February) is shown as "?" because it is determined by the length of the year, which isn't always the same.

4. Transformation 3 calculates the running day number $$s$$ since the beginning of calculation year 0 from the calculation year $$a_1$$ and the day number $$d_1$$ within the calculation year:

$$s = \dfloorratio{1461 a_1}{4} + d_1$$

This is a calendar level of type 2, with $$f = 1461, g = 4, q = 365, h = 1, t = 0$$.

$${a_1}$$ $${s}$$ $${L}$$
0 0 365
1 365 365
2 730 365
3 1095 366
4 1461

In the preceding table, $$L$$ is the length of the year: 3 years of 365 days each, followed by a year of 366 days ― the leap year. After those 4 years the pattern repeats itself.

5. And then we add to $$s$$ the CJDN of the beginning of calculation year 0 (March 1 of Year 0), which is 1721118:

$$J = s + J_0 = s + 1721118$$

We can combine the preceding steps into

\begin{align} \{ α_1, m_1 \} \| = \Div(m ― 3, 12) \\ J \| = \dfloorratio{1461\dparen{a + α_1}}{4} + \dfloorratio{153 m_1 + 2}{5} + d + 1721117 \label{eq:jul1sum} \end{align}

For example, what CJDN corresponds to Julian date 6 July 2003? Then $$a = 2003$$, $$m = 7$$, $$d = 6$$, and thus

\begin{align*} m_0 \| = m − 1 = 7 − 1 = 6 \\ d_0 \| = d − 1 = 6 − 1 = 5 \\ \{ α_1, m_1 \} \| = \Div(m_0 − 2, 12) = \Div(6 − 2, 12) = \Div(4, 12) = \{ 0, 4 \} \\ a_1 \| = a + α_1 = 2003 + 0 = 2003 \\ d_1 \| = \dfloorratio{153 m_1 + 2}{5} + d_0 = \dfloorratio{153×4 + 2}{5} + 5 \\ \| = \dfloorratio{614}{5} + 5 = 122 + 5 = 127 \\ s \| = \dfloorratio{1461 a_1}{4} + d_1 = \dfloorratio{1461×2003}{4} + 127 \\ \| = \dfloorratio{2926383}{4} + 127 = 731595 + 127 = 731722 \\ J \| = 731722 + 1721118 = 2452840 \end{align*}

Or, with the condensed formulas:

\begin{align*} \{ α_1, m_1 \} \| = \Div(m ― 3, 12) = \Div(7 ― 3, 12) = \{ 0, 4 \} \\ J \| = \dfloorratio{1461\dparen{a + α_1}}{4} + \dfloorratio{153 m_1 + 2}{5} + d + 1721117 \\ \| = \dfloorratio{1461×2003}{4} + \dfloorratio{153×4 + 2}{5} + 6 + 1721117 \\ \| = 731595 + 122 + 6 + 1721117 = 2452840 \end{align*}

Some more examples:

$${a}$$ $${m}$$ $${d}$$ $${m_0}$$ $${d_0}$$ $${α_1}$$ $${m_1}$$ $${a_1}$$ $${d_1}$$ $${s}$$ $${J}$$
−1 12 31 11 30 0 9 −1 305 −61 1721057
0 1 1 0 0 −1 10 −1 306 −60 1721058
0 2 28 1 27 −1 11 −1 364 −2 1721116
0 2 29 1 28 −1 11 −1 365 −1 1721117
0 3 1 2 0 0 0 0 0 0 1721118
1999 12 31 11 30 0 9 1999 305 730439 2451557
2000 1 1 0 0 −1 10 1999 306 730440 2451558
2000 2 28 1 27 −1 11 1999 364 730498 2451616
2000 2 29 1 28 −1 11 1999 365 730499 2451617
2000 3 1 2 0 0 0 2000 0 730500 2451618
2003 7 6 6 5 0 4 2003 127 731722 2452840

Which limit is there on these calculations if we work with numbers with a fixed memory size, so that every initial, intermediate, and final result must not exceed (in positive or negative direction) $$w$$? For how many years into the past and the future can we expect these calculations to provide correct results?

The general limit on all input values is that they cannot exceed (in positive or negative direction) $$w$$. In practice this is only of interest for running quantities such as the year number $$a$$ and the CJDN $$J$$, because the other quantities (such as the day number within the month or the year number within the century) are already limited in size by nature.

Transformation 3 yields a limit of $$w/1461$$ years, which corresponds to about $$w/4$$ days. For 32-bit numbers (with $$w = 2^{31} − 1 = 2147483647$$) this is roughly 1.5 million years. A more detailed search (as described in Sec. 15.2.3) yields that for 32-bit numbers the above calculations are usable from CJDN −535'149'630 through CJDN 538'592'029, which means from somehwere in year −1'469'872 through somewhere in year 1'469'872.

If you want to have a higher limit for this calendar then you can calculate using 64-bit numbers, or (following Sec. 15.2) replace the formula for $$s$$ (in transformation 3) by

$$s = 365 a_1 + \dfloorratio{a_1}{4} + d_1$$

That detour yields a limit of roughly $$w$$ days, and larger isn't possible. For 32-bit numbers this corresponds to about 5.9 million years.

Here are some examples (with $$d_1 = 0$$) of the original calculation and the calculation with the detour to increase the limit.

$${a}$$ $${1461 a}$$ $${1461 \dfrac{a}{w}}$$ $${s}$$ $${365 a}$$ $${\dfrac{365 a}{w}}$$ $${s}$$
−5880000 −8590680000 −4.00 −2147670000 −2146200000 −1.00 −2147670000
−1500000 −2191500000 −1.02 −547875000 −547500000 −0.25 −547875000
−1 −1461 −6.8 × 10−7 −366 −365 −1.7 × 10−7 −366
0 0 0 0 0 0 0
1 1461 6.8 × 10−7 365 365 1.7 × 10−7 365
1999 2920539 1.4 × 10−3 730134 729635 3.4 × 10−4 730134
2000 2922000 1.4 × 10−3 730500 730000 3.4 × 10−4 730500
2003 2926383 1.4 × 10−3 731595 731095 3.4 × 10−4 731595
2004 2927844 1.4 × 10−3 731961 731460 3.4 × 10−4 731961
1000000 1461000000 0.68 365250000 365000000 0.17 365250000
1500000 2191500000 1.02 547875000 547500000 0.25 547875000
5000000 7305000000 3.40 1826250000 1825000000 0.85 1826250000
5880000 8590680000 4.00 2147670000 2146200000 1.00 2147670000

#### 16.1.2. From CJDN to Julian Date (1)

We run through the opposite procedure from the one described above, with the same calendar levels as above.

  a ═══════════╗ ╔═ a₁ ══════════╗
(1)               ║
m ─(−1)─ m₀ ─┘ └─ m₁ ─┐        ║
d ─(−1)─ d₀ ─────────(2)─ d₁ ─(3)═ s ═(+J₀)═ J


The summary of the calculation levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$
1 1 12 0 1 −2 0.08333
2 153 5 30 3 2 30.6
3 1461 4 365 1 0 365.3

1. First we calculate the running day number $$s$$ by subtracting from the CJDN $$J$$ of the date of interest the CJDN of the start of calculation year 0.

$$s = J − J_0 = J − 1721118$$

2. Transformation 3 calculates from the running day number $$s$$ the calculation year $$a_1$$ and the day number $$d_1$$ within the calculation year.

\begin{align} \{ a_1, ε_1 \} \| = \Div(4 s + 3, 1461) \\ d_1 \| = \dfloorratio{ε_1}{4} \end{align}

3. Transformation 2 calculates calculation month $$m_1$$ and day number $$d_0$$ within the calculation month from day number $$d_1$$ within the calculation year.

\begin{align} \{ m_1, ε_2 \} \| = \Div(5 d_1 + 2, 153) \\ d_0 \| = \dfloorratio{ε_2}{5} \end{align}

4. Transformation 1 shifts the month number and year number such that January and not March is month 0.

\begin{align} \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) \\ a \| = a_1 + α_1 \end{align}

5. And finally we shift the month and day numbers such that they begin at 1 instead of 0.

\begin{align} m \| = m_0 + 1 \\ d \| = d_0 + 1 \end{align}

We can condense this a bit:

\begin{align} \{ a_1, ε_1 \} \| = \Div(4 J − 6884469, 1461) \\ \{ m_1, ε_2 \} \| = \Div\dparen{5\dfloorratio{ε_1}{4} + 2, 153} \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) \\ a \| = a_1 + α_1 \\ m \| = m_0 + 1 \\ d \| = \dfloorratio{ε_2}{5} + 1 \end{align}

For example, which Julian Date corresponds to Julian Day number 2452840? Then $$J = 2452840$$ so

\begin{align*} s \| = J − J_0 = 2452840 − 1721118 = 731722 \\ \{ a_1, ε_1 \} \| = \Div(4 s + 3, 1461) \\ \| = \Div(4×731722 + 3, 1461) = \Div(2926891, 1461) = \{2003, 508\} \\ d_1 \| = \dfloorratio{ε_1}{4} = \dfloorratio{508}{4} = 127 \\ \{ m_1, ε_2 \} \| = \Div(5 d_1 + 2, 153) \\ \| = \Div(5×127 + 2, 153) = \Div(637, 153) = \{4, 25\} \\ d_0 \| = \dfloorratio{ε_2}{5} = \dfloorratio{25}{5} = 5 \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) = \Div(4 + 2, 12) = \{ 0, 6 \} \\ a \| = a_1 + α_1 = 2003 − 0 = 2003 \\ m \| = m_0 + 1 = 6 + 1 = 7 \\ d \| = d_0 + 1 = 5 + 1 = 6 \end{align*}

The date is July 6th, 2003.

Or, in the condensed manner:

\begin{align*} \{ a_1, ε_1 \} \| = \Div(4 J − 6884469, 1461) = \Div(4×2452840 − 6884469, 1461) \\ \| = \Div(2926891, 1461) = \{2003, 508\} \\ \{ m_1, ε_2 \} \| = \Div\dparen{5\dfloorratio{ε_1}{4} + 2, 153} = \Div\dparen{5\dfloorratio{508}{4} + 2, 153} \\ \| = \Div(5×127 + 2, 153) = \Div(637, 153) = \{4, 25\} \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) = \Div(4 + 2, 12) = \Div(6, 12) = \{0, 6\} \\ a \| = a_1 + α_1 = 2003 + 0 = 2003 \\ m \| = m_0 + 1 = 6 + 1 = 7 \\ d \| = \dfloorratio{ε_2}{5} + 1 = \dfloorratio{25}{5} + 1 = 5 + 1 = 6 \end{align*}

A few more examples:

$${J}$$ $${s}$$ $${a_1}$$ $${ε_1}$$ $${d_1}$$ $${m_1}$$ $${ε_2}$$ $${d_0}$$ $${α_1}$$ $${m_0}$$ $${a}$$ $${m}$$ $${d}$$
−1 −1721119 −4713 1220 305 9 150 30 0 11 −4713 12 31
0 −1721118 −4713 1224 306 10 2 0 1 0 −4712 1 1
1721057 −61 −1 1220 305 9 150 30 0 11 −1 12 31
1721058 −60 −1 1224 306 10 2 0 1 0 0 1 1
1721117 −1 −1 1460 365 11 144 28 1 1 0 2 29
1721118 0 0 3 0 0 2 0 0 2 0 3 1
2451557 730439 1999 1220 305 9 150 30 0 11 1999 12 31
2451558 730440 1999 1224 306 10 2 0 1 0 2000 1 1
2451616 730498 1999 1456 364 11 139 27 1 1 2000 2 28
2451617 730499 1999 1460 365 11 144 28 1 1 2000 2 29
2451618 730500 2000 3 0 0 2 0 0 2 2000 3 1
2452840 731722 2003 508 127 4 25 5 0 6 2003 7 6

Transformation 3 has a limit of $$w/4$$ days. For 32-bit numbers that corresponds to about 1.5 million years.

If you want a higher limit then you can calculate using 64-bit numbers, or (following Sec. 15.2) replace the equation for $$α_1$$ and $$ε_1$$ (for transformation 3) by

\begin{eqnarray} \{ ω_2, δ_1 \} \| = \| \Div(s, 1461) \\ \{ α_2, ε_1 \} \| = \| \Div(4 δ_1 + 3, 1461) \\ α_1 \| = \| 4 ω_2 + α_2 \end{eqnarray}

Then the limit becomes $$w$$ days, and higher is not possible. For 32-bit numbers this corresponds to about 5.9 million years.

Here are some examples of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${s}$$ $${4 s + 3}$$ $${\dfrac{4s + 3}{w}}$$ $${α_1}$$ $${ε_1}$$ $${ω_2}$$ $${δ_1}$$ $${4 δ_1 + 3}$$ $${α_2}$$ $${ε_1}$$ $${α_1}$$
−2140000000 −8559999997 −3.99 −5859001 464 −1464751 1211 4847 3 464 −5859001
−530000000 −2119999997 −0.99 −1451061 124 −362766 1126 4507 3 124 −1451061
0 3 1.4 × 10−9 0 3 0 0 3 0 3 0
530000000 2120000003 0.99 1451060 1343 362765 335 1343 0 1343 1451060
2140000000 8560000003 3.99 5859000 1003 1464750 250 1003 0 1003 5859000

#### 16.1.3. From Julian Date to CJDN (2)

Now we use the stepped combination of calendar levels. The calculations are schematically as follows:

  a ═════════════╗
m ──(−1)─ m₀ ─(1)═ m₁ ═╗
d ──(−1)─ d₀ ─────────[2]⇒ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${r_i}$$ $${h_i}$$ $${t_i}$$ $${g_i}$$ $${γ_i}$$ $${p}$$
1 1 12 0 1 −2 0.08333
2.1 1461 48 30 1 7 5 12 4 30.4375
2.2 −2 1 10 12 4
2.3 1 1 46 48 1

1. First we shift months and days such that the first ones have number 0. January 1 then corresponds to $$m_0 = 0, d_0 = 0$$.

\begin{align} m_0 \| = m − 1 \\ d_0 \| = d − 1 \end{align}

2. Transformation 1 calculates the running month number $$m_1$$ from the year $$a$$ and the month number $$m_0$$ within the year. The formula is very simple:

$$m_1 = 12a + m_0$$

This is a calendar level of type 1, with $$f = 12, g = 0, q = 12, h = 0, t = 0$$. Because $$t = 0$$ it is also a calendar level of type 1.

3. Transformation 2 must calculate the running day number $$s$$ from the running month number $$m_1$$. Of the 12 months of a year, 7 are long, with 31 days each, so we need a formula like $$\dfloor{(7(m_1 + a))/12}$$ (which repeats itself every 12 months), but what should be the value of $$a$$?

With $$a = 0$$ we get the values

$${m_1}$$ $${•7m_1}$$
 ∆ 
0 0 0
1 0 1
2 1 0
3 1 1
4 2 0
5 2 1
6 3 1
7 4 0
8 4 1
9 5 0
10 5 1
11 6 1
12 7

where $$•7 m_1$$ means "the result of the calculation involving $$7 m_1$$".

Each time that the value increases by one, the preceding month was a long one, so these values mean that the sequence of short (S) and long (L) months was: S L S L S L L S L S L L, but we're searching for L S L S L S L L S L S L, because July and August (the 7th and 8th months) are both long. We get that if we shift the pattern by −1 month (one to the left), so $$a = −1$$. Then $$t = \dmod{f a}{g} = \dmod{−7}{12} = 5$$, so we find $$\dfloor{(7 m_1 + 5)/12}$$.

Then all months are good, except for February ($$m_1 = 1$$), because that month gets 30 days but should have only 28 days in a regular year or 29 days in a leap year. We subtract 2 days from every February using the formula $$−2\dfloor{(m_1 + 10)/12}$$. We add 1 day back in for the first of every four years by using $$\dfloor{(m_1 + 46)/48}$$. All in all we find

$$s = 30 m_1 + \dfloorratio{7 m_1 + 5}{12} − 2\dfloorratio{m_1 + 10}{12} + \dfloorratio{m_1 + 46}{48} + d_0$$

This is calendar type 4 with

$$q = 30$$, $$g = 48$$, $$\{ r_1, h_1, t_1, g_1 \} = \{ 1, 7, 5, 12 \}$$, $$\{r_2, h_2, t_2, g_2 \} = \{ −2, 1, 10, 12 \}$$, $$\{ r_3, h_3, t_3, g_3 \} = \{ 1, 1, 46, 48\}$$.

4. And then we add the CJDN of the beginning of the year 0 (January 1st, Year 0), and that is 1721058.

$$J = s + J_0 = s + 1721058$$

This condenses to

\begin{align} m_1 \| = 12 a + m − 1 \\ J \| = 30 m_1 + \dfloorratio{7 m_1 + 5}{12} − 2\dfloorratio{m_1 + 10}{12} + \dfloorratio{m_1 + 46}{48} \notag \\ \| + d + 1721057 \end{align}

For example, what CJDN corresponds to Julian date July 6th, 2003? Then $$a = 2003$$, $$m = 7$$, $$d = 6$$, so

\begin{align*} m_0 \| = m − 1 = 6 \\ d_0 \| = d − 1 = 5 \\ m_1 \| = 12 a + m_0 = 12×2003 + 6 = 24042 \\ s \| = 30 m_1 + \dfloorratio{7 m_1 + 5}{12} − 2\dfloorratio{m_1 + 10}{12} + \dfloorratio{m_1 + 46}{48} + d_0 \\ \| = 30×24042 + \dfloorratio{7×24042 + 5}{12} − 2×\dfloorratio{24042 + 10}{12} \\ \| + \dfloorratio{24042 + 46}{48} + 5 \\ \| = 721260 + \dfloorratio{168299}{12} − 2×\dfloorratio{24052}{12} + \dfloorratio{24088}{48} + 5 \\ \| = 721260 + 14024 − 2×2004 + 501 + 5 = 731782 \\ J \| = s + J_0 = 731782 + 1721058 = 2452840 \end{align*}

Or, in the condensed manner:

\begin{align*} m_1 \| = 12 a + m − 1 = 12×2003 + 7 − 1 = 24042 \\ J \| = 30 m_1 + \dfloorratio{7 m_1 + 5}{12} − 2\dfloorratio{m_1 + 10}{12} + \dfloorratio{m_1 + 46}{48} + d + 1721057 \\ \| = 30×24042 + \dfloorratio{7×24042 + 5}{12} − 2\dfloorratio{24042 + 10}{12} \\ \| + \dfloorratio{24042 + 46}{48} + 6 + 1721057 \\ \| = 721260 + \dfloorratio{168299}{12} − 2\dfloorratio{24052}{12} \\ \| + \dfloorratio{24088}{48} + 1721063 \\ \| = 721260 + 14024 − 2×2004 + 501 + 1721063 = 2452840 \end{align*}

A few more examples:

$${a}$$ $${m}$$ $${d}$$ $${m_0}$$ $${d_0}$$ $${m_1}$$ $${•7m_1}$$ $${•m_1/12}$$ $${•m_1/46}$$ $${s}$$ $${J}$$
−1 12 31 11 30 −1 −1 0 0 −1 1721057
0 1 1 0 0 0 0 0 0 0 1721058
0 12 31 11 30 11 6 1 1 365 1721423
1 1 1 0 0 12 7 1 1 366 1721424
2003 2 28 1 27 24037 14022 2003 501 731654 2452712
2003 3 1 2 0 24038 14022 2004 501 731655 2452713
2003 7 6 6 5 24042 14024 2004 501 731782 2452840
2003 12 31 11 30 24047 14027 2004 501 731960 2453018
2004 1 1 0 0 24048 14028 2004 501 731961 2453019
2004 2 28 1 27 24049 14029 2004 501 732019 2453077
2004 2 29 1 28 24049 14029 2004 501 732020 2453078
2004 3 1 2 0 24050 14029 2005 502 732021 2453079

The limit on transformation 1 is $$w/12$$ Julian years, which corresponds to about $$30.4 w$$ days. The limit on transformation 2 is roughly $$w$$ days. That is the smallest limit, so is the combined limit of all transformations. A larger combined limit is not possible. For 32-bit numbers that limit corresponds to about 5.9 million years.

#### 16.1.4. From Julian Day Number to Julian Date (2)

The calculations are schematically as follows:

  a ════════════╗
m ─(−1)─ m₀ ─(1)═ m₁ ═╗
d ─(−1)─ d₀ ─────────[2]⇒ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${r_i}$$ $${h_i}$$ $${t_i}$$ $${g_i}$$ $${γ_i}$$ $${p}$$
1 1 12 0 1 −2 0.08333
2.1 1461 48 30 1 7 5 12 4 30.4375
2.2 −2 1 10 12 4
2.3 1 1 46 48 1

We run through the above procedure in the opposite direction. First we calculate the running day number $$s$$ by subtracting the CJDN $$J_0$$ of the beginning of year 0 from the CJDN $$J$$ of the sought calendar date:

$$s = J − J_0 = J − 1721058$$

Transformation 2 produces the running month number $$m_1$$ and the day number $$d_0$$ within the month from the running day number $$s$$.

We have

\begin{align} μ_1 \| = \dfloorratio{gs + g\dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_i γ_i r_i t_i} − 1}{f} \notag \\ \| = \dfloorratio{48 s + 48×2 − (4×1×5 + 4×−2×10 + 1×1×46) − 1}{1461} \notag \\ \| = \dfloorratio{48 s + 109}{1461} \notag \\ δ_1 \| = s − 30 μ_1 − \dfloorratio{7 μ_1 + 5}{12} + 2\dfloorratio{μ_1 + 10}{12} − \dfloorratio{μ_1 + 46}{48} \end{align}

Because $$ρ ≤ 0$$ we can use the procedure with the fixed steps. Then

\begin{align} m_1 \| = μ_1 + \dfloorratio{δ_1}{32} \\ d_0 \| = s − 30 m_1 − \dfloorratio{7 m_1 + 5}{12} + 2\dfloorratio{m_1 + 10}{12} − \dfloorratio{m_1 + 46}{48} \end{align}

Transformation 1 goes from running month number $$m_1$$ to year number $$a$$ and month number $$m_0$$ within the year. This is a calendar level of type 1.

$$\{ a, m_0 \} = \Div(m_1, 12)$$

And finally we shift the month and day numbers such that they begin at 1 instead of 0.

\begin{align} m \| = m_0 + 1 \\ d \| = d_0 + 1 \end{align}

For example, what Julian Date corresponds to CJDN 2452840? Then $$J = 2452840$$, so

\begin{align*} s \| = 2452840 − 1721058 = 731782 \\ μ_1 \| = \dfloorratio{48×731782 + 109}{1461} \\ \| = \dfloorratio{35125645}{1461} = 24042 \\ δ_1 \| = 731782 − 30×24042 − \dfloorratio{7×24042 + 5}{12} \\ \| + 2×\dfloorratio{24042 + 10}{12} − \dfloorratio{24042 + 46}{48} \\ \| = 731782 − 721260 − \dfloorratio{168299}{12} + 2×\dfloorratio{24052}{12} − \dfloorratio{24088}{48} \\ \| = 10522 − 14024 + 2×2004 − 501 = 5 \\ m_1 \| = 24042 + \dfloorratio{5}{32} = 24042 \\ d_0 \| = 5 \\ \{ a, m_0 \} \| = \Div(24042, 12) = \{ 2003, 6 \} \\ m \| = 6 + 1 = 7 \\ d \| = 5 + 1 = 6 \end{align*}

so the date is July 6th, 2003.

A few more examples:

$${J}$$ $${s}$$ $${μ_1}$$ $${δ_1}$$ $${m_1}$$ $${d_0}$$ $${m_0}$$ $${a}$$ $${m}$$ $${d}$$
1721057 −1 0 −1 −1 30 11 −1 12 31
1721058 0 0 0 0 0 0 0 1 1
1721423 365 12 −1 11 30 11 0 12 31
1721424 366 12 0 12 0 0 1 1 1
2452712 731654 24037 27 24037 27 1 2003 2 28
2452713 731655 24038 0 24038 0 2 2003 3 1
2452840 731782 24042 5 24042 5 6 2003 7 6
2453018 731960 24048 −1 24047 30 11 2003 12 31
2453019 731961 24048 0 24048 0 0 2004 1 1
2453077 732019 24049 27 24049 27 1 2004 2 28
2453078 732020 24050 −1 24049 28 1 2004 2 29
2453079 732021 24050 0 24050 0 2 2004 3 1

Transformation 2 yields a limit of $$w/48$$ days. Transformation 1 does not reduce that limit because it has $$f = 1$$. The combined limit is therefore $$w/48$$ days, which corresponds to about 122 thousand years.

If you want a higher limit then you can calculate using 64-bit numbers, or replace the formula for $$μ_1$$ (for transformation 2) with

\begin{align} \{ ω_1, δ_2 \} \| = \Div(s, 1461) \\ μ_2 \| = \dfloorratio{48 δ_2 + 109}{1461} \\ μ_1 \| = 48 ω_1 + μ_2 \end{align}

Then the limit becomes $$w$$ days, and a higher limit is not possible. For 32-bit numbers this corresponds to about 5.9 million years.

Here are some examples of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$. Abbreviations:

\begin{align*} ω_3 \| = 48 s + 109 \\ ω_4 \| = 48 δ_2 + 109 \end{align*}

$${s}$$ $${ω_3}$$ $${\dfrac{ω_3}{w}}$$ $${μ_1}$$ $${ω_1}$$ $${δ_2}$$ $${ω_4}$$ $${μ_2}$$ $${μ_1}$$
−2140000000 −102719999891 −47.83 −70308009 −1464751 1211 58237 39 −70308009
−44000000 −2111999891 −0.98 −1445586 −30117 937 45085 30 −1445586
44000000 2112000109 0.98 1445585 30116 524 25261 17 1445585
2140000000 102720000109 47.83 70308008 1464750 250 12109 8 70308008

### 16.2. The GregorianCalendar

The Gregorian calendar is equal to the Julian calendar, except for the rules that say when the month of February has 29 days instead of 28 days. In the Julian calendar, February has 29 days in every fourth year, when the year number is evenly divisible by 4. In the Gregorian calendar the same rule holds, except that February has 28 days when the year number is evenly divisible by 100, except if the year number is evenly divisible by 400, when February has 29 days after all.

There are various ways to handle this:

1. We can use a flat combination of calendar levels. The calculations are schematically as follows:

                   ╔══ c₁ ══════════╗
a ═┐ ┌═ a₁ ═(2)─ a₂ ─┐        ║
(1)               │        ║
m ─┘ └─ m₁ ─┐        │        ║
d ─────────(3)─ d₁ ─(4)─ d₂ ─(5)═ J


Transformation 1 converts calendar year/month into calculation year/month, as for the Julian Calendar. Transformation 2 splits the running calculation year into a running calculation century and the calculation year within the calculation century. Transformation 3 yields the day number within the calculation year from the calculation month within the calculation year and the day number within the month. Transformation 4 yields the day number within the calculation century from the calculation year within the calculation century and the day number within the calculation year. Transformation 5 yields the running day number from the running calculation century and the day number within the calculation century.

2. We can make do with just two calendar levels combined in the flat manner if we use calendar type 4 for the upper level, with more than two different month lengths. Then the calculations are schematically as follows:

      a ═╗ ╔═ a₁ ══════════╗
(1)               ║
m ─┘ └─ m₁ ─┐        ║
d ─────────(2)─ d₁ ─[3]⇒ J


Transformation 1 converts the calendar year/month to calculation year/month. Transformation 2 yields the day number within the calculation year from the calculation month within the calculation year and the day number within the month. Transformation 3 yields the running day number from the running calculation year number and the day number within the calculation century.

3. Or we can use a stepped combination.

      a ══╗
m ─(1)═ m₁ ═╗
d ─────────[2]⇒ J


Transformation 1 yields the running month number from the year and the month number within the year. Transformation 2 yields the running day number from the running month number and the day number within the month.

The first method has calendar type 2 as its highest so it is perferred over the other two methods which have calendar type 4 as their highest.

#### 16.2.1. From Gregorian Date to CJDN (1)

We can use a flat combination of calendar levels. To convert Gregorian years into days with a single calendar level, the leap values have to return after every $$\dfloor{Q}$$ or $$\dceil{Q}$$ years (for a well-chosen $$Q$$; see equation \eqref{eq:Q}). Unfortunately, the leap year rules of the Gregorian Calendar do not meet that demand, because they mean that the time between two leap years is sometimes 4 years and sometimes 8 years.

The following $$p$$ might be considered:

• 146097 days in 400 years → $$p = f/g = 146097/400$$. This yields 85 sequences of a leap year every 4 years, but also 12 sequences of a leap year every 5 years. That does not fit the Gregorian Calendar, so this straight line is not useful for calculating the Gregorian Calendar.

• 146097 days in 100 periods of 4 years → $$p = f/g = 146097/100$$. This yields two sequences of 33 periods (of 4 years) with one fewer leap day at the end (1460 days instead of 1461 days), and one sequence of 34 periods. The Gregorian Calendar has two sequences of 25 periods (of 4 years) with one fewer leap day at the end, and then a sequence of 50 periods with one fewer leap day at the end. This one is not suitable, either.

• 36524 days in 100 years → $$p = f/g = 36524/100$$. This yields 20 sequences of a leap year every 4 years, but also 4 sequences of a leap year every 5 years. This one is not suitable.

• 146097 days in 4 periods of 100 years → $$p = f/g = 146097/4$$. This yields 3 sequences of 36524 days and 1 sequence of 36525 days, and that fits the Gregorian Calendar.

• 36525 days in 100 years → $$p = f/g = 36525/100$$. This yields 25 sequences with a leap year every 4 years. That fits, except that we sometimes need to stop already after 36524 days.

We can now use the 146097/4 line to find the 100-year periods, and then use the 36525/100 line to find the years within the 100-year period, and finally (just like for the Julian Calendar) use the 153/5 line to find the months within the year. 1 March of year 0 in the Gregorian Calendar corresponds to $$J_0 = 1721120$$. The calculations are schematically as follows:

                         ╔══ c₁ ═══════════╗
a ═══════════╗ ╔═ a₁ ═(2)─ a₂ ──┐        ║
(1)                │        ║
m ─(−1)─ m₀ ─┘ └─ m₁ ──┐        │        ║
d ─(−1)─ d₀ ──────────(3)─ d₁ ─(4)─ d₂ ─(5)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$
1 1 12 0 1 −2 0.083333
2 100 1 100 0 0 100
3 153 5 30 3 2 30.6
4 36525 100 365 25 0 365.25
5 146097 4 36524 1 0 36524.25

The steps to get from the Gregorian calendar to the CJDN are now:

1. First we shift months and days such that the first ones have number 0. January 1 then corresponds to $$m_0 = 0, d_0 = 0$$.

\begin{align} m_0 \| = m − 1 \\ d_0 \| = d − 1 \end{align}

2. Transformation 1 shifts the month number and year number such that March instead of January is the first calculation month (month $$m_1 = 0$$) of the calculation year $$a_1$$, just like for the Julian calendar (16.1.1).

\begin{align} \{ α_1, m_1 \} \| = \Div(m_0 − 2, 12) \\ a_1 \| = a + α_1 \end{align}

3. Transformation 2 calculates the calculation century number $$c_1$$ and year number $$a_1$$ within the calculation century from the calculation year number $$a_1$$.

$$\{ c_1, a_2 \} = \Div(a_1, 100)$$

4. Transformation 3 calculates the day number $$d_1$$ within the calculation year from the calculation month $$m_1$$ within the calculation year and the day number $$d_0$$ within the calculation month:

$$d_1 = \dfloorratio{153 m_1 + 2}{5} + d_0 = 30 m_1 + \dfloorratio{3 m_1 + 2}{5} + d_0$$

5. Transformation 4 calculates the day number $$d_2$$ within the calculation century from the year number $$a_2$$ within the calculation century and the day number $$d_1$$ within the calculation year.

$$d_2 = \dfloorratio{36525 a_2}{100} + d_1$$

6. Transformation 5 calculates the running day number $$s$$ from the calculation century number $$c_1$$ and the day number $$d_2$$ within the calculation century.

$$s = \dfloorratio{146097 c_1}{4} + d_2$$

7. And then we add to $$s$$ the CJDN of the beginning of calculation year 0 (March 1 of Year 0), which is 1721120:

$$J = s + J_0 = s + 1721120$$

Combined and condensed, this yields:

\begin{align} \{ α_1, m_1 \} \| = \Div(m − 3, 12) \\ \{ c_1, a_2 \} \| = \Div(a + α_1, 100) \\ J \| = \dfloorratio{146097 c_1}{4} + \dfloorratio{36525 a_2}{100} \notag \\ \| + \dfloorratio{153 m_1 + 2}{5} + d + 1721119 \end{align}

For example, which Julian Day number corresponds to Gregorian date July 6th, 2003? Then $$a = 2003$$, $$m = 7$$, $$d = 6$$ and then

\begin{align*} m_0 \| = m − 1 = 7 − 1 = 6 \\ d_0 \| = d − 1 = 6 − 1 = 5 \\ \{ α_1, m_1 \} \| = \Div(m_0 − 2, 12) = \Div(4, 12) = \{ 0, 4 \} \\ a_1 \| = a + α_1 = 2003 + 0 = 2003 \\ \{ c_1, a_2 \} \| = \Div(a_1, 100) = \Div(2003, 100) = \{ 20, 3 \} \\ d_1 \| = \dfloorratio{153m_1 + 2}{5} + d_0 = \dfloorratio{153×4 + 2}{5} + 5 \\ \| = \dfloorratio{614}{5} + 5 = 122 + 5 = 127 \\\ d_2 \| = \dfloorratio{36525a_2}{100} + d_1 = \dfloorratio{36525×3}{100} + 127 \\ \| = \dfloorratio{109575}{100} + 127 = 1095 + 127 = 1222 \\ s \| = \dfloorratio{146097c_1}{4} + d_2 = \dfloorratio{146097×20}{4} + 1222 \\ \| = \dfloorratio{2921940}{4} + 1222 = 730485 + 1222 = 731707 \\ J \| = s + 1721120 = 731707 + 1721120 = 2452827 \end{align*}

or, in the condensed manner,

\begin{align*} \{ α_1, m_1 \} \| = \Div(m − 3, 12) = \Div(7 − 3, 12) = \Div(4, 12) = \{ 0, 4 \} \\ \{ c_1, a_2 \} \| = \Div(a + α_1, 100) = \Div(2003 + 0, 100) = \Div(2003, 100) = \{ 20, 3 \} \\ J \| = \dfloorratio{146097 c_1}{4} + \dfloorratio{36525 a_2}{100} + \dfloorratio{153 m_1 + 2}{5} + d + 1721119 \\ \| = \dfloorratio{146097×20}{4} + \dfloorratio{36525×3}{100} + \dfloorratio{153×4 + 2}{5} + 6 + 1721119 \\ \| = \dfloorratio{2921940}{4} + \dfloorratio{109575}{100} + \dfloorratio{614}{5} + 1721125 \\ \| = 730485 + 1095 + 122 + 1721125 = 2452827 \end{align*}

Some more examples:

$${a}$$ $${m}$$ $${d}$$ $${m_0}$$ $${d_0}$$ $${α_1}$$ $${m_1}$$ $${a_1}$$ $${c_1}$$ $${a_2}$$ $${d_1}$$ $${d_2}$$ $${s}$$ $${J}$$
−1 12 31 11 30 0 9 −1 −1 99 305 36464 −61 1721059
0 1 1 0 0 −1 10 −1 −1 99 306 36465 −60 1721060
0 2 28 1 27 −1 11 −1 −1 99 364 36523 −2 1721118
0 2 29 1 28 −1 11 −1 −1 99 365 36524 −1 1721119
0 3 1 2 0 0 0 0 0 0 0 0 0 1721120
1900 2 28 1 27 −1 11 1899 18 99 364 36523 693959 2415079
1900 3 1 2 0 0 0 1900 19 0 0 0 693960 2415080
1999 12 31 11 30 0 9 1999 19 99 305 36464 730424 2451544
2000 1 1 0 0 −1 10 1999 19 99 306 36465 730425 2451545
2000 2 28 1 27 −1 11 1999 19 99 364 36523 730483 2451603
2000 2 29 1 28 −1 11 1999 19 99 365 36524 730484 2451604
2000 3 1 2 0 0 0 2000 20 0 0 0 730485 2451605
2003 7 6 6 5 0 4 2003 20 3 127 1222 731707 2452827

Transformation 2 doesn't reduce the limit because it has $$f = 1$$. Transformation 5 has a limit of $$w/146097$$ Gregorian centuries, which corresponds to about $$w/4$$ days. That is the combined limit. For 32-bit numbers this corresponds to about 1.5 million years. A more detailed search (as described in Sec. 15.2.3) yields that the above formulas produce the correct results for CJDN −535'148'831 through 538'592'031, which corresponds to from somewhere in Gregorian year −1'469'900 to somewhere in year 1'469'902.

If you want a higher limit then you can calculate using 64-bit numbers, or replace the formula for $$s$$ with

\begin{eqnarray} ω_1 \| = \| \dfloorratio{c_1}{4} \\ s \| = \| 36524 c_1 + ω_1 + d_2 \end{eqnarray}

That has a limit of $$w$$ days, and higher is not possible. For 32-bit numbers this corresponds to about 5.9 million years.

Here are some examples (with $$d_2 = 0$$) of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${c_1}$$ $${146097 c_1}$$ $${\dfrac{146097 c_1}{w}}$$ $${s}$$ $${\dfrac{s}{w}}$$ $${ω_1}$$ $${s}$$
−58000 −8473626000 −3.95 −2118406500 −0.99 −14500 −2118406500
−14600 −2133016200 −0.99 −533254050 −0.25 −3650 −533254050
−1 −146097 −6.8 × 10−5 −36525 −1.7 × 10−5 −1 −36525
0 0 0 0 0 0 0
1 146097 6.8 × 10−5 36524 1.7 × 10−5 0 36524
2 292194 1.4 × 10−4 73048 3.4 × 10−5 0 73048
3 438291 2.0 × 10−4 109572 5.1 × 10−5 0 109572
4 584388 2.7 × 10−4 146097 6.8 × 10−5 1 146097
14600 2133016200 0.99 533254050 0.25 3650 533254050
58000 8473626000 3.95 2118406500 0.99 14500 2118406500

#### 16.2.2. From CJDN to Gregorian Date (1)

Now we go in the opposite direction again, with the same calendar levels as before.

                         ╔══ c₁ ═══════════╗
a ═══════════╗ ╔═ a₁ ═(2)─ a₂ ──┐        ║
(1)                │        ║
m ─(−1)─ m₀ ─┘ └─ m₁ ──┐        │        ║
d ─(−1)─ d₀ ──────────(3)─ d₁ ─(4)─ d₂ ─(5)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$ $${𝔘}$$
1 12 1 12 0 2 12 180 × 106
2 100 1 100 0 0 100 21 × 106
3 153 5 30 3 2 30.6 14 × 106
4 36525 100 365 25 0 365.25 59 × 103
5 146097 4 36524 1 0 36524.25 15 × 103

1. First we subtract the CJDN that goes with running day number 0 from the CJDN to get the running day number:

$$s = J − J_0 = J − 1721120$$

2. Transformation 5 produces from the running day number $$s$$ the calculation century $$c_1$$ and the day number $$d_2$$ within the calculation century:

\begin{align} \{ c_1, ε_1 \} \| = \Div(4s + 3, 146097) \\ d_2 \| = \dfloorratio{ε_1}{4} \end{align}

3. Transformation 4 produces from the day number $$d_2$$ within the calculation century the year number $$a_2$$ within the calculation century and the day number $$d_1$$ within the calculation year.

\begin{align} \{ a_2, ε_2 \} \| = \Div(100d_2 + 99, 36525) \\ d_1 \| = \dfloorratio{ε_2}{100} \end{align}

4. Transformation 3 separates the day number $$d_1$$ within the calculation year into the calculation month number $$m_1$$ within the calculation year and the day number $$d_0$$ within the calculation month.

\begin{align} \{ m_1, ε_3 \} \| = \Div(5d_1 + 2, 153) \\ d_0 \| = \dfloorratio{ε_3}{5} \end{align}

5. Transformation 2 combines the calculation century number $$c_1$$ and the calculation year number $$a_2$$ within the calculation century into the calculation year number $$a_1$$.

$$a_1 = 100c_1 + a_2$$

6. Transformation 1 shifts the calculation month number $$m_1$$ and calculation year number $$a_1$$ such that January instead of March is the first month of the year.

\begin{align} \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) \\ a \| = a_1 + α_1 \end{align}

7. And then we shift the month number and the day numbers such that the first ones have number 1 instead of 0.

\begin{align} m \| = m_0 + 1 \\ d \| = d_0 + 1 \end{align}

This condenses a little bit, to:

\begin{align} \{ c_1, ε_1 \} \| = \Div(4J − 6884477, 146097) \\ \{ a_2, ε_2 \} \| = \Div\dparen{100\dfloorratio{ε_1}{4} + 99, 36525} \\ \{ m_1, ε_3 \} \| = \Div\dparen{5\dfloorratio{ε_2}{100} + 2, 153} \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) \\ a \| = 100c_1 + a_2 + α_1 \\ m \| = m_0 + 1 \\ d \| = \dfloorratio{ε_3}{5} + 1 \end{align}

For example, which date in the Gregorian calendar corresponds to CJDN 2452827? Then $$J = 2452827$$ and then

\begin{align*} s \| = J − 1721120 = 2452827 − 1721120 = 731707 \\ \{c_1, ε_1 \} \| = \Div(4s + 3, 146097) = \Div(4×731707 + 3, 146097) \\ \| = \Div(2926831, 146097) = \{ 20, 4891 \} \\ d_2 \| = \dfloorratio{ε_1}{4} = \dfloorratio{4891}{4} = 1222 \\ \{a_2, ε_2\} \| = \Div(100d_2 + 99, 36525) = \Div(100×1222 + 99, 36525) \\ \| = \Div(122299, 36525) = \{3, 12724\} \\ d_1 \| = \dfloorratio{ε_2}{100} = \dfloorratio{12724}{100} = 127 \\ \{m_1, ε_3 \} \| = \Div(5d_1 + 2, 153) = \Div(5×127 + 2, 153) \\ \| = \Div(637, 153) = \{4, 25\} \\ d_0 \| = \dfloorratio{ε_3}{5} = \dfloorratio{25}{5} = 5 \\ a_1 \| = 100c_1 + a_2 = 100×20 + 3 = 2003 \\ \{α_1, m_0\} \| = \Div(m_1 + 2, 12) = \Div(4 + 2, 12) = \Div(6, 12) = \{ 0, 6 \} \\ a \| = a_1 + α_1 = 2003 + 0 = 2003 \\ m \| = m_0 + 1 = 6 + 1 = 7 \\ d \| = d_0 + 1 = 5 + 1 = 6 \end{align*}

The date is July 6th, 2003.

Or, in the condensed manner,

\begin{align*} \{ c_1, ε_1 \} \| = \Div(4J − 6884477, 146097) = \Div(4×2452827 − 6884477, 146097) \\ \| = \Div(2926831, 146097) = \{20, 4891\} \\ \{ a_2, ε_2 \} \| = \Div\dparen{100\dfloorratio{ε_1}{4} + 99, 36525} = \Div\dparen{100\dfloorratio{4891}{4} + 99, 36525} \\ \| = \Div(100×1222 + 99, 36525) = \Div(122299, 36525) = \{3, 12724\} \\ \{ m_1, ε_3 \} \| = \Div\dparen{5\dfloorratio{ε_2}{100} + 2, 153} = \Div\dparen{5\dfloorratio{12724}{100} + 2, 153} \\ \| = \Div(5×127 + 2, 153) = \Div(637, 153) = \{4, 25\} \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) = \Div(4 + 2, 12) = \Div(6, 12) = \{0, 6\} \\ a \| = 100c_1 + a_2 + α_1 = 100×20 + 3 + 0 = 2003 \\ m \| = m_0 + 1 = 6 + 1 = 7 \\ d \| = \dfloorratio{ε_3}{5} + 1 = \dfloorratio{25}{5} + 1 = 5 + 1 = 6 \end{align*}

Some more examples:

$${J}$$ $${s}$$ $${c_1}$$ $${ε_1}$$ $${d_2}$$ $${a_2}$$ $${ε_2}$$ $${d_1}$$ $${m_1}$$ $${ε_3}$$ $${d_0}$$ $${a_1}$$ $${α_1}$$ $${m_0}$$ $${a}$$ $${m}$$ $${d}$$
1721059 −61 −1 145856 36464 99 30524 305 9 150 30 −1 0 11 −1 12 31
1721060 −60 −1 145860 36465 99 30624 306 10 2 0 −1 1 0 0 1 1
1721118 −2 −1 146092 36523 99 36424 364 11 139 27 −1 1 1 0 2 28
1721119 −1 −1 146096 36524 99 36524 365 11 144 28 −1 1 1 0 2 29
1721120 0 0 3 0 0 99 0 0 2 0 0 0 2 0 3 1
2415079 693959 18 146093 36523 99 36424 364 11 139 27 1899 1 1 1900 2 28
2415080 693960 19 0 0 0 99 0 0 2 0 1900 0 2 1900 3 1
2451544 730424 19 145856 36464 99 30524 305 9 150 30 1999 0 11 1999 12 31
2451545 730425 19 145860 36465 99 30624 306 10 2 0 1999 1 0 2000 1 1
2451603 730483 19 146092 36523 99 36424 364 11 139 27 1999 1 1 2000 2 28
2451604 730484 19 146096 36524 99 36524 365 11 144 28 1999 1 1 2000 2 29
2451605 730485 20 3 0 0 99 0 0 2 0 2000 0 2 2000 3 1
2452827 731707 20 4891 1222 3 12724 127 4 25 5 2003 0 6 2003 7 6

Transformation 5 yields a limit of $$w/4$$ days. Transformation 2 yields a limit of $$w/100$$ Gregorian centuries, which corresponds to about $$365.25 w$$ days. The combined limit is $$w/4$$ days, which for 32-bit numbers corresponds to about 1.5 million years.

If you want a higher limit then you can calculate using 64-bit numbers, or replace transformation 5 with

\begin{eqnarray} \{ ω_2, δ_1 \} \| = \| \Div(s, 146097) \\ \{ ω_3, ω_4 \} \| = \| \Div(4 δ_1 + 3, 146097) \\ c_1 \| = \| 4 ω_2 + ω_3 \\ d_2 \| = \| \dfloorratio{ω_4}{4} \end{eqnarray}

That has a limit of $$w$$ days, and higher is not possible. For 32-bit numbers that corresponds to about 5.9 million years.

Here are some examples of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${s}$$ $${4 s + 3}$$ $${\dfrac{4 s + 3}{w}}$$ $${c_1}$$ $${ε_1}$$ $${d_2}$$ $${ω_2}$$
530000000 2120000003 0.99 14510 132533 33133 3627
2140000000 8560000003 3.99 58591 30676 7669 14647

$${s}$$ $${δ_1}$$ $${4 δ_1 + 3}$$ $${ω_3}$$ $${ω_4}$$ $${c_1}$$ $${d_2}$$
530000000 106181 424727 2 132533 14510 33133
2140000000 117241 468967 3 30676 58591 7669

#### 16.2.3. From Gregorian Date to CJDN (2)

We can make do with just two calendar levels combined in the flat manner if we use calendar type 4 for the upper level, with multiple month lengths. Then, for that upper level,

\begin{align*} q \| = 365 \\ g \| = 400 \\ \{d_1,h_1,s_1\} \| = \{1,100,0\} \\ \{d_2,h_2,s_2\} \| = \{−1,4,0\} \\ \{d_3,h_3,s_3\} \| = \{1,1,0\} \end{align*}

The lower calendar level is the same as before, so

  a ═══════════╗ ╔═ a₁ ══════════╗
(1)               ║
m ─(−1)─ m₀ ─┘ └─ m₁ ─┐        ║
d ─(−1)─ d₀ ─────────(2)─ d₁ ─[3]⇒ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${r_i}$$ $${h_i}$$ $${t_i}$$ $${g_i}$$ $${γ_i}$$ $${p}$$
1 1 12 0 1 −2 0.083333
2 153 5 30 3 2 30.6
3.1 146097 400 365 1 1 0 4 100 365.2425
3.2 −1 1 0 100 4
3.3 1 1 0 400 1

The steps to get from the Gregorian calendar to the CJDN are now:

1. First we shift months and days such that the first ones have number 0. January 1 then corresponds to $$m_0 = 0, d_0 = 0$$.

\begin{align} m_0 \| = m − 1 \\ d_0 \| = d − 1 \end{align}

2. Transformation 1 shifts the month number and year number such that March instead of January is the first calculation month (month $$m_1 = 0$$) of the calculation year $$a_1$$, just like for the Julian calendar (16.1.1).

\begin{align} \{ α_1, m_1 \} \| = \Div(m_0 − 2, 12) \\ a_1 \| = a + α_1 \end{align}

3. Transformation 2 calculates the day number $$d_1$$ within the calculation year from the calculation month $$m_1$$ and the day number $$d_0$$ within the calculation month:

$$d_1 = \dfloorratio{153 m_1 + 2}{5} + d_0 = 30 m_1 + \dfloorratio{3 m_1 + 2}{5} + d_0$$

4. Transformation 3 calculates the running day number $$s$$ from the year number $$a_1$$ and the day number $$d_1$$ within the calculation year.

$$s = 365 a_1 + \dfloorratio{a_1}{4} − \dfloorratio{a_1}{100} + \dfloorratio{a_1}{400} + d_1$$

5. And then we add to $$s$$ the CJDN of the beginning of calculation year 0 (March 1 of Year 0), which is 1721120:

$$J = s + J_0 = s + 1721120$$

This condenses to

\begin{align} \{ α_1, m_1 \} \| = \Div(m − 3, 12) \\ a_1 \| = a + α_1 \\ J \| = 365 a_1 + \dfloorratio{a_1}{4} − \dfloorratio{a_1}{100} + \dfloorratio{a_1}{400} \notag \\ \| + \dfloorratio{153 m_1 + 2}{5} + d + 1721119 \end{align}

For example, which CJDN corresponds to Gregorian date July 6th, 2003? Then $$a = 2003$$, $$m = 7$$, $$d = 6$$, so

\begin{align*} m_0 \| = m − 1 = 7 − 1 = 6 \\ d_0 \| = d − 1 = 6 − 1 = 5 \\ \{α_1, m_1\} \| = \Div(m_0 − 2, 12) = \Div(6 − 2, 12) = \Div(4, 12) = \{0, 4\} \\ a_1 \| = a + α_1 = 2003 + 0 = 2003 \\ d_1 \| = \dfloorratio{153m_1 + 2}{5} + d_0 = \dfloorratio{153×4 + 2}{5} + 5 = \dfloorratio{614}{5} + 5 = 122 + 5 = 127 \\ s \| = 365a_1 + \dfloorratio{a_1}{4} − \dfloorratio{a_1}{100} + \dfloorratio{a_1}{400} + d_1 \\ \| = 365×2003 + \dfloorratio{2003}{4} − \dfloorratio{2003}{100} + \dfloorratio{2003}{400} + 127 \\ \| = 731095 + 500 − 20 + 5 + 127 = 731707 \\ J \| = 731707 + 1721120 = 2452827 \end{align*}

Or, in the condensed manner:

\begin{align*} \{ α_1, m_1 \} \| = \Div(m ― 3, 12) = \Div(7 ― 3, 12) = \Div(4, 12) = \{ 0, 4 \} \\ a_1 \| = a + α_1 = 2003 + 0 = 2003 \\ A \| = 365a_1 + \dfloorratio{a_1}{4} − \dfloorratio{a_1}{100} + \dfloorratio{a_1}{400} \\ \| + \dfloorratio{153m_1 + 2}{5} + d + 1721119 \\ \| = 365×2003 + \dfloorratio{2003}{4} − \dfloorratio{2003}{100} + \dfloorratio{2003}{400} \\ \| + \dfloorratio{153×4 + 2}{5} + 6 + 1721119 \\ \| = 731095 + 500 − 20 + 5 + \dfloorratio{614}{5} + 1721125 \\ \| = 2452705 + 122 = 2452827 \end{align*}

Some more examples:

$${a}$$ $${m}$$ $${d}$$ $${m_0}$$ $${d_0}$$ $${α_1}$$ $${m_1}$$ $${a_1}$$ $${d_1}$$ $${s}$$ $${J}$$
−1 12 31 11 30 0 9 −1 305 −61 1721059
0 1 1 0 0 −1 10 −1 306 −60 1721060
0 2 28 1 27 −1 11 −1 364 −2 1721118
0 2 29 1 28 −1 11 −1 365 −1 1721119
0 3 1 2 0 0 0 0 0 0 1721120
1900 2 28 1 27 −1 11 1899 364 693959 2415079
1900 3 1 2 0 0 0 1900 0 693960 2415080
1999 12 31 11 30 0 9 1999 305 730424 2451544
2000 1 1 0 0 −1 10 1999 306 730425 2451545
2000 2 28 1 27 −1 11 1999 364 730483 2451603
2000 2 29 1 28 −1 11 1999 365 730484 2451604
2000 3 1 2 0 0 0 2000 0 730485 2451605
2003 7 6 6 5 0 4 2003 127 731707 2452827

Transformation 3 has a limit of about $$w/365.2425$$ Gregorian years, which corresponds to $$w$$ days, and a higher one is not possible. For 32-bit numbers it corresponds to about 5.9 million years.

#### 16.2.4. From CJDN to Gregorian Date (2)

Now we go in the opposite direction again.

  a ═══════════╗ ╔═ a₁ ══════════╗
(1)               ║
m ─(−1)─ m₀ ─┘ └─ m₁ ─┐        ║
d ─(−1)─ d₀ ─────────(2)─ d₁ ─[3]⇒ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${r_i}$$ $${h_i}$$ $${t_i}$$ $${g_i}$$ $${γ_i}$$ $${p}$$
1 1 12 0 1 −2 0.0833333
2 153 5 30 3 2 30.6
3.1 146097 400 365 1 1 0 4 100 365.2425
3.2 −1 1 0 100 4
3.3 1 1 0 400 1

1. First we subtract the CJDN that goes with running day number 0 from the CJDN to get the running day number:

$$s = J − J_0 = J − 1721120$$

2. Transformation 3 produces from the running day number $$s$$ the calculation year number $$a_2$$ and the day number $$d_1$$ within the calculation year. We have

\begin{align} ρ \| = 2×2 − (−1) − 365 − 1 − 2×\dparen{\dfrac{1×1}{4} + \dfrac{−1×1}{100} + \dfrac{1×1}{400}} \notag \\ \| = −361 − 2×\dparen{\dfrac{1}{4} − \dfrac{1}{100} + \dfrac{1}{400}} \notag \\ \| = −361\dfrac{97}{200} \le 0 \end{align}

so we can use the method with the fixed number of steps.

\begin{align} α_1 \| = \dfloorratio{400s + 400×2 − 0 − 1}{146097} = \dfloorratio{400s + 799}{146097} \\ δ_1 \| = s − 365α_1 − \dfloorratio{α_1}{4} + \dfloorratio{α_1}{100} − \dfloorratio{α_1}{400} \\ α_2 \| = \dfloorratio{δ_1}{367} \\ a_1 \| = α_1 + α_2 \\ d_1 \| = s − 365a_1 − \dfloorratio{a_1}{4} + \dfloorratio{a_1}{100} − \dfloorratio{a_1}{400} \end{align}

3. Transformation 2 separates the day number $$d_1$$ within the calculation year into the calculation month number $$m_1$$ within the calculation year and the day number $$d_0$$ within the calculation month.

\begin{align} \{ m_1, ε_1 \} \| = \Div(5d_1 + 2, 153) \\ d_0 \| = \dfloorratio{ε_1}{5} \end{align}

4. Transformation 1 shifts the calculation month number $$m_1$$ and calculation year number $$a_1$$ such that January instead of March is the first month of the year.

\begin{align} \{ α_2, m_0 \} \| = \Div(m_1 + 2, 12) \\ a \| = a_1 + α_2 \end{align}

5. And then we shift the month number and the day numbers such that the first ones have number 1 instead of 0.

\begin{align} m \| = m_0 + 1 \\ d \| = d_0 + 1 \end{align}

This condenses a bit, to

\begin{align} s \| = J − J_0 = J − 1721120 \\ α_1 \| = \dfloorratio{400s + 799}{146097} \\ α_2 \| = \dfloorratio{s − 365α_1 − \dfloorratio{α_1}{4} + \dfloorratio{α_1}{100} − \dfloorratio{α_1}{400}}{367} \\ a_1 \| = α_1 + α_2 \\ \{ m_1, ε_1 \} \| = \Div\dparen{5\dparen{s − 365a_1 − \dfloorratio{a_1}{4} + \dfloorratio{a_1}{100} − \dfloorratio{a_1}{400}} + 2, 153} \\ \{ α_2, m_0 \} \| = \Div(m_1 + 2, 12) \\ a \| = a_1 + α_2 \\ m \| = m_0 + 1 \\ d \| = \dfloorratio{ε_1}{5} + 1 \end{align}

For example, which date in the Gregorian calendar corresponds to CJDN 2452827? Then $$J = 2452827$$ and then

\begin{align*} s \| = J − 1721120 = 731707 \\ α_1 \| = \dfloorratio{400s + 799}{146097} = \dfloorratio{400×731707 + 799}{146097} = \dfloorratio{292683599}{146097} = 2003 \\ δ_1 \| = s − 365α_1 − \dfloorratio{α_1}{4} + \dfloorratio{α_1}{100} − \dfloorratio{α_1}{400} \\ \| = 731707 − 365×2003 − \dfloorratio{2003}{4} + \dfloorratio{2003}{100} − \dfloorratio{2003}{400} \\ \| = 731707 − 731095 − 500 + 20 − 5 = 127 \\ α_2 \| = \dfloorratio{δ_1}{367} = \dfloorratio{127}{367} = 0 \\ a_1 \| = α_1 + α_2 = 2003 + 0 = 2003 \\ d_1 \| = s − 365a_1 − \dfloorratio{a_1}{4} + \dfloorratio{a_1}{100} − \dfloorratio{a_1}{400} \\ \| = 731707 − 365×2003 − \dfloorratio{2003}{4} + \dfloorratio{2003}{100} − \dfloorratio{2003}{400} \\ \| = 731707 − 731095 − 500 + 20 − 5 = 127 \\ \{ m_1, ε_1 \} \| = \Div(5d_1 + 2, 153) = \Div(5×127 + 2, 153) \\ \| = \Div(637, 153) = \{ 4, 25 \} \\ d_0 \| = \dfloorratio{ε_1}{5} = \dfloorratio{25}{5} = 5 \\ \{ α_2, m_0 \} \| = \Div(m_1 + 2, 12) = \Div(4 + 2, 12) = \Div(6, 12) = \{ 0, 6 \} \\ a \| = a_1 + α_2 = 2003 + 0 = 2003 \\ m \| = m_0 + 1 = 6 + 1 = 7 \\ d \| = d_0 + 1 = 5 + 1 = 6 \end{align*}

The date is July 6th, 2003.

Or, in the condensed manner:

\begin{align} s \| = J − 1721120 = 2452827 − 1721120 = 731707 \\ α_1 \| = \dfloorratio{400×s + 799}{146097} = \dfloorratio{400×731707 + 799}{146097} \\ \| = \dfloorratio{292683599}{146097} = 2003 \\ α_2 \| = \dfloorratio{s − 365×α_1 − \dfloorratio{α_1}{4} + \dfloorratio{α_1}{100} − \dfloorratio{α_1}{400}}{367} \\ \| = \dfloorratio{731707 − 365×2003 − \dfloorratio{2003}{4} + \dfloorratio{2003}{100} − \dfloorratio{2003}{400}}{367} \\ \| = \dfloorratio{731707 − 731095 − 500 + 20 − 5}{367} \\ \| = \dfloorratio{127}{367} = 0 \\ a_1 \| = α_1 + α_2 = 2003 + 0 = 2003 \\ \{ m_1, ε_1 \} \| = \Div\dparen{5×\dparen{s − 365×a_1 − \dfloorratio{a_1}{4} + \dfloorratio{a_1}{100} − \dfloorratio{a_1}{400}} + 2, 153} \\ \| = \Div(5×(731707 − 731095 − 500 + 20 − 5) + 2, 153) \\ \| = \Div(5×127 + 2, 153) = \Div(637, 153) = \{ 4, 25 \} \\ \{ α_2, m_0 \} \| = \Div(m_1 + 2, 12) = \Div(4 + 2, 12) = \Div(6, 12) = \{ 0, 6 \} \\ a \| = a_1 + α_2 = 2003 + 0 = 2003 \\ m \| = m_0 + 1 = 6 + 1 = 7 \\ d \| = \dfloorratio{ε_1}{5} + 1 = \dfloorratio{25}{5} + 1 = 6 \end{align}

Transformation 3 has a limit of $$w/400$$ days. For 32-bit numbers this corresponds to about 15 thousand years. The zero point of $$J$$ is in year −4712 and adding 15 thousand years to that leads you to about the year 10 thousand.

If you want to use this calendar far beyond the year 10'000 then Section 15.2 explains how to do that. You can do that by using 64-bit numbers, or by replacing the formula for $$α_1$$ with

\begin{eqnarray} \{ ω_2, δ_2 \} \| = \| \Div(s, 146097) \\ α_2 \| = \| \dfloorratio{400 δ_2 + 799}{146097} \\ α_1 \| = \| 400 ω_2 + α_2 \end{eqnarray}

That gives a limit of $$w$$ days, and a higher is not possible. For 32-bit numbers this corresponds to about 5.9 million years.

Here are some examples of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${s}$$ $${400 s + 799}$$ $${\dfrac{400 s + 799}{w}}$$ $${α_1}$$ $${ω_2}$$ $${δ_2}$$ $${400 δ_2 + 799}$$ $${α_2}$$ $${α_1}$$
5300000 2120000799 0.99 14510 36 40508 16203999 110 14510
2140000000 856000000799 398.61 5859121 14647 117241 46897199 321 5859121

#### 16.2.5. From Gregorian Date to CJDN (3)

The calculations are schematically as follows:

  a ════════════╗
m ─(−1)─ m₀ ─(1)═ m₁ ═╗
d ─(−1)─ d₀ ─────────[2]⇒ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${r_i}$$ $${h_i}$$ $${t_i}$$ $${g_i}$$ $${γ_i}$$ $${p}$$
1 1 12 0 1 −2 0.08333
2.1 146097 4800 30 1 7 5 12 400 30.436875
2.2 −2 1 10 12 400
2.3 1 1 46 48 100
2.4 −1 1 1198 1200 4
2.5 1 1 4798 4800 1

Just like for the Julian calendar we can use a stepped combination of calendar levels. Compared to the Julian calendar we have to add to transformation 2 the leap year rules for each 100 years and for each 400 years:

\begin{eqnarray*} 30 m_1 + \dfloorratio{7 m_1 + 5}{12} − 2\dfloorratio{m_1 + 10}{12} + \dfloorratio{m_1 + 46}{48} \\ − \dfloorratio{m_1 + 1198}{1200} + \dfloorratio{m_1 + 4798}{4800} \end{eqnarray*}

which means calendar type 4 with

\begin{eqnarray*} q \| = \| 30 \\ g \| = \| 4800 \\ \{ r_1, h_1, t_1, g_1 \} \| = \| \{ 1, 7, 5, 12 \} \\ \{ r_2, h_2, t_2, g_2 \} \| = \| \{−2, 1, 10, 12 \} \\ \{ r_3, h_3, t_3, g_3 \} \| = \| \{ 1, 1, 46, 48 \} \\ \{ r_4, h_4, t_4, g_4 \} \| = \| \{−1, 1, 1198, 1200 \} \\ \{ r_5, h_5, t_5, g_5 \} \| = \| \{ 1, 1, 4798, 4800 \} \end{eqnarray*}

The CJDN $$J_0$$ that corresponds to $$\{ a, m, d \} = \{ 0, 0, 0 \}$$, i.e., January 1st of year 0 (in the Gregorian calendar) is 1721060.

For the rest things are the same as for the Julian calendar. We then find

\begin{align} m_0 \| = m − 1 \\ d_0 \| = d − 1 \\ m_1 \| = 12 a + m_0 \\ s \| = 30 m_1 + \dfloorratio{7 m_1 + 5}{12} − 2\dfloorratio{m_1 + 10}{12} + \dfloorratio{m_1 + 46}{48} \notag \\ \| − \dfloorratio{m_1 + 1198}{1200} + \dfloorratio{m_1 + 4798}{4800} + d_0 \\ J \| = s + 1721060 \end{align}

This condenses to

\begin{align} m_1 \| = 12 a + m − 1 \\ J \| = 30 m_1 + \dfloorratio{7 m_1 + 5}{12} − 2\dfloorratio{m_1 + 10}{12} + \dfloorratio{m_1 + 46}{48} \notag \\ \| − \dfloorratio{m_1 + 1198}{1200} + \dfloorratio{m_1 + 4798}{4800} + d + 1721059 \end{align}

For example, what CJDN corresponds to Julian date July 6th, 2003? Then $$a = 2003$$, $$m = 7$$, $$d = 6$$, so

\begin{align*} m_0 \| = m − 1 = 6 \\ d_0 \| = d − 1 = 5 \\ m_1 \| = 12 a + m_0 = 12×2003 + 6 = 24042 \\ s \| = 30 m_1 + \dfloorratio{7 m_1 + 5}{12} − 2\dfloorratio{m_1 + 10}{12} + \dfloorratio{m_1 + 46}{48} \\ \| − \dfloorratio{m_1 + 1198}{1200} + \dfloorratio{m_1 + 4798}{4800} + d_0 \\ \| = 30×24042 + \dfloorratio{7×24042 + 5}{12} − 2×\dfloorratio{24042 + 10}{12} + \dfloorratio{24042 + 46}{48} \\ \| − \dfloorratio{24042 + 1198}{1200} + \dfloorratio{24042 + 4798}{4800} + 5 \\ \| = 721260 + \dfloorratio{168299}{12} − 2×\dfloorratio{24052}{12} + \dfloorratio{24088}{48} \\ \| − \dfloorratio{25240}{1200} + \dfloorratio{28840}{4800} + 5 \\ \| = 721260 + 14024 − 2×2004 + 501 − 21 + 6 + 5 = 731767 \\ J \| = s + J_0 = 731767 + 1721060 = 2452827 \end{align*}

Or, in the condensed manner:

\begin{align*} m_1 \| = 12 a + m − 1 = 12×2003 + 7 − 1 = 24042 \\ J \| = 30 m_1 + \dfloorratio{7 m_1 + 5}{12} − 2\dfloorratio{m_1 + 10}{12} + \dfloorratio{m_1 + 46}{48} \\ \| − \dfloorratio{m_1 + 1198}{1200} + \dfloorratio{m_1 + 4798}{4800} + d + 1721059 \\ \| = 30×24042 + \dfloorratio{7×24042 + 5}{12} − 2\dfloorratio{24042 + 10}{12} + \dfloorratio{24042 + 46}{48} \\ \| − \dfloorratio{24042 + 1198}{1220} + \dfloorratio{24042 + 4798}{4800} + 6 + 1721059 \\ \| = 721260 + \dfloorratio{168299}{12} − 2\dfloorratio{24052}{12} + \dfloorratio{24088}{48} \\ \| − \dfloorratio{25240}{1200} + \dfloorratio{28840}{4800} + 1721065 \\ \| = 721260 + 14024 − 2×2004 + 501 − 21 + 6 + 1721065 = 2452827 \end{align*}

A few more examples:

$${a}$$ $${m}$$ $${d}$$ $${m_0}$$ $${d_0}$$ $${m_1}$$ $${•7m_1}$$ $${•\dfrac{m_1}{12}}$$ $${•\dfrac{m_1}{48}}$$ $${•\dfrac{m_1}{1200}}$$ $${•\dfrac{m_1}{4800}}$$ $${s}$$ $${J}$$
−1 12 31 11 30 −1 −1 0 0 0 0 −1 1721059
0 1 1 0 0 0 0 0 0 0 0 0 1721060
0 12 31 11 30 11 6 1 1 1 1 365 1721425
1 1 1 0 0 12 7 1 1 1 1 366 1721426
2003 2 28 1 27 24037 14022 2003 501 21 6 731639 2452699
2003 3 1 2 0 24038 14022 2004 501 21 6 731640 2452700
2003 7 6 6 5 24042 14024 2004 501 21 6 731767 2452827
2003 12 31 11 30 24047 14027 2004 501 21 6 731945 2453005
2004 1 1 0 0 24048 14028 2004 501 21 6 731946 2453006
2004 2 28 1 27 24049 14029 2004 501 21 6 732004 2453064
2004 2 29 1 28 24049 14029 2004 501 21 6 732005 2453065
2004 3 1 2 0 24050 14029 2005 502 21 6 732006 2453066

The limit for these calculations is equal to that of the corresponding Julian calendar. For 32-bits numbers this corresponds to about 5.9 million years.

#### 16.2.6. From CJDN to Gregorian Date (3)

The calculations are schematically as follows:

  a ════════════╗
m ─(−1)─ m₀ ─(1)═ m₁ ═╗
d ─(−1)─ d₀ ─────────[2]⇒ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${r_i}$$ $${h_i}$$ $${t_i}$$ $${g_i}$$ $${γ_i}$$ $${p}$$
1 1 12 0 1 −2 0.08333
2.1 146097 4800 30 1 7 5 12 400 30.436875
2.2 −2 1 10 12 400
2.3 1 1 46 48 100
2.4 −1 1 1198 1200 4
2.5 1 1 4798 4800 1

We run through the above procedure in the opposite direction. First we calculate the running day number $$s$$ by subtracting the CJDN $$J_0$$ of the beginning of year 0 from the CJDN $$J$$ of the sought calendar date:

$$s = J − J_0 = J − 1721060$$

Transformation 2 produces the running month number $$m_1$$ and the day number $$d_0$$ within the month from the running day number $$s$$.

We have

\begin{align} μ_1 \| = \dfloorratio{gs + g\dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_i γ_i r_i t_i} − 1}{f} \notag \\ \| = \dfloorratio{4800s + 4800×3 − (−1394) − 1}{146097} \notag \\ \| = \dfloorratio{4800s + 15793}{146097} \notag \\ δ_1 \| = s − 30μ_1 − \dfloorratio{7μ_1 + 5}{12} + 2\dfloorratio{μ_1 + 10}{12} − \dfloorratio{μ_1 + 46}{48} \notag \\ \| + \dfloorratio{μ_1 + 1198}{1200} − \dfloorratio{μ_1 + 4798}{4800} \\ ρ \| = 2\dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_{r_i \lt 0} r_i} − q − 1 − 2 \dparen{\sum_i \dfrac{r_ih_i}{g_i}} \notag \\ \| = 2×3 − (―3) − 30 − 2×0.436875 = −21.87375 \end{align}

Because $$ρ ≤ 0$$ we can use the procedure with the fixed steps. Then

\begin{align} m_1 \| = μ_1 + \dfloorratio{δ_1}{33} \\ d_0 \| = s − 30m_1 − \dfloorratio{7m_1 + 5}{12} + 2\dfloorratio{m_1 + 10}{12} − \dfloorratio{m_1 + 46}{48} \notag \\ \| + \dfloorratio{m_1 + 1198}{1200} − \dfloorratio{m_1 + 4798}{4800} \end{align}

Transformation 1 goes from running month number $$m_1$$ to year number $$a$$ and month number $$m_0$$ within the year. This is a calendar level of type 1.

$$\{ a, m_0 \} = \Div(m_1, 12)$$

And finally we shift the month and day numbers such that they begin at 1 instead of 0.

\begin{align} m \| = m_0 + 1 \\ d \| = d_0 + 1 \end{align}

For example, which date in the Gregorian calendar corresponds to CJDN 2452827? Then $$J = 2452827$$ and then

\begin{align*} s \| = J − 1721060 = 2452827 − 1721060 = 731767 \\ μ_1 \| = \dfloorratio{4800s + 15793}{146097} = \dfloorratio{4800×731767 + 15793}{46097} \\ \| = \dfloorratio{3512497393}{146097} = 24042 \\ δ_1 \| = s − 30μ_1 − \dfloorratio{7μ_1 + 5}{12} + 2\dfloorratio{μ_1 + 10}{12} − \dfloorratio{μ_1 + 46}{48} \\ \| + \dfloorratio{μ_1 + 1198}{1200} − \dfloorratio{μ_1 + 4798}{4800} \\ \| = 731767 − 30×24042 − \dfloorratio{7×24042 + 5}{12} + 2×\dfloorratio{24042 + 10}{12} \\ \| − \dfloorratio{24042 + 46}{48} + \dfloorratio{24042 + 1198}{1200} − \dfloorratio{24042 + 4798}{4800} \\ \| = 731767 − 721260 − \dfloorratio{168299}{12} + 2×\dfloorratio{24052}{12} \\ \| − \dfloorratio{24088}{48} + \dfloorratio{25240}{1200} − \dfloorratio{28840}{4800} \\ \| = 10507 − 14024 + 4008 − 501 + 21 − 6 = 5 \\ m_1 \| = μ_1 + \dfloorratio{δ_1}{33} = 24042 + \dfloorratio{5}{33} = 24042 + 0 = 24042 \\ d_0 \| = s − 30m_1 − \dfloorratio{7m_1 + 5}{12} + 2\dfloorratio{m_1 + 10}{12} − \dfloorratio{m_1 + 46}{48} \\ \| + \dfloorratio{m_1 + 1198}{1200} − \dfloorratio{m_1 + 4798}{4800} \\ \| = 5 \\ \{a, m_0\} \| = \Div(m_1, 12) = \Div(24042, 12) = \{ 2003, 6 \} \\ m \| = m_0 + 1 = 6 + 1 = 7 \\ d \| = d_0 + 1 = 5 + 1 = 6 \end{align*}

The date is July 6th, 2003.

A few more examples:

$${J}$$ $${s}$$ $${μ_1}$$ $${δ_1}$$ $${m_1}$$ $${d_0}$$ $${a}$$ $${m_0}$$ $${m}$$ $${d}$$
1721059 −1 0 −1 −1 30 −1 11 12 31
1721060 0 0 0 0 0 0 0 1 1
1721425 365 12 −1 11 30 0 11 12 31
1721426 366 12 0 12 0 1 0 1 1
2452699 731639 24038 −1 24037 27 2003 1 2 28
2452700 731640 24038 0 24038 0 2003 2 3 1
2452827 731767 24042 5 24042 5 2003 6 7 6
2453005 731945 24048 −1 24047 30 2003 11 12 31
2453006 731946 24048 0 24048 0 2004 0 1 1
2453064 732004 24050 −2 24049 27 2004 1 2 28
2453065 732005 24050 −1 24049 28 2004 1 2 29
2453066 732006 24050 0 24050 0 2004 2 3 1

Transformation 2 yields a limit of $$w/4800$$ days, which for 32-bit numbers corresponds to about 1225 years. That is far too little, because the zero point of $$J$$ is in the year −4712 and 1225 years later is the year −3487 which is already over 5000 years in the past. If you want a higher limit then you can use 64-bit numbers or (according to Sec. 15.2) replace the formula for $$μ_1$$ with

\begin{eqnarray} \{ ω_1, δ_1 \} \| = \| \Div(s,146097) \\ μ_2 \| = \| \dfloorratio{4800 δ_1 + 15793}{146097} \\ μ_1 \| = \| 4800 ω_1 + μ_2 \end{eqnarray}

This raises the limit to $$w$$ days, and higher isn't possible. For 32-bit numbers this corresponds to about 5.9 million years.

Here are some examples of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${s}$$ $${4800 s + 15793}$$ $${\dfrac{4800 s + 15793}{w}}$$ $${μ_1}$$
0 15793 7.4 × 10−6 0
1 20593 9.6 × 10−6 0
2 25393 1.2 × 10−5 0
445000 2136015793 0.99 14620
2140000000 10272000015793 4783.27 70309452

$${s}$$ $${ω_1}$$ $${δ_1}$$ $${4800 δ_1 + 15793}$$ $${μ_2}$$ $${μ_1}$$
0 0 0 15793 0 0
1 0 1 20593 0 0
2 0 2 25393 0 0
445000 3 6709 32218993 220 14620
2140000000 14647 117241 562772593 3852 70309452

### 16.3. The Milanković Calendar

Some Eastern Orthodox Churches have for some time (since 1923) used a calendar invented by Milutin Milanković that only differs from the Gregorian Calendar in the rule about which century years are leap years. In the Gregorian Calendar those are all years whose number is not evenly divisible by 400. In the Milanković Calendar those are are years that when dividing by 900 leave a remainder equal to 200 or 600. The following table shows for the century years from 1500 through 2900 which of them are leap years in the Gregorian and Milanković Calendars.

Year Gregorian Milanković
1500 no yes
1600 yes no
1700 no no
1800 no no
1900 no no
2000 yes yes
2100 no no
2200 no no
2300 no no
2400 yes yes
2500 no no
2600 no no
2700 no no
2800 yes no
2900 no yes

Between the years 1601 and 2799, the Milanković and Gregorian calendars give the same results. The years 1600 and 2800 are leap years in the Gregorian calendar but not in the Milanković calendar.

Just like for the Gregorian Calendar we can handle this in different ways. We show only the method that has calendar type 2 as its highest, because that one is the most convenient in practice.

#### 16.3.1. From Milanković Date to CJDN

With these leap year rules, the Milanković calendar has a period of 365×900 + 900/4 − (900/100)×(7/9) = 328718 days. The conversion of a date to CJDN is nearly the same for the Milanković calendar as for the Gregorian calendar (see Section 16.2.1). The calculations are schematically as follows:

                         ╔══ c₁ ══════════╗
a ═══════════╗ ╔═ a₁ ═(2)─ a₂ ─┐        ║
(1)               │        ║
m ─(−1)─ m₀ ─┘ └─ m₁ ─┐        │        ║
d ─(−1)─ d₀ ─────────(3)─ d₁ ─(4)─ d₂ ─(5)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$
1 1 12 0 1 −2 0.08333
2 100 1 100 0 0 100
3 153 5 30 3 2 30.6
4 36525 100 365 25 0 365.25
5 328718 9 36524 2 6 36524+2/9

The steps to get from the Milanković calendar to the CJDN are now:

1. First we shift months and days such that the first ones have number 0. January 1 then corresponds to $$m_0 = 0, d_0 = 0$$.

\begin{align} m_0 \| = m − 1 \\ d_0 \| = d − 1 \end{align}

2. Transformation 1 shifts the month number and year number such that March instead of January is the first calculation month (month $$m_1 = 0$$) of the calculation year $$a_1$$, just like for the Julian calendar (16.1.1).

\begin{align} \{ α_1, m_1 \} \| = \Div(m_0 − 2, 12) \\ a_1 \| = a + α_1 \end{align}

3. Transformation 2 calculates the calculation century number $$c_1$$ and year number $$a_1$$ within the calculation century from the calculation year number $$a_1$$.

$$\{ c_1, a_2 \} = \Div(a_1, 100)$$

4. Transformation 3 calculates the day number $$d_1$$ within the calculation year from the calculation month $$m_1$$ within the calculation year and the day number $$d_0$$ within the calculation month:

$$d_1 = \dfloorratio{153 m_1 + 2}{5} + d_0 = 30 m_1 + \dfloorratio{3 m_1 + 2}{5} + d_0$$

5. Transformation 4 calculates the day number $$d_2$$ within the calculation century from the year number $$a_2$$ within the calculation century and the day number $$d_1$$ within the calculation year.

$$d_2 = \dfloorratio{36525 a_2}{100} + d_1$$

6. Transformation 5 calculates the running day number $$s$$ from the calculation century number $$c_1$$ and the day number $$d_2$$ within the calculation century.

$$s = \dfloorratio{328718 c_1 + 6}{9} + d_2$$

7. And then we add to $$s$$ the CJDN of the beginning of calculation year 0 (March 1 of Year 0), which is 1721120:

$$J = s + J_0 = s + 1721120$$

Combined and condensed, this yields:

\begin{align} \{ α_1, m_1 \} \| = \Div(m − 3, 12) \\ \{ c_1, a_2 \} \| = \Div(a + α_1, 100) \\ J \| = \dfloorratio{328718 c_1 + 6}{9} + \dfloorratio{36525 a_2}{100} \notag \\ \| + \dfloorratio{153 m_1 + 2}{5} + d + 1721119 \end{align}

For example, which CJDN corresponds to Milanković date July 6th, 2003? Then $$a = 2003$$, $$m = 7$$, $$d = 6$$ hence

\begin{align*} m_0 \| = m − 1 = 7 − 1 = 6 \\ d_0 \| = d − 1 = 6 − 1 = 5 \\ \{α_1, m_1\} \| = \Div(m_0 − 2, 12) = \Div(6 − 2, 12) = \Div(4, 12) = \{ 0, 4 \} \\ a_1 \| = a + α_1 = 2003 + 0 = 2003 \\ \{ c_1, a_2 \} \| = \Div(a_1, 100) = \Div(2003, 100) = \{ 20, 3 \} \\ d_1 \| = \dfloorratio{153m_1 + 2}{5} + d_0 = \dfloorratio{153×4 + 2}{5} + 5 = \dfloorratio{614}{5} + 5 = 122 + 5 = 127 \\ d_2 \| = \dfloorratio{36525a_2}{100} + d_1 = \dfloorratio{36525×3}{100} + 127 \\ \| = \dfloorratio{109575}{100} + 122 = 1095 + 127 = 1222 \\ s \| = \dfloorratio{328718c_1 + 6}{9} + d_2 = \dfloorratio{328718×20 + 6}{9} + 1222 \\ \| = \dfloorratio{6574366}{9} + 1222 = 730485 + 1222 = 731707 \\ J \| = s + 1721119 = 731707 + 1721120 = 2452827 \end{align*}

Some more examples:

$${a}$$ $${m}$$ $${d}$$ $${m_0}$$ $${d_0}$$ $${α_1}$$ $${m_1}$$ $${a_1}$$ $${c_1}$$ $${a_2}$$ $${d_1}$$ $${d_2}$$ $${s}$$ $${J}$$
−1000 12 15 11 14 0 9 −1000 −10 0 289 289 −364953 1356167
−1 12 31 11 30 0 9 −1 −1 99 305 36464 −60 1721060
0 1 1 0 0 −1 10 −1 −1 99 306 36465 −59 1721061
0 2 28 1 27 −1 11 −1 −1 99 364 36523 −1 1721119
0 3 1 2 0 0 0 0 0 0 0 0 0 1721120
1900 2 28 1 27 −1 11 1899 18 99 364 36523 693959 2415079
1900 3 1 2 0 0 0 1900 19 0 0 0 693960 2415080
1999 12 31 11 30 0 9 1999 19 99 305 36464 730424 2451544
2000 1 1 0 0 −1 10 1999 19 99 306 36465 730425 2451545
2000 2 28 1 27 −1 11 1999 19 99 364 36523 730483 2451603
2000 2 29 1 28 −1 11 1999 19 99 365 36524 730484 2451604
2000 3 1 2 0 0 0 2000 20 0 0 0 730485 2451605
2003 7 6 6 5 0 4 2003 20 3 127 1222 731707 2452827

With the condensed formulas:

$${a}$$ $${m}$$ $${d}$$ $${α_1}$$ $${m_1}$$ $${c_1}$$ $${a_2}$$ $${J}$$
−1000 12 15 0 9 −10 0 1356167
−1 12 31 0 9 −1 99 1721060
0 1 1 −1 10 −1 99 1721061
0 2 28 −1 11 −1 99 1721119
0 3 1 0 0 0 0 1721120
1900 2 28 −1 11 18 99 2415079
1900 3 1 0 0 19 0 2415080
1999 12 31 0 9 19 99 2451544
2000 1 1 −1 10 19 99 2451545
2000 2 28 −1 11 19 99 2451603
2000 2 29 −1 11 19 99 2451604
2000 3 1 0 0 20 0 2451605
2003 7 6 0 4 20 3 2452827

Transformation 2 yields no extra limitation because there $$f = 1$$. Transformation 5 yields a limit of $$w/328718$$ Milanković centuries, which corresponds to about $$w/9$$ days, and which is also the combined limit. For 32-bit numbers this corresponds to 650 thousand years. A more detailed search (as described in Sec. 15.2.3) shows that for 32-bit numbers the above formulas produce the correct results for CJDN −236'855'099 through 240'330'413, which corresponds to from somewhere in Milanković year −653'200 to somewhere in year 653'290.

If you want a higher limit then you can use 64-bit numbers or replace transformation 5 with

$$s = 36524 c_1 + \dfloorratio{2 c_1 + 6}{9} + d_2$$

Then the limit is about $$w$$ days, and higher is not possible. For 32-bit numbers this corresponds to about 5.9 million years.

Here are some examples (with $$d_2 = 0$$) of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${c_1}$$ $${328718 c_1 + 6}$$ $${\dfloor{328718 c_1 + 6}{w}}$$ $${s}$$ $${36524 c_1}$$ $${\dfrac{36524 c_1}{w}}$$ $${2 c_1 + 6}$$ $${s}$$
6500 2136667006 0.99 237407445 237406000 0.11 13006 237407445
58700 19295746606 8.99 2143971845 2143958800 1.00 117406 2143971845

#### 16.3.2. From CJDN to Milanković Date

Also in the opposite direction, we do the same as for the Gregorian calendar (see Section 16.2.2), except that we use different formulas to calculate $$c_1$$ and $$d_2$$. The calculations are schematically as in this diagram:

                         ╔══ c₁ ══════════╗
a ═══════════╗ ╔═ a₁ ═(2)─ a₂ ─┐        ║
(1)               │        ║
m ─(−1)─ m₀ ─┘ └─ m₁ ─┐        │        ║
d ─(−1)─ d₀ ─────────(3)─ d₁ ─(4)─ d₂ ─(5)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$
1 1 12 0 1 −2 0.08333
2 100 1 100 0 0 100
3 153 5 30 3 2 30.6
4 36525 100 365 25 0 365.25
5 328718 9 36524 2 6 36524+2/9

1. First we subtract the CJDN that goes with running day number 0 from the CJDN to get the running day number:

$$s = J − J_0 = J − 1721120$$

2. Transformation 5 produces from the running day number $$s$$ the calculation century $$c_1$$ and the day number $$d_2$$ within the calculation century:

\begin{align} \{ c_1, ε_1 \} \| = \Div(9s + 2, 328718) \\ d_2 \| = \dfloorratio{ε_1}{9} \end{align}

3. Transformation 4 produces from the day number $$d_2$$ within the calculation century the year number $$a_2$$ within the calculation century and the day number $$d_1$$ within the calculation year.

\begin{align} \{ a_2, ε_2 \} \| = \Div(100d_2 + 99, 36525) \\ d_1 \| = \dfloorratio{ε_2}{100} \end{align}

4. Transformation 3 separates the day number $$d_1$$ within the calculation year into the calculation month number $$m_1$$ within the calculation year and the day number $$d_0$$ within the calculation month.

\begin{align} \{ m_1, ε_3 \} \| = \Div(5d_1 + 2, 153) \\ d_0 \| = \dfloorratio{ε_3}{5} \end{align}

5. Transformation 2 combines the calculation century number $$c_1$$ and the calculation year number $$a_2$$ within the calculation century into the calculation year number $$a_1$$.

$$a_1 = 100c_1 + a_2$$

6. Transformation 1 shifts the calculation month number $$m_1$$ and calculation year number $$a_1$$ such that January instead of March is the first month of the year.

\begin{align} \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) \\ a \| = a_1 + α_1 \end{align}

7. And then we shift the month number and the day numbers such that the first ones have number 1 instead of 0.

\begin{align} m \| = m_0 + 1 \\ d \| = d_0 + 1 \end{align}

This condenses a little bit, to:

\begin{align} \{ c_1, ε_1 \} \| = \Div(9J − 15490078, 328718) \\ \{ a_2, ε_2 \} \| = \Div\dparen{100\dfloorratio{ε_1}{9} + 99, 36525} \\ \{ m_1, ε_3 \} \| = \Div\dparen{5\dfloorratio{ε_2}{100} + 2, 153} \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) \\ a \| = 100c_1 + a_2 + α_1 \\ m \| = m_0 + 1 \\ d \| = \dfloorratio{ε_3}{5} + 1 \end{align}

For example, which date in the Milanković calendar corresponds to CJDN 2452827? Then $$J = 2452827$$ and then

\begin{align*} s \| = J − 1721120 = 2452827 − 1721120 = 731707 \\ \{c_1, ε_1 \} \| = \Div(9 s + 2, 328718) = \Div(9×731707 + 2, 328718) \\ \| = \Div(6585365, 328718) = \{ 20, 11005 \} \\ d_2 \| = \dfloorratio{ε_1}{9} = \dfloorratio{11005}{9} = 1222 \\ \{a_2, ε_2\} \| = \Div(100 d_2 + 99, 36525) = \Div(100×1222 + 99, 36525) \\ \| = \Div(122299, 36525) = \{3, 12724\} \\ d_1 \| = \dfloorratio{ε_2}{100} = \dfloorratio{12724}{100} = 127 \\ \{m_1, ε_3 \} \| = \Div(5 d_1 + 2, 153) = \Div(5×127 + 2, 153) \\ \| = \Div(637, 153) = \{4, 25\} \\ d_0 \| = \dfloorratio{ε_3}{5} = \dfloorratio{25}{5} = 5 \\ a_1 \| = 100 c_1 + a_2 = 100×20 + 3 = 2003 \\ \{α_1, m_0\} \| = \Div(m_1 + 2, 12) = \Div(4 + 2, 12) = \Div(6, 12) = \{ 0, 6 \} \\ a \| = a_1 + α_1 = 2003 + 0 = 2003 \\ m \| = m_0 + 1 = 6 + 1 = 7 \\ d \| = d_0 + 1 = 5 + 1 = 6 \end{align*}

The date is July 6th, 2003.

Or, in the condensed manner,

\begin{align*} \{ c_1, ε_1 \} \| = \Div(9 J − 15490078, 328718) \\ \| = \Div(9×2452827 − 15490078, 328718) \\ \| = \Div(6585365, 328718) = \{ 20, 11005 \} \\ \{ a_2, ε_2 \} \| = \Div\dparen{100\dfloorratio{ε_1}{9} + 99, 36525} = \Div\dparen{100\dfloorratio{11005}{9} + 99, 36525} \\ \| = \Div(100×1222 + 99, 36525) = \Div(122299, 36525) = \{ 3, 12724 \} \\ \{ m_1, ε_3 \} \| = \Div\dparen{5\dfloorratio{ε_2}{100} + 2, 153} = \Div\dparen{5\dfloorratio{12724}{100} + 2, 153} \\ \| = \Div(5×127 + 2, 153) = \Div(635, 153) = \{ 4, 25 \} \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) = \Div(4 + 2, 12) = \Div(6, 12) = \{ 0, 6 \} \\ a \| = 100 c_1 + a_2 + α_1 = 100×20 + 3 + 0 = 2003 \\ m \| = m_0 + 1 = 6 + 1 = 7 \\ d \| = \dfloorratio{ε_3}{5} + 1 = \dfloorratio{25}{5} + 1 = 5 + 1 = 6 \end{align*}

Some more examples:

$${J}$$ $${s}$$ $${c_1}$$ $${ε_1}$$ $${d_2}$$ $${a_2}$$ $${ε_2}$$ $${d_1}$$ $${m_1}$$ $${ε_3}$$ $${d_0}$$ $${a_1}$$ $${α_1}$$ $${m_0}$$ $${a}$$ $${m}$$ $${d}$$
1356167 −364953 −10 2605 289 0 28999 289 9 70 14 −1000 0 11 −1000 12 15
1721060 −60 −1 328180 36464 99 30524 305 9 150 30 −1 0 11 −1 12 31
1721061 −59 −1 328189 36465 99 30624 306 10 2 0 −1 1 0 0 1 1
1721119 −1 −1 328711 36523 99 36424 364 11 139 27 −1 1 1 0 2 28
1721120 0 0 2 0 0 99 0 0 2 0 0 0 2 0 3 1
2415079 693959 18 328709 36523 99 36424 364 11 139 27 1899 1 1 1900 2 28
2415080 693960 19 0 0 0 99 0 0 2 0 1900 0 2 1900 3 1
2451544 730424 19 328176 36464 99 30524 305 9 150 30 1999 0 11 1999 12 31
2451545 730425 19 328185 36465 99 30624 306 10 2 0 1999 1 0 2000 1 1
2451603 730483 19 328707 36523 99 36424 364 11 139 27 1999 1 1 2000 2 28
2451604 730484 19 328716 36524 99 36524 365 11 144 28 1999 1 1 2000 2 29
2451605 730485 20 7 0 0 99 0 0 2 0 2000 0 2 2000 3 1
2452827 731707 20 11005 1222 3 12724 127 4 25 5 2003 0 6 2003 7 6

Or, in the condensed manner,

$${J}$$ $${c_1}$$ $${ε_1}$$ $${a_2}$$ $${ε_2}$$ $${m_1}$$ $${ε_3}$$ $${α_1}$$ $${m_0}$$ $${a}$$ $${m}$$ $${d}$$
1356167 −10 2605 0 28999 9 70 0 11 −1000 12 15
1721060 −1 328180 99 30524 9 150 0 11 −1 12 31
1721061 −1 328189 99 30624 10 2 1 0 0 1 1
1721119 −1 328711 99 36424 11 139 1 1 0 2 28
1721120 0 2 0 99 0 2 0 2 0 3 1
2415079 18 328709 99 36424 11 139 1 1 1900 2 28
2415080 19 0 0 99 0 2 0 2 1900 3 1
2451544 19 328176 99 30524 9 150 0 11 1999 12 31
2451545 19 328185 99 30624 10 2 1 0 2000 1 1
2451603 19 328707 99 36424 11 139 1 1 2000 2 28
2451604 19 328716 99 36524 11 144 1 1 2000 2 29
2451605 20 7 0 99 0 2 0 2 2000 3 1
2452827 20 11005 3 12724 4 25 0 6 2003 7 6

Transformation 5 has a limit of $$w/9$$ days. Transformation 2 yields a limt of $$w/100$$ centuries which corresponds to about $$365.25 w$$ days, so no extra limit after all. The combined limit is $$w/9$$ days, which for 32-bit numbers corresponds to about 653 thousand years.

If you want the greatest possible limit then you can calculate using 64-bit numbers or replace transformation 5 with

\begin{align} \{ ω_4, δ_1 \} \| = \Div(s, 328718) \\ \{ ω_5, ε_1 \} \| = \Div(9 δ_1 + 2,328718) \\ c_1 \| = 9 ω_4 + ω_5 \end{align}

That has a limit of $$w$$ days, and higher is not possible. For 32-bit numbers this corresponds to about 5.8 million years.

Here are some examples of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${s}$$ $${9 s + 2}$$ $${\dfrac{9 s + 2}{w}}$$ $${c_1}$$ $${ε_1}$$ $${ω_4}$$
237000000 2133000002 0.99 6488 277618 720
2140000000 19260000002 8.97 58591 83664 6510

$${s}$$ $${δ_1}$$ $${9 δ_1 + 2}$$ $${\dfrac{9 δ_1 + 2}{w}}$$ $${ω_5}$$ $${ε_1}$$ $${c_1}$$
237000000 323040 2907362 1.4 × 10−3 8 277618 6488
2140000000 45820 412382 1.9 × 10−4 1 83664 58591

### 16.4. The Hershel Calendar

The English scientist John Herschel (1792 - 1871) invented a revision to the Gregorian Calendar that makes it more closely follow the average length of a solar year. His idea was to add a leap year rule that says that a year is not a leap year after all (and February contains 28 days) if the year number is evenly divisible by 4000. Then the full set of rules for leap years are:

1. only if the year number is evenly divisible by 4

2. but not if the year number is evenly divisible by 100

3. but have a leap year anyway if the year number is evenly divisible by 400

4. but don't have a leap year after all if the year number is evenly divisible by 4000.

For rule 4 we must take away one day from the end of every group of 10 400-calculation-year periods, so the first 9 400-calculation-year periods should contain 146097 days, and the last one should contain 146096 days. We get that with a formula like

$d = \dfloorratio{1460969 c + 9}{10}$

where $$c$$ is the number of 400-calculation-year periods, and $$d$$ is the number of days within the most recent 4000-calculation-year period, as can be seen from the following table.

$${c}$$ $${1460969 c + 9}$$ $${d}$$ $${∆d}$$
0 9 0 146097
1 1460978 146097 146097
2 2921947 292194 146097
3 4382916 438291 146097
4 5843885 584388 146097
5 7304854 730485 146097
6 8765823 876582 146097
7 10226792 1022679 146097
8 11687761 1168776 146097
9 13148730 1314873 146096
10 14609699 1460969

#### 16.4.1. From Herschel Date to CJDN

The calculations are schematically as follows:

                         ╔══ c₁ ═(5)═ c₂ ═══════════╗
║        └── c₃ ──┐        ║
a ═══════════╗ ╔═ a₁ ═(2)─ a₂ ──┐        │        ║
(1)                │        │        ║
m ─(−1)─ m₀ ─┘ └─ m₁ ──┐        │        │        ║
d ─(−1)─ d₀ ──────────(3)─ d₁ ─(4)─ d₂ ─(6)─ d₃ ─(7)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$
1 1 12 1 0 −2
2 1 100 1 0 0
3 153 5 30 3 2
4 36525 100 365 25 0
5 1 4 0 1 0
6 146097 4 36524 1 0
7 1460969 10 146096 9 9

The steps to get from the Herschel calendar to the CJDN are now:

1. First we shift months and days such that the first ones have number 0. January 1 then corresponds to $$m_0 = 0, d_0 = 0$$.

\begin{align} m_0 \| = m − 1 \\ d_0 \| = d − 1 \end{align}

2. Transformation 1 shifts the month number and year number such that March instead of January is the first calculation month (month $$m_1 = 0$$) of the calculation year $$a_1$$.

\begin{align} \{ α_1, m_1 \} \| = \Div(m_0 − 2, 12) \\ a_1 \| = a + α_1 \end{align}

3. Transformation 2 calculates the calculation century number $$c_1$$ and year number $$a_1$$ within the calculation century from the calculation year number $$a_1$$.

$$\{ c_1, a_2 \} = \Div(a_1, 100)$$

4. Transformation 3 calculates the day number $$d_1$$ within the calculation year from the calculation month $$m_1$$ and the day number $$d_0$$ within the calculation month:

$$d_1 = \dfloorratio{153 m_1 + 2}{5} + d_0 = 30 m_1 + \dfloorratio{3 m_1 + 2}{5} + d_0$$

5. Transformation 4 calculates the day number $$d_2$$ within the calculation century from the year number $$a_2$$ within the calculation century and the day number $$d_1$$ within the calculation year.

$$d_2 = \dfloorratio{36525 a_2}{100} + d_1$$

6. Transformation 5 calculates from the running calculation century number $$c_1$$ the running number $$c_2$$ of 400-calculation-year periods and the number $$c_3$$ of calculation centuries within the last 400-calculation-year period.

$$\{ c_2, c_3 \} = \Div(c_1, 4)$$

7. Transformation 6 calculates the day number $$d_3$$ within the 400-calculation-year period from the calculation century number $$c_3$$ within the 400-calculation-year period and the day number $$d_2$$ within the calculation century.

$$d_3 = \dfloorratio{146097 c_3}{4} + d_2$$

8. Transformation 7 calculates the running day number $$s$$ from the running number of 400-calculation-year periods $$c_2$$ and the day number $$d_3$$ within the last 400-calculation-year period.

$$s = \dfloorratio{1460969 c_2 + 9}{10} + d_3$$

9. And then we add to $$s$$ the CJDN of the beginning of calculation year 0 (March 1 of Year 0), which is 1721120:

$$J = s + J_0 = s + 1721120$$

Combined and condensed, this yields:

\begin{align} \{ α_1, m_1 \} \| = \Div(m − 3, 12) \\ \{ c_1, a_2 \} \| = \Div(a + α_1, 100) \\ \{ c_2, c_3 \} \| = \Div(c_1, 4) \\ J \| = \dfloorratio{1460969 c_2 + 9}{10} + \dfloorratio{146097 c_3}{4} + \dfloorratio{36525 a_2}{100} \notag \\ \| + \dfloorratio{153 m_1 + 2}{5} + d + 1721119 \end{align}

For example, which CJDN corresponds to the date 11 August 2022 in the Herschel Calendar? Then $$a = 2022$$, $$m = 0$$, and $$d = 11$$, and then

\begin{align*} \{ α_1, m_1 \} \| = \Div(m − 3, 12) = \Div(8 ― 3, 12) = \Div(5, 12) = \{ 0, 5 \} \\ \{ c_1, a_2 \} \| = \Div(a + α_1, 100) = \Div(2022 + 0, 100) \\ \| = \Div(2022, 100) = \{ 20, 22 \} \\ \{ c_2, c_3 \} \| = \Div(c_1, 4) = \Div(20, 4) = \{ 5, 0 \} \\ J \| = \dfloorratio{1460969 c_2 + 9}{10} + \dfloorratio{146097 c_3}{4} + \dfloorratio{36525 a_2}{100} \\ \| + \dfloorratio{153 m_1 + 2}{5} + d + 1721120 \\ \| = \dfloorratio{1460969×5 + 9}{10} + \dfloorratio{146097×0}{4} + \dfloorratio{36525×22}{100} \\ \| + \dfloorratio{153×5 + 2}{5} + 11 + 1721120 \\ \| + \dfloorratio{153 m_1 + 2}{5} + d + 1721120 \\ \| = \dfloorratio{7304854}{10} + 0 + \dfloorratio{803550}{100} \\ \| + \dfloorratio{767}{5} + 11 + 1721120 \\ \| = 730485 + 0 + 8035 + 153 + 11 + 1721119 = 2459803 \end{align*}

Some more examples:

$${a}$$ $${m}$$ $${d}$$ $${α_1}$$ $${m_1}$$ $${c_1}$$ $${a_2}$$ $${c_2}$$ $${c_3}$$ $${•c_2}$$ $${•c_3}$$ $${•a_2}$$ $${•m_1}$$ $${J}$$
2022 7 22 0 4 20 22 5 0 730485 0 8035 122 2459783
1000 1 1 −1 10 9 99 2 1 292194 36524 36159 306 2086303
2000 2 29 −1 11 19 99 4 3 584388 109572 36159 337 2451604
2000 3 1 0 0 20 0 5 0 730485 0 0 0 2451605
2022 8 11 0 5 20 22 5 0 730485 0 8035 153 2459803
3600 2 29 −1 11 35 99 8 3 1168776 109572 36159 337 3035992
3600 3 1 0 0 36 0 9 0 1314873 0 0 0 3035993
4000 2 28 −1 11 39 99 9 3 1314873 109572 36159 337 3182088
4000 3 1 0 0 40 0 10 0 1460969 0 0 0 3182089
5800000 1 1 −1 10 57999 99 14499 3 2118258954 109572 36159 306 2120126111

Transformation 4 yields a limit of $$w/365,25$$ years, which corresponds to $$w$$ days. Transformation 7 yields a limit of $$w/1460969$$ 400-calculation-year periods, which corresponds to $$w/10$$ days. The combined limit is $$w/10$$ days, which for 32-bit numbers corresponds to about 588'000 years. A more detailed search (as described in Sec. 15.2.3) shows that for 32-bit numbers the above formulas produce the correct results for CJDN −212'895'226 through 216'469'484, which corresponds to from somewhere in Herschel year −587'600 to somewhere in year 587'961.

If you want the greatest possible limit then you can calculate with 64-bit numbers or else replace the formula for $$s$$ by0

$$s = 146096 c_2 + \dfloorratio{9 c_2 + 9}{10} + d_3$$

Then the limit is $$w$$ days, which for 32-bit numbers corresponds to about 5.8 million years.

For example, if $$a = 5800000$$ then $$c_2 = 14499$$. The old formula for $$s$$ yields (with $$d_3 = 0$$)

\begin{align*} s \| = \dfloorratio{1460969 c_2 + 9}{10} = \dfloorratio{1460969×14499 + 9}{10} \\ \| = \dfloorratio{21182589540}{10} = 2118258954 \end{align*}

The greatest intermediate result 21'182'589'540 is roughly 10 times too great to be a 32-bit number. With the detour we get (for $$d_3 = 0$$)

\begin{align*} s \| = 146096 c_2 + \dfloorratio{9 c_2 + 9}{10} = 146096×14499 + \dfloorratio{9×14499 + 9}{10} \\ \| = 2118245904 + \dfloorratio{130500}{10} = 2118245904 + 13050 = 2118258954 \end{align*}

That is the same result as with the old formula, but now the greatest intermediate result is the end result, which is just small enough to be a 32-bit number.

#### 16.4.2. From CJDN to Herschel Date

The calculations are schematically as follows:

                         ╔══ c₁ ═(5)═ c₂ ═══════════╗
║        └── c₃ ──┐        ║
a ═══════════╗ ╔═ a₁ ═(2)─ a₂ ──┐        │        ║
(1)                │        │        ║
m ─(−1)─ m₀ ─┘ └─ m₁ ──┐        │        │        ║
d ─(−1)─ d₀ ──────────(3)─ d₁ ─(4)─ d₂ ─(6)─ d₃ ─(7)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$
1 1 12 1 0 −2
2 1 100 1 0 0
3 153 5 30 3 2
4 36525 100 365 25 0
5 1 4 0 1 0
6 146097 4 36524 1 0
7 1460969 10 146096 9 9

Now we go in the opposite direction again, with the same calendar levels as before.

1. First we subtract the CJDN that goes with running day number 0 from the CJDN to get the running day number:

$$s = J − J_0 = J − 1721120$$

2. Transformation 7 calculates from running day number $$s$$ the number $$c_2$$ of 400-calculation-year periods and the day number $$d_3$$ within the last 400-calculation-year period.

\begin{align} \{ c_2, ε_1 \} \| = \Div(10 s, 1460969) \\ d_3 \| = \dfloorratio{ε_1}{10} \end{align}

3. Transformation 6 calculates from the day number $$d_3$$ within the last 400-calculation-year period the number $$c_3$$ of calculation centuries within the last 400-calculation-year period and the day number $$d_2$$ within the last calculation century.

\begin{align} \{ c_3, ε_2 \} \| = \Div(4 d_3 + 3, 146097) \\ d_2 \| = \dfloorratio{ε_2}{4} \end{align}

4. Transformation 5 calculates the number of calculation centuries since calculation year 0 from the number $$c_3$$ of calculation centuries within the last 400-calculation-year period and the number $$c_2$$ of 400-calculation-year periods since calculation year 0.

$$c_1 = 4 c_2 + c_3$$

5. Transformation 4 produces from the day number $$d_2$$ since the beginning of the calculation century the year number $$a_2$$ within the calculation century and the day number $$d_1$$ within the calculation year.

\begin{align} \{ a_2, ε_3 \} \| = \Div(100d_2 + 99, 36525) \\ d_1 \| = \dfloorratio{ε_3}{100} \end{align}

6. Transformation 3 separates the day number $$d_1$$ since the beginning of the calculation year into the calculation month number $$m_1$$ within the calculation year and the day number $$d_0$$ within the calculation month.

\begin{align} \{ m_1, ε_4 \} \| = \Div(5d_1 + 2, 153) \\ d_0 \| = \dfloorratio{ε_4}{5} \end{align}

7. Transformation 2 combines the calculation century number $$c_1$$ and the calculation year number $$a_2$$ since the beginning of the calculation century into the calculation year number $$a_1$$.

$$a_1 = 100 c_1 + a_2$$

8. Transformation 1 shifts the calculation month number $$m_1$$ and calculation year number $$a_1$$ such that January instead of March is the first month of the year.

\begin{align} \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) \\ a \| = a_1 + α_1 \end{align}

9. And then we shift the month number and the day numbers such that the first ones have number 1 instead of 0.

\begin{align} m \| = m_0 + 1 \\ d \| = d_0 + 1 \end{align}

This condenses a bit, to

\begin{align} \{ c_2, ε_1 \} \| = \Div(10 J − 17211200, 1460969) \\ \{ c_3, ε_2 \} \| = \Div\dparen{4 \dfloorratio{ε_1}{10} + 3, 146097} \\ \{ a_2, ε_3 \} \| = \Div\dparen{100 \dfloorratio{ε_2}{4} + 99, 36525} \\ \{ m_1, ε_4 \} \| = \Div\dparen{5 \dfloorratio{ε_3}{100} + 2, 153} \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) \\ a \| = 400 c_2 + 100 c_3 + a_2 + α_1 \\ m \| = m_0 + 1 \\ d \| = \dfloorratio{ε_4}{5} + 1 \end{align}

For example, which Herschel date goes with CJDN 2459803? Then $$J = 2459803$$ and then

\begin{align*} \{ c_2, ε_1 \} \| = \Div(10 J − 17211200, 1460969) = \Div(10×2459803 − 17211200, 1460969) \\ \| = \Div(7386830, 1460969) = \{ 5, 81985 \} \\ \{ c_3, ε_2 \} \| = \Div\dparen{4 \dfloorratio{ε_1}{10} + 3, 146097} = \Div\dparen{4 \dfloorratio{81985}{10} + 3, 146097} \\ \| = \Div(4×8198 + 3, 146097) = \Div(32795, 146097) = \{ 0, 32795 \} \\ \{ a_2, ε_3 \} \| = \Div\dparen{100 \dfloorratio{ε_2}{4} + 99, 36525} = \Div\dparen{100 \dfloorratio{32795}{4} + 99, 36525} \\ \| = \Div(100×8198 + 99, 36525) = \Div(819899, 36525) = \{ 22, 16349 \} \\ \{ m_1, ε_4 \} \| = \Div\dparen{5 \dfloorratio{ε_3}{100} + 2, 153} = \Div\dparen{5 \dfloorratio{16349}{100} + 2, 153} \\ \| = \Div(5×163 + 2, 153) = \Div(817, 153) = \{ 5, 52 \} \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) = \Div(5 + 2, 12) = \Div(7, 12) = \{ 0, 7 \} \\ a \| = 400 c_2 + 100 c_3 + a_2 + α_1 = 400×5 + 100×0 + 22 + 0 = 2022 \\ m \| = m_0 + 1 = 7 + 1 = 8 \\ d \| = \dfloorratio{ε_4}{5} + 1 = \dfloorratio{52}{5} + 1 = 10 + 1 = 11 \end{align*}

so the date is day 11 in month 8 in year 2022.

Some more examples:

$${J}$$ $${c_2}$$ $${ε_1}$$ $${c_3}$$ $${ε_2}$$ $${a_2}$$ $${ε_3}$$ $${m_1}$$ $${ε_4}$$ $${α_1}$$ $${m_0}$$ $${a}$$ $${m}$$ $${d}$$
2459783 5 81785 0 32715 22 14349 4 105 0 6 2022 7 22
2086303 2 729892 1 145862 99 30624 10 2 1 0 1000 1 1
2451604 4 1460964 3 146096 99 36524 11 144 1 1 2000 2 29
2451605 5 5 0 3 0 99 0 2 0 2 2000 3 1
2459803 5 81985 0 32795 22 16349 5 52 0 7 2022 8 11
3035992 8 1460968 3 146096 99 36524 11 144 1 1 3600 2 29
3035993 9 9 0 3 0 99 0 2 0 2 3600 3 1
3182088 9 1460959 3 146092 99 36424 11 139 1 1 4000 2 28
3182089 10 0 0 3 0 99 0 2 0 2 4000 3 1
2120126111 14499 1460379 3 145860 99 30624 10 2 1 0 5800000 1 1

Transformation 7 has a limit of $$w/10$$ days, and that is the combined limit. For 32-bit numbers this corresponds to about 580'000 years.

If you want a greater limit then you can calculate using 64-bit numbers or else change the formula for $$\{ c_2, ε_1 \}$$ by

\begin{align} \{ ω_1, δ_1 \} \| = \Div(s, 1460969) \\ \{ ω_2, ε_1 \} \| = \Div(10 δ_1, 1460969) \\ c_2 \| = 10 ω_1 + ω_2 \end{align}

Then the limit becomes $$w$$ days, which for 32-bit numbers corresponds to about 5.8 million years.

For example, for $$s = 2120126111$$ the old formula yields

\begin{align*} \{ c_2, ε_1 \} \| = \Div(10 s, 1460969) = \Div(10×2120126111, 1460969) \\ \| = \Div(21201261110, 1460969) = \{ 14511, 1139951 \} \end{align*}

The greatest intermediate result is 21'201'261'110, which is about 10 times greater than will fit in a 32-bit number. With the detour we find

\begin{align} \{ ω_1, δ_1 \} \| = \Div(s, 1460969) = \Div(2120126111, 1460969) = \{ 1451, 260092 \} \\ \{ ω_2, ε_1 \} \| = \Div(10 δ_1, 1460969) = \Div(10×260092, 1460969) \\ \| = \Div(2600920, 1460969) = \{ 1, 1139951 \} \\ c_2 \| = 10 ω_1 + ω_2 = 10×1451 + 1 = 14511 \end{align}

so the same results as before, but now the greatest intermediate result is the starting number, which is just small enough to be a 32-bit number.

### 16.5. The Egyptian Calendar

The ancient Egyptians had a very simple calendar indeed, without leap years and with 30 days to every month, except that the last month had 5 days.

At the higher calendar level, each year has 365 days. At the lower level, each month has 30 days. The last month of the year actually has only 5 days, but we get that for free from the higher calendar level. We combine the two levels in the flat way.

The calendar levels are very schematically as follows:

  a ════════════════╗
m ─ m₀ ──┐        ║
d ─ d₀ ─(1)─ d₁ ─(2)═ J


#### 16.5.1. From Egyptian Date to CJDN

The calendar levels are schematically as follows:

  a ═════════════════════╗
m ─(−1)─ m₀ ──┐        ║
d ─(−1)─ d₀ ─(1)─ d₁ ─(2)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$
1 30 1 30 0 0 30
2 365 1 365 0 0 365

1. First we subtract 1 from the month number and day number so they begin at 0 instead of 1.

\begin{align*} m_0 \| = m − 1 \\ d_0 \| = d − 1 \end{align*}

2. Transformation 1 combines the month number $$m_0$$ within the year and the day number $$d_0$$ within the month into the day number $$d_1$$ within the year.

$$d_1 = 30 m_0 + d_0$$

3. Transformation 2 combines the year number $$a$$ and the day number $$d_1$$ within the year into the running day number $$s$$.

$$s = 365 a + d_1$$

4. And then we add the CJDN of running day number 0. In the calendar according to the Era of Nabonassar the first day of the first year (1 Thoth of year 1) was equivalent to 26 February −746 in the Julian calendar, i.e., to JD 1448638. To get that we must use $$J_0 = 1448273$$.

$$J = s + J_0 = s + 1448273$$

This condenses to

$$J = 365a + 30m + d + 1448242$$

For example, which CJDN corresponds to day 7 of month 5 of year 218 in the Egyptian calendar? Then we find

\begin{align*} m_0 \| = m − 1 = 5 − 1 = 4 \\ d_0 \| = d − 1 = 7 − 1 = 6 \\ d_1 \| = 30m_0 + d_0 = 30×4 + 6 = 126 \\ s \| = 365a + d_1 = 365×218 + 126 = 79696 \\ J \| = s + 1448273 = 79696 + 1448273 = 1527969 \end{align*}

so the answer is CJDN 1527969. With the condensed formula we find

\begin{align*} J \| = 365a + 30m + d + 1448242 \\ \| = 365×218 + 30×5 + 7 + 1448242 = 1527969 \end{align*}

which is the same answer as before. A few more examples:

$${a}$$ $${m}$$ $${d}$$ $${m_0}$$ $${d_0}$$ $${d_1}$$ $${s}$$ $${J}$$
−1 13 5 12 4 364 −1 1448272
0 1 1 0 0 0 0 1448273
0 13 5 12 4 364 364 1448637
1 1 1 0 0 0 365 1448638
1 1 30 0 29 29 394 1448667
1 2 1 1 0 30 395 1448668
218 5 7 4 6 126 79696 1527969

Transformation 2 has a limit of $$w/365$$ years, which corresponds to $$w$$ days, and a higher one is not possible. For 32-bit numbers this corresponds to about 5.9 million years. A more detailed search (as described in Sec. 15.2.3) shows that for 32-bit numbers the above formulas produce the correct results for CJDN −2'146'035'375 through 2'147'483'647, which corresponds to from somewhere in Egyptian year −5'883'517 to somewhere in year 5'879'548.

#### 16.5.2. From CJDN to Egyptian Date

In the opposite direction, the calculations are simple as well.

The calendar levels are schematically as follows:

  a ═════════════════════╗
m ─(−1)─ m₀ ──┐        ║
d ─(−1)─ d₀ ─(1)─ d₁ ─(2)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$
1 30 1 30 0 0 30
2 365 1 365 0 0 365

1. First we subtract the CJDN $$J_0$$ of running day number 0.

$$s = J − J_0 = s − 1448273$$

2. Transformation 2 deduces from the running day number $$s$$ the year number $$a$$ and the day number $$d_1$$ within the year.

$$\{ a, d_1 \} = \Div(s, 365)$$

3. Transformation 1 deduces from the day number within the year the month number $$m_0$$ within the year and the day number $$d_0$$ within the month.

$$\{ m_0, d_0 \} = \Div(d_1, 30)$$

4. And then we add 1 to the month number and the day number so they begin at 1 instead of at 0.

\begin{align} m \| = m_0 + 1 \\ d \| = d_0 + 1 \end{align}

What date in the Egyptian calendar corresponds to CJDN 1527969? Then

\begin{align*} s \| = J − J_0 = 1527969 − 1448273 = 79696 \\ \{ a, d_1 \} \| = \Div(79696, 365) = \{ 218, 126 \} \\ \{ m_0, d_0 \} \| = \Div(126, 30) = \{4, 6\} \\ m \| = m_0 + 1 = 4 + 1 = 5 \\ d \| = d_0 + 1 = 6 + 1 = 7 \end{align*}

so it is day 7 of month 5 of year 218. A few more examples:

$${J}$$ $${s}$$ $${a}$$ $${d_1}$$ $${m_0}$$ $${d_0}$$ $${m}$$ $${d}$$
1448272 −1 −1 364 12 4 13 5
1448273 0 0 0 0 0 1 1
1448637 364 0 364 12 4 13 5
1448638 365 1 0 0 0 1 1
1448667 394 1 29 0 29 1 30
1448668 395 1 30 1 0 2 1
1527969 79696 218 126 4 6 5 7

Tranformations 1 and 2 yield no extra limitation (for 32-bit numbers) because for them $$f = 1$$. So only the general limitations hold that $$J$$ and $$s$$ must be less than $$w$$ days, which means 5.9 million years.

### 16.6. The Babylonian Calendar

The Metonic Cycle says that 235 (synodical) months are equal to 19 (tropical) years of 12 or 13 months each, with 125 months of 30 days and 110 months of 29 days, so 6940 days in total. The long years (with 13 months) are the 1st, 4th, 7th, 9th, 12th, 15th, and 18th year of each cycle. In the 18th year, month 6 is doubled; in the other long years month 12 is doubled. Day 1 of month 1 (Nisannu) of year 1 of the era of Seleukos corresponds to 3 April −310 in the Julian Calendar, or CJDN 1607558.

The Babylonians determined the beginning of each month by looking for a particular phase of the Moon. They did not give the first month of each year the same number of days, and likewise for the other months, but did vary the number of months in each year according to the method described above. The distribution of months into years ran independently from the distribution of days into months.

If a calendar is (partly) based on direct observations, then it is a bit unpredictable and cannot be completely caught in formulas. The calendar then depends on things like the weather. If there happen to be many clouds in the sky one day, then the calendar officials may not see the moon at all that night, and then the official start of the new month may be delayed until after they see the moon the next night.

We derive a calendar that looks like the one of the Babylonians, but is entirely predictable. The difference with the historical calendar of the Babylonians should be at most 1 day.

That means a calendar with a stepped combination of a calendar level between day and month and a calendar level between month and year. The calculations are schematically as follows:

  a ══╗
m ─(1)═ m₁ ═╗
d ─────────(2)═ J


#### 16.6.1. From Babylonian Date to Julian Day Number

The calculations are schematically as follows:

  a ════════════╗
m ─(−1)─ m₀ ─(1)═ m₁ ═╗
d ─(−1)─ d₀ ─────────(2)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$
1 235 19 12 7 13 12.368421
2 6940 235 29 125 0 29.531915

1. First we subtract 1 from the month number and day number so they begin at 0 instead of 1.

\begin{align*} m_0 \| = m − 1 \\ d_0 \| = d − 1 \end{align*}

2. Transformation 1 calculates from the year number $$a$$ and the month number $$m_0$$ within the year the running month number $$m_1$$.

$$m_1 = \dfloorratio{235a + 13}{19} + m_0 \label{eq:j2μ1}$$

3. Transformation 2 calculations from the running month number $$m_1$$ and the day number $$d_0$$ within the month the running day number $$s$$.

$$s = \dfloorratio{6940m_1}{235} + d_0$$

4. And then we add the CJDN of day 1 of month 1 of year 0.

$$J = s + J_0 = s + 1607175$$

This condenses to

$$J = \dfloorratio{6940\dparen{\dfloorratio{235a + 13}{19} + m − 1}}{235} + d + 1607174$$

For example, which CJDN $$J$$ corresponds to year 3, month 9, day 27 of the era of Seleukos? Then $$a = 3$$, $$m = 9$$, $$d = 27$$, so

\begin{align*} m_0 \| = m − 1 = 9 − 1 = 8 \\ d_0 \| = d − 1 = 27 − 1 = 26 \\ m_1 \| = \dfloorratio{235a + 13}{19} + m_0 = \dfloorratio{235×3 + 13}{19} + 8 = \dfloorratio{718}{19} + 8 = 37 + 8 = 45 \\ s \| = \dfloorratio{6940m_1}{235} + d_0 = \dfloorratio{6940×45}{235} + 26 = \dfloorratio{312300}{235} + 26 = 1328 + 26 = 1354 \\ J \| = s + J_0 = 1354 + 1607175 = 1608529 \end{align*}

Some more examples:

$${a}$$ $${m}$$ $${d}$$ $${m_0}$$ $${d_0}$$ $${m_1}$$ $${s}$$ $${J}$$
0 1 1 0 0 0 0 1607175
1 1 1 0 0 13 383 1607558
3 9 27 8 26 45 1354 1608529
2315 3 1 2 0 28635 845646 2452821

Transformation 1 has a limit of $$w/235$$ years, which corresponds to about $$1.6 w$$ days. Transformation 2 has a limit of $$w/6940$$ months, which corresponds to about $$w/235$$ days, and that is the combined limit. For 32-bit numbers it corresponds to about 25 thousand years. A more detailed search (as described in Sec. 15.2.3) shows that for 32-bit numbers the above formulas produce the correct results for CJDN −7'531'034 through 10'745'402, which corresponds to from somewhere in Herschel year −25'019 to somewhere in year 25'018.

If that is too low for you then you can use 64-bit numbers or increase the range of transformation 2 as described in Sec. 15.2. You can change the formula for $$s$$ to

\begin{eqnarray} \{ ω_1, μ_1 \} \| = \| \Div(m_1, 235) \\ ω_2 \| = \| \dfloorratio{125 μ_1}{235} \\ s \| = \| 29 m_1 + 125 ω_1 + ω_2 + d_0 \end{eqnarray}

This increases the limit to about $$w/29.53$$ months, which corresponds to about $$w$$ days, and a higher limit is not possible. For 32-bit numbers this corresponds to about 5.9 million years.

Here are some examples (with $$d_0 = 0$$) of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${m_1}$$ $${6940 m_1}$$ $${\dfrac{6940 m_1}{w}}$$ $${s}$$ $${ω_1}$$ $${μ_1}$$ $${125 μ_1}$$ $${ω_2}$$ $${s}$$
305000 2116700000 0.99 9007234 1297 205 25625 109 9007234
72000000 499680000000 232.68 2126297872 306382 230 28750 122 2126297872

#### 16.6.2. From CJDN to Babylonian Date

Now we go in the opposite direction, from Julian Day number $$J$$ to day $$d$$, month $$m$$, year $$a$$ in the era of Seleukos.

The calculations are schematically as follows:

  a ════════════╗
m ─(−1)─ m₀ ─(1)═ m₁ ═╗
d ─(−1)─ d₀ ─────────(2)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$
1 235 19 12 7 13 12.368421
2 6940 235 29 125 0 29.531915

1. First we subtract from CJDN $$J$$ of the day of interest the CJDN of day 1 of month 1 of year 0 to find the running day number $$s$$.

$$s = J − J_0 = J − 1607175$$

2. Transformation 2 calculates from the running day number $$s$$ the running month number $$m_1$$ and the day number $$d_0$$ within the month.

\begin{align} \{ m_1, ε_1 \} \| = \Div(235s + 234, 6940) \\ d_0 \| = \dfloorratio{ε_1}{235} \end{align}

3. Transformation 1 produces from the running month number $$m_1$$ the year number $$a$$ and the month number $$m_0$$ within the year.

\begin{align} \{ a, ε_2 \} \| = \Div(19m_1 + 5, 235) \\ m_0 \| = \dfloorratio{ε_2}{19} \end{align}

4. And then we add 1 to the month number $$m_0$$ and day number $$d$$ to have them start at 1 instead of at 0.

\begin{align} m \| = m_0 + 1 \\ d \| = d_0 + 1 \end{align}

This can be condensed to

\begin{align} \{ m_1, ε_1 \} \| = \Div(235J − 377685891, 6940) \\ \{ a, ε_2 \} \| = \Div(19m_1 + 5, 235) \\ m \| = \dfloorratio{ε_2}{19} + 1 \\ d \| = \dfloorratio{ε_1}{235} + 1 \end{align}

For example, which date in the Babylonian calendar corresponds to CJDN 1608529? Then $$J = 1608529$$, so

\begin{align*} s \| = J − J_0 = 1608529 − 1607175 = 1354 \\ \{ m_1, ε_1 \} \| = \Div(235s + 234, 6940) = \Div(235×1354 + 234, 6940) \\ \| = \Div(318424, 6940) = \{ 45, 6124 \} \\ d_0 \| = \dfloorratio{ε_1}{235} = \dfloorratio{6124}{235} = 26 \\ \{ a, ε_2 \} \| = \Div(19m_1 + 5, 235) = \Div(19×45 + 5, 235) = \Div(860, 235) = \{ 3, 155\} \\ m_0 \| = \dfloorratio{155}{19} = 8 \\ m \| = 8 + 1 = 9 \\ d \| = 26 + 1 = 27 \end{align*}

which means day 27 of month 9 of year 3.

In the condensed manner:

\begin{align*} \{ m_1, ε_1 \} \| = \Div(235J − 377685891, 6940) = \Div(235×1608529 − 377685891, 6940) \\ \| = \Div(318424, 6940) = \{ 45, 6124\} \\ \{ a, ε_2 \} \| = \Div(19m_1 + 5, 235) = \Div(19×45 + 5, 235) \\ \| = \Div(860, 235) = \{ 3, 155 \} \\ m \| = \dfloorratio{ε_2}{19} + 1 = \dfloorratio{155}{19} + 1 = 8 + 1 = 9 \\ d \| = \dfloorratio{ε_1}{235} + 1 = \dfloorratio{6124}{235} + 1 = 26 + 1 = 27 \end{align*}

Some more examples:

$${J}$$ $${s}$$ $${m_1}$$ $${ε_1}$$ $${d_0}$$ $${a}$$ $${ε_2}$$ $${m_0}$$ $${m}$$ $${d}$$
1607175 0 0 234 0 0 5 0 1 1
1607558 383 13 19 0 1 17 0 1 1
1608529 1354 45 6124 26 3 155 8 9 27
2452821 845646 28635 144 0 2315 45 2 3 1

Transformation 1 has a limit of $$w/19$$ months, which corresponds to about $$1.6 w$$ days. Transformation 2 has a limit of $$w/235$$ days, and that is the combined limit. For 32-bit numbers it corresponds to about 25 thousand years.

If you want a higher limit then you can use 64-bit numbers or replace transformation 2 with

\begin{eqnarray} \{ ω_3, δ_1 \} \| = \| \Div(s, 6940) \\ \{ μ_1, ε_1 \} \| = \| \Div(235 δ_1 + 234, 6940) \\ m_1 \| = \| 235 ω_3 + μ_1 \\ d_0 \| = \| \dfloorratio{ε_1}{235} \end{eqnarray}

Then the limit becomes $$w$$ days, which is the highest achievable limit. For 32-bit numbers this corresponds to about 5.9 million years.

Here are some examples of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${s}$$ $${235 s + 234}$$ $${\dfrac{235 s + 234}{w}}$$ $${m_1}$$ $${ε_1}$$
9100000 2138500234 1.00 308141 1694
2140000000 502900000234 234.18 72463976 6794

$${s}$$ $${ω_3}$$ $${δ_1}$$ $${235 δ_1 + 234}$$ $${μ_1}$$ $${ε_1}$$ $${m_1}$$
9100000 1311 1660 390334 56 1311 308141
2140000000 308357 2420 568934 81 2997 72463976

### 16.7. The Jewish Calendar

The Jewish calendar is a lunisolar calendar, like the Babylonian calendar. The Jewish calendar is a lot more complicated than the Babylonian one, because

• the Jewish calendar has four rules that can delay the start of a new year, to ensure that certain calendar days do not fall on certain days of the week.

• the calendar year in the Jewish calendar can have six different lengths.

• the Jewish calendar has three different places where a leap day or an embolismic month can be inserted.

• the Jewish New Year does not fall at the beginning of the first month but at the beginning of the seventh month.

A calendar month has 29 or 30 days, a calendar year has 12 or 13 months, and a calendar day begins at 6 o'clock in the evening.

There are 6 different lengths of calendar years, namely 353, 354, 355, 383, 384, or 385 days. The years with 354 or 384 days are called regular. Years with one day more are called complete. Years with a day less are called deficient. Years with 355 or fewer days are called common, and years with more days are called embolismic.

New Year is the day at which the calendar year number increases by one. In the Jewish calendar, this is not the first day of calendar month 1 (Nisan), but the first day of calendar month 7 (Tishri). After calendar month 6 (Elul) of year $$a$$ comes calendar month 7 (Tishri) of year $$a + 1$$. Calendar month 1 (Nisan) comes halfway through the calendar year, not at the beginning.

The extra month (the embolismic month) is inserted between calendar month 11 (Shevat) and calendar month 12 (Adar), which means it is in the middle of the calendar year.

The calculations are very schematically as follows:

  a ═╗ ╔ a₁ ═╦══════════╗
(1)     ╚(2)═ m₂ ╗ ║
m ─┘ └ m₁ ──────────║─║───────┐
d ──────────────────║─║───────│────────┐
(3)⇒ d₁ ═(4)⇒ d₂ ⇔(5)⇒ J


#### 16.7.1. From Jewish Date to CJDN

The calculations are schematically as follows:

  a ═╗ ╔ a₁ ═╦══════════╗
(1)     ╚(2)═ m₂ ╗ ║
m ─┘ └ m₁ ──────────║─║───────┐
d ─(−1)─ d₀ ────────║─║───────│────────┐
[3]⇒ d₁ ═(4)⇒ d₂ ⇔[5]⇒ s ═(+J₀)⇔ J


The calendar levels are

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$
2 235 19 12 7 −234 12.368
3 765433 25920 29 13753 12084 29.531
4 384 13 29 7 10 29.538

As an example we'll calculate the CJDN of the following dates in the Jewish calendar:

$${a}$$ Month $${m}$$ $${d}$$
4524 Tishri 7 30
4524 Kislev 9 30
4527 Sivan 3 1
4682 Kislev 9 12
4682 Sivan 3 18

1. First we subtract 1 from the day number so it begins at 0 instead of 1.

$$d_0 = d − 1$$

For the example dates we find

$${a}$$ $${m}$$ $${d}$$ $${d_0}$$
4524 7 30 29
4524 9 30 29
4527 3 1 0
4682 9 12 11
4682 3 18 17
325709 13 29 28

2. Transformation 1 produces the calculation year and the calculation month.

In some years there is and in other years there isn't an embolismic month between New Year of calendar year $$a − 1$$ and calendar months 1 through 6 of that same calendar year. This makes calculating the day number within the year difficult for those calendar months. It is more convenient for this to move those months to calculation year $$a$$ and to calculate them from New Year of calendar year $$a$$.

So we define calculation year $$a_1$$ and calculation month $$m_1$$. We assign calculation month number 0 to the month holding New Year (Tishri, calendar month 1) because we do all associated calculations relative to New Year.

\begin{align} m_1 \| = m − 7 \\ a_1 \| = a − \dfloorratio{m − 7}{10} = a − \dfloorratio{m_1}{10} \end{align}

Then we get

$${a}$$ $${m}$$ $${a_1}$$ $${m_1}$$
0 12 0 5
0 13 0 6
0 1 1 −6
0 2 1 −5
0 3 1 −4
0 4 1 −3
0 5 1 −2
0 6 1 −1
1 7 1 0
1 8 1 1
1 9 1 2
1 10 1 3
1 11 1 4
1 12 1 5
1 1 2 −6
1 2 2 −5

For the example dates we find

$${a}$$ $${m}$$ $${d}$$ $${a_1}$$ $${m_1}$$ $${d_0}$$
4524 7 30 4524 0 29
4524 9 30 4524 2 29
4527 3 1 4528 −4 0
4682 9 12 4682 2 11
4682 3 18 4683 −4 17
325709 13 29 325709 6 28

3. Transformation 2 yields running month number $$m_2$$ of New Year of calculation year $$a_1$$. New Year of calculation year $$a_1$$ is equal to New Year of the calendar year with that same number.

$$m_2 = \dfloorratio{235 a_1 − 234}{19}$$

For new year of Jewish year 4682 ($$a_1 = 4682$$) we find

\begin{align*} m_2 \| = \dfloorratio{235 a_1 − 234}{19} = \dfloorratio{235×4682 − 234}{19} \\ \| = \dfloorratio{1100036}{19} = 57896 \end{align*}

so New Year of year 4682 is 57896 months after New Year of year 1.

For the example dates we find

$${a}$$ $${m}$$ $${a_1}$$ $${m_2}$$
4524 7 4524 55942
4524 9 4524 55942
4527 3 4528 55991
4682 9 4682 57896
4682 3 4683 57909
325709 13 325709 4028493

4. Transformation 3 provides the running day number $$d_1$$ of New Year of calculation year $$a_1$$. That is identical to the running day number of New Year of the calendar year with that same number. This is a complicated calculation that depends not just on that year but also on the previous and following years.

The epoch of the calendar (the beginning of 1 Tishri of year 1) is at 6 o'clock at night on Sunday 6 October −3760 in the Julian proleptic calendar, which corresponds to CJD 347997.75. For correspondences between calendar dates from different calendars we look at the situation at noon. Noon of the first day (New Year) of the Jewish calendar was on Monday 7 October −3760 in the Julian proleptic calendar (CJDN 347998 = $$J_0$$).

The beginning of New Year's day is determined by the mean conjunction between the Sun and the Moon, where the length of a synodical month is set at 29 and 13753/25920 days, which is 765433/25920 days. The New Moon at the beginning of the month of Tishri (the New Year's month) of year 1 was at 5 hours, 11 minutes, and 20 seconds (= 5604/25920 days) after the beginning of the first day of that month (and that began at 6 o'clock at night).

The time $$δ_1$$ in days that elapsed since the beginning of the first day of the calendar and the New Moon at the beginning of the month with running month number $$m_2$$ is equal to

$$δ_1 = \dfrac{765433 m_2 + 5604}{25920} \label{eq:μ}$$

The running day number $$δ_2$$ of the calendar day on which that New Moon occurs is

$$δ_2 = \dfloor{δ_1} = \dfloorratio{765433 m_2 + 5604}{25920}$$

We again look at New Year of the Jewish year 4682. We earlier found that $$m_2 = 57896$$. Then

\begin{align*} δ_1 \| = \dfrac{765433 m_2 + 5604}{25920} = \dfrac{765433×57896 + 5604}{25920} \\ \| = \frac{44315514572}{25920} = 1709703 + \frac{12812}{25920} \\ δ_2 \| = \dfloorratio{765433 m_2 + 5604}{25920} = \dfloorratio{765433×57896 + 5604}{25920} \\ \| = \dfloorratio{44315514572}{25920} = 1709703 \end{align*}

Note that the greatest intermediate result 44'315'514'572 is far too great to be a 32-bit number.

For the example dates we find

$${a}$$ $${m}$$ $${d}$$ $${a_1}$$ $${m_2}$$ $${δ_2}$$
4524 7 30 4524 55942 1652000
4524 9 30 4524 55942 1652000
4527 3 1 4528 55991 1653447
4682 9 12 4682 57896 1709703
4682 3 18 4683 57909 1710087
325709 13 29 325709 4028493 118963791

Now we adjust the provisionary running day number $$δ_2$$ for four possible delays.

1. The first delay occurs when the mean conjunction falls at or after noon and before the end of the calendar day at 6 o'clock at night. In that case, New Year is delayed by 1 day, the current year gets 1 day shorter, and the preceding year gets 1 day longer.

The time of day follows from $$\dmod{δ_1}{1}$$, which is equal to 0 at the beginning of the calendar day at 6 o'clock at night, and is equal to 3/4 at noon. So if $$\dmod{δ_1}{1} ≥ 3/4$$, then New Year is delayed by one day. If $$\dmod{δ_1}{1} ≥ 3/4$$ then $$\dmod{δ_1}{1} + 1/4 ≥ 1$$ so $$\dfloor{δ_2 + \frac{1}{4}} = δ_2 + 1$$, so the running day number $$δ_3$$ of the first day of the month, including the effect of the first delay, is

$$δ_3 = \dfloor{δ_1 + \frac{1}{4}} = \dfloorratio{765433 m_2 + 12084}{25920} \label{eq:υ_1}$$

For year 4682 we find

\begin{align*} δ_3 \| = \dfloorratio{765433 m_2 + 12084}{25920} = \dfloorratio{765433×57896 + 12084}{25920} \\ \| = \dfloorratio{44315521052}{25920} = 1709703 = δ_2 \end{align*}

so that year's beginning is unaffected by the first delay.

For the example dates we find

$${a}$$ $${m}$$ $${d}$$ $${a_1}$$ $${m_2}$$ $${δ_2}$$ $${δ_3}$$
4524 7 30 4524 55942 1652000 1652000
4524 9 30 4524 55942 1652000 1652000
4527 3 1 4528 55991 1653447 1653447
4682 9 12 4682 57896 1709703 1709703
4682 3 18 4683 57909 1710087 1710087
325709 13 29 325709 4028493 118963791 118963792

so from these examples only New Year of year 325709 is affected by the first delay.

2. The second delay occurs when the mean conjunction (after taking into account the first delay) falls on a Sunday, Wednesday, or Friday. In that case, New Year is delayed by 1 day, the current year gets one day shorter, and the preceding year gets one day longer.

$$δ_2 = δ_3 = 0$$ corresponds to CJDN 347998 which was a Monday, because $$\dmod{347998}{7} = 0$$ and 0 corresponds to Monday. The second delay occurs when

$$δ_4 = \dmod{δ_3}{7}$$

is equal to 2, 4, or 6.

We seek a formula that returns 0 if $$δ_4$$ is equal to 0, 1, 3, or 5, and that returns 1 if $$δ_4$$ is equal to 2, 4, or 6. Because we only want 0 or 1 to be returned, something involving $$\dmod{·}{2}$$ seems to be needed. That we only want whole numbers as results points at something looking like $$\dmod{⌊...δ_4...⌋}{2}$$. The simplest formula that might work is then $$\dmod{⌊kδ_4⌋}{2}$$ for a suitable factor $$k$$. Some searching shows that we get the desired outcomes when $$5/6 \lt k \lt 1$$. A few ratios with small denominators that are suitable for $$k$$ are 6/7, 7/8, 8/9, 9/10, 10/11, 11/12. The ratio with denominator 7 has the smallest denominator and has as additional bonus that it returns the desired values also if one calculates $$\dmod{⌊k δ_3⌋}{2}$$ instead of $$\dmod{⌊k\dmod{δ_3}{7}⌋}{2}$$: that saves one modulus calculation. With that, the running day number $$δ_5$$ of the first day of the month, including the first two delays, is equal to

$$δ_5 = δ_3 + \dmod{\dfloorratio{6 δ_3}{7}}{2} \label{eq:υ_2}$$

3. The third delay is needed if a year, after treatment of the first two delays, would get a length of 356 days, which is deemed unacceptably long. By delaying New Year by 2 days, the length of the year is reduced to 354 days, which is acceptable. The preceding year (which was 353 or 383 days long) then gets 2 days longer (i.e., 355 or 385 days).

The length $$L_2(a_1)$$ of calculation year $$a_1$$ (including the effects of the first two delays) is equal to

$$L_2(a_1) = δ_5(a_1 + 1) − δ_5(a_1)$$

so New Year of year $$a_1$$ is delayed by 2 days if $$L_2(a_1) = 356$$. We achieve the desired effect with formula

$$δ_6 = 2\dmod{\dfloorratio{L_2 + 19}{15}}{2}$$

$${L_2}$$ $${δ_6}$$
353 0
354 0
355 0
356 2
382 0
383 0
384 0
385 0

4. The fourth delay is needed when the preceding year (after treatment of the first two delays) would get a length of 382 days, which is deemed unacceptably short. By delaying New Year of the current year by 1 day the preceding year becomes 383 days long, which is acceptable. The current year (which was 355 days long) then gets one day shorter (i.e., 354 days).

So, New Year of calculation year $$a_1$$ is delayed by 1 day when $$L_2(a_1 − 1) = 382$$. We get the desired effect with formula

$$δ_7 = \dmod{\dfloorratio{L_2(a_1 − 1) + 7}{15}}{2}$$

$${L_2}$$ $${δ_7}$$
353 0
354 0
355 0
356 0
382 1
383 0
384 0
385 0

so the running day number $$d_1$$ of New Year, taking into account all four delays, is

\begin{align} m_2(a_1) \| = \dfloorratio{235 a_1 − 234}{19} \\ δ_3(a_1) \| = \dfloorratio{765433 m_2(a_1) + 12084}{25920} \\ δ_5(a_1) \| = δ_3(a_1) + \dmod{\dfloorratio{6 δ_3(a_1)}{7}}{2} \\ L_2(a_1) \| = δ_5(a_1 + 1) − δ_5(a_1) \\ d_1(a_1) \| = δ_5(a_1) + 2\dmod{\dfloorratio{L_2(a_1) + 19}{15}}{2} + \dmod{\dfloorratio{L_2(a_1 − 1) + 7}{15}}{2} \notag \\ \| = δ_5(a_1) + 2\dmod{\dfloorratio{δ_5(a_1 + 1) − δ_5(a_1) + 19}{15}}{2} \notag \\ \| + \dmod{\dfloorratio{δ_5(a_1) − δ_5(a_1 − 1) + 7}{15}}{2} \end{align}

Note that to calculate $$d_1$$ for year $$a_1$$ requires the values of $$δ_5(a_1 − 1)$$, $$δ_5(a_1)$$, and $$δ_5(a_1 + 1)$$.

We now know the running day number $$d_1$$ of New Year (1 Tishri) of calculation year $$a_1$$, which is the same as the running day number of New Year of the calculation year with that same numer.

The length $$L$$ of calculation year $$a_1$$ (and of the calendar year with that same number) is then equal to

$$L = d_1(a_1 + 1) − d_1(a_1)$$

For the calculation of $$L$$ of year $$a_1$$ you need $$δ_5$$ for the 4 years $$a_1 − 1$$ through $$a_1 + 2$$.

Years do not exist for which $$L_2(a_1) = 356$$ and at the same time $$L_2(a_1 − 1) = 382$$, so the third and fourth delays are never active at the same time.

Some month lengths depend on the length of the year. With all delays taken into account, years can only have the following lengths $$L$$: 353, 354, 355, 383, 384, or 385 days.

For $$a_1 = 4682$$ we found earlier that $$δ_2 = 1709703$$. Equation \eqref{eq:υ_1} then yields $$δ_3 = 1709703 = δ_2$$, so the first delay does not affect that year. Equation \eqref{eq:υ_2} yields

\begin{align*} δ_5 \| = δ_3 + \dmod{\dfloorratio{6δ_3}{7}}{2} \\ \| = 1709703 + \dmod{\dfloorratio{6×1709703}{7}}{2} \\ \| = 1709703 + \dmod{\dfloorratio{10258218}{7}}{2} \\ \| = 1709703 + \dmod{1465459}{2} = 1709703 + 1 = 1709704 \end{align*}

so the second delay does have effect. The length of year $$a_1 = 4682$$ taking into account the first two delays is $$L_2(4682) = δ_5(4683) − δ_5(4682) = 1710087 − 1709704 = 383$$ days. The year with $$a_1 = 4683$$ therefore has a length (taking into account the first two delays) of 356 days, so the third delay applies, and New Year of that year is delayed by 2 days. The results for this and some other years are listed in the following table. The column with title "v" mentions the numbers of the delays that applied.

Some more examples:

$${a_1}$$ $${δ_2}$$ $${δ_3}$$ $${δ_5}$$ $${L_2}$$ $${δ_6}$$ $${δ_7}$$ $${d_1}$$ $${L}$$ v
−1 −739 −738 −737 353 0 0 −737 353 1,2
0 −384 −384 −384 384 0 0 −384 384
1 0 0 0 355 0 0 0 355
2 354 354 355 355 0 0 355 355 2
4523 1651646 1651646 1651646 354 0 0 1651646 354
4524 1652000 1652000 1652000 355 0 0 1652000 355
4525 1652355 1652355 1652355 385 0 0 1652355 385
4526 1652738 1652739 1652740 353 0 0 1652740 353 1,2
4527 1653093 1653093 1653093 354 0 0 1653093 354
4528 1653447 1653447 1653447 385 0 0 1653447 385
4681 1709349 1709349 1709349 355 0 0 1709349 355
4682 1709703 1709703 1709704 383 0 0 1709704 385 2
4683 1710087 1710087 1710087 356 2 0 1710089 354 3
4684 1710441 1710442 1710443 353 0 0 1710443 353 1,2
5517 2014695 2014695 2014696 355 0 0 2014696 355 2
5518 2015049 2015050 2015051 382 0 0 2015051 383 1,2
5519 2015433 2015433 2015433 355 0 1 2015434 354 4
5520 2015788 2015788 2015788 355 0 0 2015788 355
325708 118963437 118963437 118963437 355 0 0 118963437 355
325709 118963791 118963792 118963792 385 0 0 118963792 385 1
325710 118964175 118964176 118964177 354 0 0 118964177 354 1,2
325711 118964530 118964530 118964531 353 0 0 118964531 353 2

The first delay depends on the time of day, and the second delay depends on the day of the week, so those two delays combined depend on the time since the beginning of the week. The leap years depend on the position of the year in the current cycle of 19 years = 235 months. The calendar as a whole repeats itself when a whole number of weeks coincides with a whole number of leap cycles. The leap cycle has a length of 235×765'433/25920 = 35'975'351/5184 days, so each period of 5184 cycles covers a whole number of days, namely 35'975'351. This number of days is not a multiple of 7, so the calendar only repeats itself after 7×35'975'351 = 251'827'457 days = 35'975'351 weeks = 689'472 years = 8'527'680 months.

The distribution of the calendar year lengths in that period of 689'472 years is listed in the following table, including how many of those years have that length if you take into account different delays.

$${L}$$ $${δ_2}$$ $${δ_3}$$ $${δ_5}$$ $${δ_6}$$ $${d_1}$$
353 78'738 69'222 69'222
354 275'583 275'583 140'946 163'785 167'497
355 159'873 159'873 192'933 202'449 198'737
356 22'839
382 3712 3712
383 25'984 25'984 116'288 102'965 106'677
384 228'032 228'032 36'288 36'288 36'288
385 97'728 111'051 111'051

The next table shows of how many years from that big cycle of 689'472 years the New Year is affected by the delays mentioned in the column with title "v".

v
 #       
    % 
    − 
268'937 39.0
1 172'368 25.0
2 295'488 42.9
3 22'839 3.3
4 3712 0.5
1+2 73'872 10.7
rest 0 0

New Year can be delayed by both the first and second delays, but not by any other combination of more than one delay.

The next table shows how many years there can be between two successive cases of a certain combination of delays. For example, the time between two New Years that are both delayed by only the 2nd delay varies between 1 and 7 years with an average of 2.33 years.

v min max average
   - 
1 7 2.56
1 1 16 4.00
2 1 7 2.33
3 7 71 30.19
4 78 345 185.73
1+2 3 53 9.33

The next table shows how often a year with a certain length follows a year with that same or another length. The columns are for the current year, and the rows are for the following year. For example, that a year of 354 days is followed by a year of 383 days occurs 40'000 times in the great cycle of 689'472 years.

353 354 355 383 384 385
353 0 16'404 16'404 0 0 36'414
354 13'776 0 54'468 53'354 0 45'899
355 9516 54'491 16'381 53'323 36'288 28'738
383 0 40'000 66'677 0 0 0
384 29'965 0 13'323 0 0 0
385 22'965 56'602 31'484 0 0 0

5. Transformation 4 produces the running day number $$d_2$$ of the first day of calculation month $$m_1$$ from that month number and from running day number $$d_1$$ of New Year.

The month lengths are as follow, in years with different lengths:

Name 353 354 355 383 384 385
Nisan 30 30 30 30 30 30
Iyar 29 29 29 29 29 29
Sivan 30 30 30 30 30 30
Tammuz 29 29 29 29 29 29
Av 30 30 30 30 30 30
Elul 29 29 29 29 29 29
Tishri 30 30 30 30 30 30
Ḥeshvan 29 29 30 29 29 30
Kislev 29 30 30 29 30 30
Tevet 29 29 29 29 29 29
Shevat 30 30 30 30 30 30
Adar (Ⅱ) 29 29 29 29 29 29

In a year of 13 months, the embolismic (extra) month Adar Ⅰ is inserted between Shevat and the original Adar, which is then renamed to Adar Ⅱ.

The lengths of the months do not fit a simple calendar level (of types 1 or 2 from Sec. 15.11), because for such a calendar level the count of months in each successive group with the same month length varies by not more than one, and that isn't always the case here. Here that count of months is usually equal to 1, sometimes equal to 2 (for Shevat and Adar Ⅰ in an embolismic year), but also sometimes equal to 3 (for Ḥeshvan through Tevet in a deficient year of 353 or 383 days long, and for Tishri through Kislev in a complete year of 355 or 384 days).

The lengths that the months have in a year of 384 days long fit the equation

$$δ_8 = \dfloorratio{384 m_1 + 10}{13}$$

where $$m_1$$ is the calculation month number, and $$δ_8$$ is the day number of the first day of that month since the first day of most recent month 1. Note: In a regular year of 12 months we assign month Adar calendar month number $$m = 12$$ and calculation month number $$m_1 = 5$$ but in an embolismic year of 13 months we assign Adar (which is then called Adar Ⅱ) calendar month number $$m = 13$$ and calculation month number $$m_1 = 6$$.

$${m}$$ $${m_1}$$ $${δ_8}$$ $${∆δ_8}$$
1 −6 −177 30
2 −5 −147 29
3 −4 −118 30
4 −3 −88 29
5 −2 −59 30
6 −1 −29 29
7 0 0 30
8 1 30 29
9 2 59 30
10 3 89 29
11 4 118 30
12 5 148 30
13 6 178 29
14 7 207

This formula can also be used for month lengths in a common regular year of 354 days, when the length of the year terminates the 12th calendar month ($$m = 12$$, $$m_1 = 5$$) at 29 days.

A correction to this formula is needed for years with a length $$L$$ unequal to 354 or 384 days. In a deficient year with 353 or 383 days, month 9 must be one day shorter. In a complete year with 355 or 385 days, month 8 must be one day longer. The corrections $$δ_9$$ for month 8 and $$δ_{10}$$ for month 9 as a function of year length $$L$$ are

$${L}$$ $${δ_9}$$ $${δ_{10}}$$
353 0 −1
354 0 0
355 1 0
383 0 −1
384 0 0
385 1 0

We find the following formulas for these corrections:

\begin{align} δ_9 \| = \dmod{\dfloorratio{L + 1}{2}}{3} \\ δ_{10} \| = −\dmod{\dfloorratio{385 − L}{2}}{3} \end{align}

The $$δ_9$$ correction applies to the beginning of calculation months 2 through 6, and the $$δ_{10}$$ correction to dates in calculation months 3 through 6. In the following table, $$ω_2$$ shows (with value 1) to which months the $$δ_9$$ correction applies, and $$ω_3$$ likewise for the $$δ_{10}$$ correction.

$${m}$$ $${m_1}$$ $${ω_2}$$ $${ω_3}$$
1 −6 0 0
2 −5 0 0
3 −4 0 0
4 −3 0 0
5 −2 0 0
6 −1 0 0
7 0 0 0
8 1 0 0
9 2 1 0
10 3 1 1
11 4 1 1
12 5 1 1
13 6 1 1

We get that using the equations

\begin{align} ω_2 \| = \dfloorratio{m_1 + 10}{12} \\ ω_3 \| = \dfloorratio{m_1 + 9}{12} \end{align}

With that, the formula to go from calculation month $$m_1$$ to day number $$δ_{11}$$ of the first day of that month since New Year ($$m_1 = 0$$)

\begin{align} δ_{11} \| = δ_8 + ω_2 δ_9 + ω_3 δ_{10} \notag \\ \| = \dfloorratio{384 m_1 + 10}{13} + \dmod{\dfloorratio{L + 1}{2}}{3} \dfloorratio{m_1 + 10}{12} \notag \\ \| − \dmod{\dfloorratio{385 − L}{2}}{3} \dfloorratio{m_1 + 9}{12} \end{align}

For month Kislev ($$m_1 = 2$$) of calculation year 4682 (that has $$L = 385$$) we find

\begin{align*} δ_8 \| = \dfloorratio{384 m_1 + 10}{13} = \dfloorratio{384×2 + 10}{13} = \dfloorratio{778}{13} = 59 \\ δ_9 \| = \dmod{\dfloorratio{L + 1}{2}}{3} = \dmod{\dfloorratio{386}{2}}{3} = \dmod{193}{3} = 1 \\ δ_{10} \| = −\dmod{\dfloorratio{385 − L}{2}}{3} = −\dmod{\dfloorratio{385 − 385}{2}}{3} = 0 \\ ω_2 \| = \dfloorratio{m_1 + 10}{12} = \dfloorratio{2 + 10}{12} = \dfloorratio{12}{12} = 1 \\ ω_3 \| = \dfloorratio{m_1 + 9}{12} = \dfloorratio{2 + 9}{12} = \dfloorratio{11}{12} = 0 \\ δ_{11} \| = δ_8 + ω_2 δ_9 + ω_3 δ_{10} = 59 + 1×1 − 0×0 = 60 \end{align*}

For the example dates we find

$${a}$$ $${m}$$ $${d}$$ $${a_1}$$ $${m_1}$$ $${δ_8}$$ $${L}$$ $${δ_9}$$ $${δ_{10}}$$ $${ω_2}$$ $${ω_3}$$ $${δ_{11}}$$
4524 7 30 4524 0 0 355 1 0 0 0 0
4524 9 30 4524 2 59 355 1 0 1 0 60
4527 3 1 4528 −4 −118 385 1 0 0 0 −118
4682 9 12 4682 2 59 385 1 0 1 0 60
4682 3 18 4683 −4 −118 354 0 0 0 0 −118
325709 13 29 325709 6 178 385 1 0 1 1 179

With that, the running day number $$d_2$$ of the first day of calculation month $$m_1$$ of calculation year $$a_1$$, measured since 1 Tishri of calendar year 1, is

$$d_2 = δ_{12} + δ_{11} = d_1(a_1) + δ_{11} \label{eq:jewishd2}$$

For month Kislev of calendar year $$a = 4682$$ we find $$a_1 = a = 4682$$ so

$d_2 = d_1(4682) + δ_{11} = 1709704 + 60 = 1709764$

For the example dates we find

$${a}$$ $${m}$$ $${d}$$ $${a_1}$$ $${m_1}$$ $${d_1}$$ $${δ_{11}}$$ $${d_2}$$
4524 7 30 4524 0 1652000 0 1652000
4524 9 30 4524 2 1652000 60 1652060
4527 3 1 4528 −4 1653447 −118 1653329
4682 9 12 4682 2 1709704 60 1709764
4682 3 18 4683 −4 1710089 −118 1709971
325709 13 29 325709 6 118963792 179 118963971

6. Transformation 5 produces the running day number $$s$$ of the date of interest from the running day number $$d_2$$ of the first day of calendar month $$m$$ of calendar year $$a$$ and the day number $$d_0$$ within the month:

$$s = d_2 + d_0$$

For day 12 of Kislev 4682 we find

$s = 1709764 + 11 = 1709775$

For the example dates we find

$${a}$$ $${m}$$ $${d}$$ $${d_0}$$ $${d_2}$$ $${s}$$
4524 7 30 29 1652000 1652029
4524 9 30 29 1652060 1652089
4527 3 1 0 1653329 1653329
4682 9 12 11 1709764 1709775
4682 3 18 17 1709971 1709988
325709 13 29 28 118963971 118963999

7. The epoch of the calendar is 1 Tishri of calendar year 1 and corresponds to CJDN 347'998 = $$J_0$$. So, the CJDN $$J$$ of the desired date is

$$J = s + J_0 = s + 347998$$

For day 12 of Kislev 4682 we find

$J = 1709775 + 347998 = 2057773$

so the CJDN that corresponds to 12 Kislev 4682 is 2'057'773.

For the example dates we find

$${a}$$ $${m}$$ $${d}$$ $${s}$$ $${J}$$
4524 7 30 1652029 2000027
4524 9 30 1652089 2000087
4527 3 1 1653329 2001327
4682 9 12 1709775 2057773
4682 3 18 1709988 2057986
325709 13 29 118963999 119311997

The following table shows some examples of the entire calculation. The table would be very wide, so it has been split.

$${a}$$ $${m}$$ $${d}$$ $${a_1}$$ $${m_1}$$ $${d_0}$$ $${m_2(a_1−1)}$$ $${m_2(a_1)}$$ $${m_2(a_1+1)}$$ $${m_2(a_1+2)}$$
1 1 1 2 −6 0 0 12 24 37
1 6 29 2 −1 28 0 12 24 37
2 7 1 2 0 0 0 12 24 37
2 12 29 2 5 28 0 12 24 37
2 1 1 3 −6 0 12 24 37 49
2 6 29 3 −1 28 12 24 37 49
3 7 1 3 0 0 12 24 37 49
3 10 1 3 3 0 12 24 37 49
1000 10 10 1000 3 9 12343 12356 12368 12380
1000 12 29 1000 5 28 12343 12356 12368 12380
1001 1 1 1002 −6 0 12368 12380 12393 12405
3767 6 29 3768 −1 28 46579 46591 46604 46616
3768 7 1 3768 0 0 46579 46591 46604 46616
4524 7 30 4524 0 29 55930 55942 55954 55967
4524 9 30 4524 2 29 55930 55942 55954 55967
4527 3 1 4528 −4 0 55979 55991 56004 56016
4682 9 12 4682 2 11 57884 57896 57909 57921
4682 13 29 4682 6 28 57884 57896 57909 57921
4682 1 1 4683 −6 0 57896 57909 57921 57933
4682 3 18 4683 −4 17 57896 57909 57921 57933
4682 6 29 4683 −1 28 57896 57909 57921 57933
4683 7 1 4683 0 0 57896 57909 57921 57933
4683 12 29 4683 5 28 57896 57909 57921 57933
4683 1 1 4684 −6 0 57909 57921 57933 57946
325709 13 29 325709 6 28 4028481 4028493 4028506 4028518

$${a}$$ $${m}$$ $${d}$$ $${a_1}$$ $${δ_3(a_1−1)}$$ $${δ_3(a_1)}$$ $${δ_3(a_1+1)}$$ $${δ_3(a_1+2)}$$
1 1 1 2 0 354 709 1093
1 6 29 2 0 354 709 1093
2 7 1 2 0 354 709 1093
2 12 29 2 0 354 709 1093
2 1 1 3 354 709 1093 1447
2 6 29 3 354 709 1093 1447
3 7 1 3 354 709 1093 1447
3 10 1 3 354 709 1093 1447
1000 10 10 1000 364496 364880 365234 365589
1000 12 29 1000 364496 364880 365234 365589
1001 1 1 1002 365234 365589 365973 366327
3767 6 29 3768 1375506 1375860 1376244 1376598
3768 7 1 3768 1375506 1375860 1376244 1376598
4524 7 30 4524 1651646 1652000 1652355 1652739
4524 9 30 4524 1651646 1652000 1652355 1652739
4527 3 1 4528 1653093 1653447 1653831 1654186
4682 9 12 4682 1709349 1709703 1710087 1710442
4682 13 29 4682 1709349 1709703 1710087 1710442
4682 1 1 4683 1709703 1710087 1710442 1710796
4682 3 18 4683 1709703 1710087 1710442 1710796
4682 6 29 4683 1709703 1710087 1710442 1710796
4683 7 1 4683 1709703 1710087 1710442 1710796
4683 12 29 4683 1709703 1710087 1710442 1710796
4683 1 1 4684 1710087 1710442 1710796 1711180
325709 13 29 325709 118963437 118963792 118964176 118964530

$${a}$$ $${m}$$ $${d}$$ $${a_1}$$ $${m_1}$$ $${d_0}$$ $${δ_5(a_1−1)}$$ $${δ_5(a_1)}$$ $${δ_5(a_1+1)}$$ $${δ_5(a_1+2)}$$
1 1 1 2 −6 0 0 355 710 1093
1 6 29 2 −1 28 0 355 710 1093
2 7 1 2 0 0 0 355 710 1093
2 12 29 2 5 28 0 355 710 1093
2 1 1 3 −6 0 355 710 1093 1447
2 6 29 3 −1 28 355 710 1093 1447
3 7 1 3 0 0 355 710 1093 1447
3 10 1 3 3 0 355 710 1093 1447
1000 10 10 1000 3 9 364497 364880 365235 365589
1000 12 29 1000 5 28 364497 364880 365235 365589
1001 1 1 1002 −6 0 365235 365589 365974 366327
3767 6 29 3768 −1 28 1375507 1375860 1376245 1376599
3768 7 1 3768 0 0 1375507 1375860 1376245 1376599
4524 7 30 4524 0 29 1651646 1652000 1652355 1652740
4524 9 30 4524 2 29 1651646 1652000 1652355 1652740
4527 3 1 4528 −4 0 1653093 1653447 1653832 1654187
4682 9 12 4682 2 11 1709349 1709704 1710087 1710443
4682 13 29 4682 6 28 1709349 1709704 1710087 1710443
4682 1 1 4683 −6 0 1709704 1710087 1710443 1710796
4682 3 18 4683 −4 17 1709704 1710087 1710443 1710796
4682 6 29 4683 −1 28 1709704 1710087 1710443 1710796
4683 7 1 4683 0 0 1709704 1710087 1710443 1710796
4683 12 29 4683 5 28 1709704 1710087 1710443 1710796
4683 1 1 4684 −6 0 1710087 1710443 1710796 1711181
325709 13 29 325709 6 28 118963437 118963792 118964177 118964531

$${a}$$ $${m}$$ $${d}$$ $${a_1}$$ $${m_1}$$ $${d_0}$$ $${L_2(a_1−1)}$$ $${L_2(a_1)}$$ $${L_2(a_1+1)}$$ $${d_1(a_1)}$$ $${d_1(a_1+1)}$$ $${L}$$
1 1 1 2 −6 0 355 355 383 355 710 355
1 6 29 2 −1 28 355 355 383 355 710 355
2 7 1 2 0 0 355 355 383 355 710 355
2 12 29 2 5 28 355 355 383 355 710 355
2 1 1 3 −6 0 355 383 354 710 1093 383
2 6 29 3 −1 28 355 383 354 710 1093 383
3 7 1 3 0 0 355 383 354 710 1093 383
3 10 1 3 3 0 355 383 354 710 1093 383
1000 10 10 1000 3 9 383 355 354 364880 365235 355
1000 12 29 1000 5 28 383 355 354 364880 365235 355
1001 1 1 1002 −6 0 354 385 353 365589 365974 385
3767 6 29 3768 −1 28 353 385 354 1375860 1376245 385
3768 7 1 3768 0 0 353 385 354 1375860 1376245 385
4524 7 30 4524 0 29 354 355 385 1652000 1652355 355
4524 9 30 4524 2 29 354 355 385 1652000 1652355 355
4527 3 1 4528 −4 0 354 385 355 1653447 1653832 385
4682 9 12 4682 2 11 355 383 356 1709704 1710089 385
4682 13 29 4682 6 28 355 383 356 1709704 1710089 385
4682 1 1 4683 −6 0 383 356 353 1710089 1710443 354
4682 3 18 4683 −4 17 383 356 353 1710089 1710443 354
4682 6 29 4683 −1 28 383 356 353 1710089 1710443 354
4683 7 1 4683 0 0 383 356 353 1710089 1710443 354
4683 12 29 4683 5 28 383 356 353 1710089 1710443 354
4683 1 1 4684 −6 0 356 353 385 1710443 1710796 353
325709 13 29 325709 6 28 355 385 354 118963792 118964177 385

$${a}$$ $${m}$$ $${d}$$ $${a_1}$$ $${m_1}$$ $${d_0}$$ $${δ_8}$$ $${δ_9}$$ $${δ_{10}}$$ $${ω_2}$$ $${ω_3}$$ $${δ_{11}}$$ $${d_2}$$ $${s}$$ $${J}$$
1 1 1 2 −6 0 −177 1 0 0 0 −177 178 178 348176
1 6 29 2 −1 28 −29 1 0 0 0 −29 326 354 348352
2 7 1 2 0 0 0 1 0 0 0 0 355 355 348353
2 12 29 2 5 28 148 1 0 1 1 149 504 532 348530
2 1 1 3 −6 0 −177 0 −1 0 0 −177 533 533 348531
2 6 29 3 −1 28 −29 0 −1 0 0 −29 681 709 348707
3 7 1 3 0 0 0 0 −1 0 0 0 710 710 348708
3 10 1 3 3 0 89 0 −1 1 1 88 798 798 348796
1000 10 10 1000 3 9 89 1 0 1 1 90 364970 364979 712977
1000 12 29 1000 5 28 148 1 0 1 1 149 365029 365057 713055
1001 1 1 1002 −6 0 −177 1 0 0 0 −177 365412 365412 713410
3767 6 29 3768 −1 28 −29 1 0 0 0 −29 1375831 1375859 1723857
3768 7 1 3768 0 0 0 1 0 0 0 0 1375860 1375860 1723858
4524 7 30 4524 0 29 0 1 0 0 0 0 1652000 1651999 1999997
4524 9 30 4524 2 29 59 1 0 1 0 60 1652060 1652089 2000087
4527 3 1 4528 −4 0 −118 1 0 0 0 −118 1653329 1653329 2001327
4682 9 12 4682 2 11 59 1 0 1 0 60 1709764 1709775 2057773
4682 13 29 4682 6 28 178 1 0 1 1 179 1709883 1709911 2057909
4682 1 1 4683 −6 0 −177 0 0 0 0 −177 1709912 1709912 2057910
4682 3 18 4683 −4 17 −118 0 0 0 0 −118 1709971 1709988 2057986
4682 6 29 4683 −1 28 −29 0 0 0 0 −29 1710060 1710088 2058086
4683 7 1 4683 0 0 0 0 0 0 0 0 1710089 1710089 2058087
4683 12 29 4683 5 28 148 0 0 1 1 148 1710237 1710265 2058263
4683 1 1 4684 −6 0 −177 0 −1 0 0 −177 1710266 1710266 2058264
325709 13 29 325709 6 28 178 1 0 1 1 179 118963971 118963999 119311997

The preceding calculations condense to

\begin{align} m_1 \| = m − 7 \\ a_1 \| = a − \dfloorratio{m_1}{10} \\ δ_3(a_1) \| = \dfloorratio{765433 \dfloorratio{235 a_1 − 234}{19} + 12084}{25920} \\ δ_5(a_1) \| = δ_3(a_1) + \dmod{\dfloorratio{6 δ_3(a_1)}{7}}{2} \\ L_2(a_1) \| = δ_5(a_1 + 1) − δ_5(a_1) \\ d_1(a_1) \| = δ_5(a_1) + 2\dmod{\dfloorratio{L_2(a_1) + 19}{15}}{2} + \dmod{\dfloorratio{L_2(a_1 − 1) + 7}{15}}{2} \\ L \| = d_1(a_1 + 1) − d_1(a_1) \\ d_2 \| = d_1(a_1) + \dfloorratio{384 m_1 + 10}{13} + \dmod{\dfloorratio{L + 1}{2}}{3} \dfloorratio{m_1 + 10}{12} \notag \\ \| − \dmod{\dfloorratio{385 − L}{2}}{3} \dfloorratio{m_1 + 9}{12} \\ J \| = d_2 + d + 347997 \end{align}

For 12 Kislev 4682 ($$a = 4682, m = 9, d = 12$$) we find

\begin{align*} m_1 \| = m − 7 = 9 − 7 = 2 \\ a_1 \| = a − \dfloorratio{m_1}{10} = 4682 − \dfloorratio{2}{10} = 4682 \\ δ_3(a_1) \| = δ_3(4682) = \dfloorratio{765433 \dfloorratio{235 a_1 − 234}{19} + 12084}{25920} \\ \| = \dfloorratio{765433 \dfloorratio{235×4682 − 234}{19} + 12084}{25920} \\ \| = \dfloorratio{765433 \dfloorratio{1100036}{19} + 12084}{25920} \\ \| = \dfloorratio{765433×57896 + 12084}{25920} \\ \| = \dfloorratio{44315521052}{25920} = 1709703 \\ δ_3(a_1 − 1) \| = δ_3(4681) = 1709349 \\ δ_3(a_1 + 1) \| = δ_3(4683) = 1710087 \\ δ_3(a_1 + 2) \| = δ_3(4684) = 1710442 \\ δ_5(a_1) \| = δ_5(4682) = δ_3(a_1) + \dmod{\dfloorratio{6 δ_3(a_1)}{7}}{2} \\ \| = 1709703 + \dmod{\dfloorratio{6×1709703}{7}}{2} \\ \| = 1709703 + \dmod{\dfloorratio{10258218}{7}}{2} \\ \| = 1709703 + \dmod{1465459}{2} = 1709704 \\ δ_5(a_1 − 1) \| = δ_5(4681) = 1709349 \\ δ_5(a_1 + 1) \| = δ_5(4683) = 1710087 \\ δ_5(a_1 + 2) \| = δ_5(4684) = 1710443 \\ L_2(a_1) \| = L_2(4682) = δ_5(a_1 + 1) − δ_5(a_1) \\ \| = δ_5(4683) − δ_5(4682) = 1710087 − 1709704 = 383 \\ L_2(a_1 − 1) \| = L_2(4681) = δ_5(4682) − δ_5(4681) = 1709704 − 1709349 = 355 \\ L_2(a_1 + 1) \| = L_2(4683) = δ_5(4684) − δ_5(4683) = 1710443 − 1710087 = 356 \\ d_1(a_1) \| = d_1(4682) = δ_5(a_1) + 2\dmod{\dfloorratio{L_2(a_1) + 19}{15}}{2} + \dmod{\dfloorratio{L_2(a_1 − 1) + 7}{15}}{2} \\ \| = δ_5(4682) + 2\dmod{\dfloorratio{L_2(4682) + 19}{15}}{2} + \dmod{\dfloorratio{L_2(4681) + 7}{15}}{2} \\ \| = 1709704 + 2\dmod{\dfloorratio{383 + 19}{15}}{2} + \dmod{\dfloorratio{355 + 7}{15}}{2} \\ \| = 1709704 + 2\dmod{\dfloorratio{402}{15}}{2} + \dmod{\dfloorratio{362}{15}}{2} \\ \| = 1709704 + 2×\dmod{26}{2} + \dmod{24}{2} = 1709704 \\ d_1(a_1 + 1) \| = d_1(4683) = δ_5(4683) + 2\dmod{\dfloorratio{L_2(4683) + 19}{15}}{2} + \dmod{\dfloorratio{L_2(4682) + 7}{15}}{2} \\ \| = 1710087 + 2\dmod{\dfloorratio{356 + 19}{15}}{2} + \dmod{\dfloorratio{383 + 7}{15}}{2} \\ \| = 1710087 + 2\dmod{\dfloorratio{375}{15}}{2} + \dmod{\dfloorratio{390}{15}}{2} \\ \| = 1710087 + 2×\dmod{25}{2} + \dmod{26}{2} \\ \| = 1710087 + 2×1 + 0 = 1710089 \\ L \| = d_1(a_1 + 1) − d_1(a_1) = d_1(4683) − d_1(4682) = 1710089 − 1709704 = 385 \\ d_2 \| = d_1(a_1) + \dfloorratio{384 m_1 + 10}{13} + \dmod{\dfloorratio{L + 1}{2}}{3} \dfloorratio{m_1 + 10}{12} \\ \| − \dmod{\dfloorratio{385 − L}{2}}{3} \dfloorratio{m_1 + 9}{12} \\ \| = d_1(4682) + \dfloorratio{384×2 + 10}{13} + \dmod{\dfloorratio{385 + 1}{2}}{3} \dfloorratio{2 + 10}{12} \\ \| − \dmod{\dfloorratio{385 − 385}{2}}{3} \dfloorratio{2 + 9}{12} \\ \| = 1709704 + \dfloorratio{778}{13} + \dmod{\dfloorratio{386}{2}}{3} \dfloorratio{12}{12} − \dmod{\dfloorratio{0}{2}}{3} \dfloorratio{11}{12} \\ \| = 1709704 + 59 + \dmod{193}{3}×1 − 0×0 \\ \| = 1709704 + 59 + 1×1 − 0×0 = 1709764 \\ J \| = d_2 + d + 347997 = 1709764 + 12 + 347997 = 2057773 \end{align*}

Transformation 2 yields a limit of $$w/235$$ years, which corresponds to about $$1.56 w$$ dys. The calculations of $$δ_2$$ and $$δ_3$$ (part of transformation 3) yield a limit of $$w/765433$$ months, which corresponds to about $$w/25920$$ days. The calculation of $$δ_5$$ yields a limit of $$w/6$$ days. The other calculations do not decrease the limit because their input values are limited by nature. The combined limit is about $$w/25920$$ days. For 32-bit numbers this corresponds to about 226 years, which is far too few to be practical. A more detailed search (as described in Sec. 15.2.3) shows that for 32-bit numbers the above formulas produce the correct results for CJDN 265'814 through 430'594, which corresponds to from somewhere in Jewish year −224 to somewhere in year 227.

To get a higher limit, you can calculate with 64-bit numbers, or replace the formula for $$δ_2$$ by

\begin{eqnarray} \{ ω_4, μ_2 \} \| = \| \Div(m_2, 25920) \\ δ_2 \| = \| 29 m_2 + 13753 ω_4 + \dfloorratio{13753 μ_2 + 5604}{25920} \end{eqnarray}

and the formula for $$δ_3$$ likewise, but with 12084 instead of 5604.

For the condensed formulas you should replace the formula for $$δ_3$$ with

\begin{align} m_2 \| = \dfloorratio{235 a_1 − 234}{19} \\ \{ ω_4, μ_2 \} \| = \Div\dparen{m_2, 25920} \\ δ_3 \| = 29 m_2 + 13753 ω_4 + \dfloorratio{13753 μ_2 + 12084}{25920} \end{align}

The limit of that detour is $$w$$ days. and then the combined limit becomes $$w/6$$ days, which for 32-bit numbers corresponds to about 980'000 years. If that isn't enough then you can also replace the formula for $$δ_5$$ with

$$δ_5 = δ_3 + \dmod{\dfloorratio{6\dmod{δ_3}{7}}{7}}{2}$$

Then the combined limit is $$w$$ days, and a higher limit is not possible. For 32-bit numbers that limit corresponds to about 5.9 million years.

Here are some examples of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${m_2}$$ $${765433 m_2 + 5604}$$ $${\dfrac{765433 m_2 + 5604}{w}}$$ $${δ_2}$$ $${ω_4}$$
2800 2143218004 1.00 82685 0
72000000 55111176005604 25663.14 2126202777 2777

$${m_2}$$ $${μ_2}$$ $${13753 μ_2 + 5604}$$ $${\dfrac{13753 μ_2 + 5604}{w}}$$ $${δ_2}$$
2800 2800 38514004 0.02 82685
72000000 20160 277266084 0.13 2126202777

$${δ_3}$$ $${6 δ_3}$$ $${\dfrac{6 δ_3}{w}}$$ $${δ_5}$$ $${6\dmod{δ_3}{7}}$$ $${δ_5}$$
355000000 2130000000 0.99 355000000 30 355000000
355000001 2130000006 0.99 355000002 36 355000002
355000002 2130000012 0.99 355000002 0 355000002
355000003 2130000018 0.99 355000003 6 355000003
355000004 2130000024 0.99 355000005 12 355000005
355000005 2130000030 0.99 355000005 18 355000005
2140000000 12840000000 5.98 2140000000 30 2140000000

#### 16.7.2. From CJDN to Jewish Calendar

Now we go in the opposite direction. The calendar is so complex that we cannot just reverse the calculations that we did from date to CJDN.

1. Transform CJDN $$J$$ into running day number $$s$$ since 1 Tishri of year 1:

$$s = J − J_0 = J − 347998$$

As examples we'll calculate the calendar dates that correspond to the following CJDNs: 2'000'087, 2'001'327, 2'057'773, 2'057'986, 119'311'997. For $$J = 2057773$$ we find $$s = 2057773 − 347998 = 1709775$$. All in all we find

$${J}$$ $${s}$$
2000027 1652029
2000087 1652089
2001327 1653506
2057773 1709775
2057986 1710165
119311997 118964176

2. We need to take into account the effect of all delays to determine in which month of which year the day with a certain running day number belongs, but the effect of the second, third, and fourth delays can only be calculated for a specific month in a specific year, and that month and year are the very items we're trying to figure out. So, we need to first estimate a month and year without taking into account the second, third, and fourth delays, and then calculate what those delays are, and then see if our estimate was good or bad.

Using the inverse of equation \eqref{eq:υ_1} we can calculate the provisional running calculation month number $$μ_2$$ for running day number $$s$$ as if the second, third, and fourth delays do not exist:

$$μ_2 = \dfloorratio{25920 s + 13835}{765433} \label{eq:y_1p}$$

Voor het uitrekenen van het voorlopige rekenjaarnummer $$α_3$$ en rekenmaandnummer $$μ_3$$ hebben we zoiets nodig als de inverse van formule \eqref{eq:j2μ1}:

\begin{align} \{ α_3, ε_3 \} \| = \Div(19 μ_2 + 252, 235) \\ μ_3 \| = \dfloorratio{ε_3}{19} \end{align}

maar die levert altijd $$μ_3 ≥ 0$$ terwijl ons rekenmaandnummer zo klein als −6 moet kunnen zijn (voor nisan). We krijgen dat voor elkaar door eerst 6 op te tellen bij $$μ_2$$, dan die inverse formule toe te passen, en daarna 6 af te trekken om $$μ_3$$ te vinden:

\begin{align} \{ α_3, ε_3 \} \| = \Div(19 (μ_2 + 6) + 252, 235) = \Div(19 μ_2 + 366, 235) \\ μ_3 \| = \dfloorratio{ε_3}{19} − 6 \end{align}

For $$J = 2057773$$ we found earlier $$s = 1709775$$, and now we find

\begin{align*} μ_2 \| = \dfloorratio{25920 s + 13835}{765433} = \dfloorratio{25920×1709775 + 13835}{765433} \\ \| = \dfloorratio{44317381835}{765433} = 57898 \\ \{ α_3, ε_3 \} \| = \Div(19 μ_2 + 366, 235) = \Div(19×57898 + 366, 235) \\ \| = \Div(1100428, 235) = \{ 4682, 158 \} \\ μ_3 \| = \dfloorratio{ε_3}{19} − 6 = \dfloorratio{158}{19} − 6 = 8 − 6 = 2 \end{align*}

Some more examples:

$${J}$$ $${s}$$ $${μ_2}$$ $${α_3}$$ $${ε_3}$$ $${μ_3}$$
2000027 1652029 55942 4524 124 0
2000087 1652089 55945 4524 181 3
2001327 1653329 55987 4528 39 −4
2057773 1709775 57898 4682 158 2
2057986 1709988 57905 4683 56 −4
119311997 118963999 4028500 325710 16 −6

If we calculate the running day number $$d_2$$ (from 16.7.1) of the first day of calculation month $$μ_2$$ of calculation year $$α_3$$ with all applicable delays included, and then calculate the provisional day-number-in-the-month $$s − d_2$$, then we find results that vary between −2 en 29. The days for which this day number is negative belong in the previous month, so then the true running month number is equal to $$μ_2 − 1$$. There are 5'963'491 such days in each great calendar cycle of 8'527'680 months, so not every month has such days. The number of months in the great calendar cycle for which the first two days have $$s \lt d_2$$ is 1'006'441, which means about 11.8% of all months. And the number of months for which none of the days have $$s \lt d_2$$ is 4'767'513, which means about 55.9% of all months. And 32.3% of the months have one day with $$s \lt d_2$$. The greatest number of months in a row that have no days with $$s \lt d_2$$ is 25.

The days for which this day number is not less than 0 and not greater than 28 certainly belong in month $$μ_2$$, because all months have at least 29 days. The days for which this day number is equal to 29 (which indicates the 30th day of the month, because the first day of the month has calculation day number 0) can belong in the current month, or else in the next month, because some months have only 29 days.

If we calculate the day number in the month compared to the next month (i.e., $$s − d_2(μ_2 + 1)$$), then we find results that vary between −32 and 0. The days for which this day number is equal to 0 belong in this next month ($$μ_2 + 1$$). There are 163'258 such days in each great calendar cycle, so roughly one out of every 52 months has a day for which $$μ_2$$ is one too small. For 97.6% of days, $$μ_2$$ is correct.

Unfortunately, there is no simple relationship between the day number relative to month $$μ_2$$ and that relative to month $$μ_2 + 1$$, so we must calculate both day numbers to figure out the month into which the desired day falls.

The minimal calculation is as follows:

1. Calculate the provisional calendar year number $$α_3$$ and provisional calculation month number $$μ_3$$:

\begin{align} \{ α_3, ε_3 \} \| = \Div(19 μ_2 + 366, 235) \\ μ_3 \| = \dfloorratio{ε_3}{19} − 6 \end{align}

Then calculate the running day number $$d_2(α_3, μ_4)$$ of the first day of that calendar month in that calendar year, as described in Sec. 16.7.1, and then the provisional calculation day number $$δ_{14}$$ since the first day of that month:

$$δ_{14} = s − d_2(α_3, μ_3)$$

If $$0 ≤ δ_{14} ≤ 28$$ then the sought calculation date $$\{ a_1, m_1, d_0 \}$$ is $$\{ α_3, μ_3, δ_{14} \}$$.

2. If $$δ_{14} = 29$$ then calculate the second provisional running month number $$μ_5$$:

$$μ_5 = μ_2 + 1$$

Then calculate the provisional calendar year number $$α_4$$, the provisional calculation month number $$μ_6$$, and the provisional calculation day number $$δ_{15}$$:

\begin{align} \{ α_4, ε_4 \} \| = \Div(19 μ_5 + 366, 235) \\ μ_6 \| = \dfloorratio{ε_4}{19} − 6 \\ δ_{15} \| = s − d_2(α_4, μ_6) \end{align}

If $$δ_{15} \lt 0$$ then the sought calculation date $$\{ a_1, m_1, d_0 \}$$ is $$\{ α_3, μ_3, δ_{14} \}$$. Otherwise the correct calculation month number is $$μ_7 = μ_5 = μ_2 + 1$$, and the sought calculation date $$\{ a_1, m_1, d_0 \}$$ is $$\{ α_4, μ_6, δ_{15} \}$$.

3. If $$δ_{14} \lt 0$$ then the correct running calculation month number is

$$μ_7 = μ_2 − 1$$

Calculate from that the calendar year number $$a_1$$, the calculation month number $$m_1$$, and the calculation day number $$d_0$$:

\begin{align} \{ a_1, ε_5 \} \| = \Div(19 μ_7 + 366, 235) \\ m_1 \| = \dfloorratio{ε_5}{19} − 6 \\ d_0 \| = s − d_2(a_1, m_1) \end{align}

For $$J = 2057773$$ we had $$s = 1709775$$, $$μ_2 = 57898$$. Then

\begin{align*} \{ α_3, ε_3 \} \| = \Div(19 μ_2 + 366, 235) = \Div(19×57898 + 366, 235) \\ \| = \Div(1100428, 235) = \{ 4682, 158 \} \\ μ_3 \| = \dfloorratio{ε_3}{19} − 6 = \dfloorratio{158}{19} − 6 = 8 − 6 = 2 \end{align*}

Then we calculate $$d_2(α_3, μ_3) = d_2(4682, 2)$$ as described in Sec. 16.7.1. We find $$d_2(4682, 2) = 1709764$$. Then

$δ_{14} = s − d_2(α_3, μ_3) = 1709775 − 1709764 = 11$

That $$δ_{14}$$ is not negative and is not greater than 28, so we have already found the sought calculation date: $$\{ a_1, m_1, d_0 \}$$ is equal to $$\{ α_3, μ_3, δ_{14} \} = \{ 4682, 2, 11 \}$$.

For all example CJDNs we find

$${J}$$ $${s}$$ $${μ_2}$$ $${α_3}$$ $${ε_3}$$ $${μ_3}$$ $${d_2}$$ $${δ_{14}}$$
2000027 1652029 55942 4524 124 0 1652000 29
2000087 1652089 55945 4524 181 3 1652090 −1
2001327 1653329 55987 4528 39 −4 1653329 0
2057773 1709775 57898 4682 158 2 1709764 11
2057986 1709988 57905 4683 56 −4 1709971 17
119311997 118963999 4028500 325710 16 −6 118964000 −1

$${J}$$ $${μ_5}$$ $${α_4}$$ $${ε_4}$$ $${μ_6}$$ $${d_2}$$ $${δ_{15}}$$
2000027 55943 4524 143 1 1652030 −1

$${J}$$ $${μ_7}$$ $${a_1}$$ $${ε_5}$$ $${m_1}$$ $${d_2}$$ $${d_0}$$
2000027 4524 0 29
2000087 55944 4524 162 2 1652060 29
2001327 4528 −4 0
2057773 4682 2 11
2057986 4683 4 17
119311997 4028499 325709 232 6 118963971 28

The number of calculations is then not the same for all dates. If it is advantageous to have the same number of calculations for all dates, then calculate as described below.

1. The first provisional running month number $$μ_3$$ is

$$μ_3 = μ_2 + 1$$

From that, calculate the provisional calendar year number $$α_3$$ and provisional calculation month number $$μ_4$$:

\begin{align} \{ α_3, ε_3 \} \| = \Div(19 μ_3 + 366, 235) \\ μ_4 \| = \dfloorratio{ε_3}{19} − 6 \end{align}

Then calculate the running day number $$d_2(α_3, μ_4)$$ of the first day of that calendar year and calculation month, as described in Sec. 16.7.1, and then the provisional calculation day number $$δ_{14}$$ since the first day of that month:

$$δ_{14} = s − d_2(α_3, μ_4)$$

2. The second provisional running month number $$μ_5$$ is

$$μ_5 = μ_3 + \dfloorratio{δ_{14}}{64}$$

(The divisor 64 in the above division must be greater than 32 because $$δ_{14}$$ varies between −32 and 0 and we want $$μ_5 = μ_3 − 1$$ if $$δ_{14} \lt 0$$. We choose 64 because it is the first power of 2 greater than 32, and perhaps that makes the division a teeny bit faster.)

Then calculate the provisional calendar year number $$α_4$$, the provisional calculation month number $$μ_6$$, and the provisional calculation day number $$δ_{15}$$:

\begin{align} \{ α_4, ε_4 \} \| = \Div(19 μ_5 + 366, 235) \\ μ_6 \| = \dfloorratio{ε_4}{19} − 6 \\ δ_{15} \| = s − d_2(α_4, μ_6) \end{align}

3. The final running month number $$μ_7$$ is

$$μ_7 = μ_5 + \dfloorratio{δ_{15}}{64}$$

From that, calculate the calendar year number $$a_1$$, the calculation month number $$m_1$$, and the calculation day number $$d_0$$:

\begin{align} \{ a_1, ε_5 \} \| = \Div(19 μ_7 + 366, 235) \\ m_1 \| = \dfloorratio{ε_5}{19} − 6 \\ d_0 \| = s − d_2(a_1, m_0) \end{align}

For $$J = 2057773$$ we had $$μ_2 = 57898$$. Then

\begin{align*} μ_3 \| = μ_2 + 1 = 57898 + 1 = 57899 \\ \{ α_3, ε_3 \} \| = \Div(19×57899 + 366, 235) = \Div(1100447, 235) \\ \| = \{ 4682, 177 \} \\ μ_4 \| = \dfloorratio{ε_3}{19} − 6 = \dfloorratio{177}{19} − 6 = 9 − 6 = 3 \end{align*}

Then we can calculate $$d_2(α_3, μ_4) = d_2(4682, 3)$$ as described in Sec. 16.7.1, and find $$d_2(4682, 3) = 1709794$$. Then $$δ_{14} = s − d_2(4682, 3) = 1709775 − 1709794 = −19$$. And then

$μ_5 = μ_3 + \dfloorratio{δ_{14}}{64} = 57899 + \dfloorratio{−19}{64} = 57898$

With that, we can calculate $$α_4, μ_6, d_2(α_4, μ_6), δ_{15}$$ like $$α_3, μ_4, d_2(α_3, μ_4), δ_{14}$$ above. We find $$α_4 = 4682, μ_6 = 2, δ_{15} = 11$$. Then

$μ_7 = μ_5 + \dfloorratio{δ_{15}}{64} = 57899 + \dfloorratio{11}{64} = 57899$

so $$μ_7 = μ_5$$, which means the numbers don't change anymore, so we end up with $$a_1 = 4682, m_1 = 2, d_0 = 11$$.

For all example CJDNs we find

$${J}$$ $${s}$$ $${μ_2}$$ $${μ_3}$$ $${α_3}$$ $${μ_4}$$ $${d_2}$$ $${δ_{14}}$$
2000027 1652029 55942 55943 4524 1 1652030 −1
2000087 1652089 55945 55946 4524 4 1652119 −30
2001327 1653329 55987 55988 4528 −3 1653359 −30
2057773 1709775 57898 57899 4682 3 1709794 −19
2057986 1709988 57905 57906 4683 −3 1710001 −13
119311997 118963999 4028500 4028501 325710 −5 118964030 −31

$${J}$$ $${μ_5}$$ $${α_4}$$ $${μ_6}$$ $${d_2}$$ $${δ_{15}}$$ $${μ_7}$$ $${a_1}$$ $${m_1}$$ $${d_2}$$ $${d_0}$$
2000027 55942 4524 0 1652000 29 55942 4524 0 1652000 29
2000087 55945 4524 3 1652090 −1 55944 4524 2 1652060 29
2001327 55987 4528 −4 1653329 0 55987 4528 −4 1653329 0
2057773 57898 4682 2 1709764 11 57898 4682 2 1709764 11
2057986 57905 4683 −4 1709971 17 57905 4683 −4 1709971 17
119311997 4028500 325710 −6 118964000 −1 4028499 325709 6 118963971 28

3. Transformation 1 produces calendar year $$a$$ from calculation year $$a_1$$ and calculation month $$m_1$$. Calculation months −6 through −1 of calculation year $$a_1$$ belong to calendar year $$a = a_1 − 1$$, and calculation months 0 through 6 belong to calendar year $$a = a_1$$. We arrange that through

\begin{align} a \| = a_1 + \dfloorratio{m_1}{10} \\ m \| = m_1 + 7 \end{align}

$${m_1}$$ $${∆a}$$ $${m}$$
−6 −1 1
−5 −1 2
−4 −1 3
−3 −1 4
−2 −1 5
−1 −1 6
0 0 7
1 0 8
2 0 9
3 0 10
4 0 11
5 0 12
6 0 13

For $$J = 2057773$$ we had $$a_1 = 4682$$ and $$m_1 = 2$$ so

\begin{align} a \| = a_1 + \dfloorratio{m_1}{10} = 4682 + \dfloorratio{2}{10} = 4682 \\ m \| = m_1 + 7 = 2 + 7 = 9 \end{align}

For all example CJDNs we find

$${J}$$ $${a_1}$$ $${m_1}$$ $${d_0}$$ $${a}$$ $${m}$$
2000027 4524 0 29 4524 7
2000087 4524 2 29 4524 9
2001327 4528 −4 0 4527 3
2057773 4682 2 11 4682 9
2057986 4683 −4 17 4682 3
119311997 325709 6 28 325709 13

4. And then we add 1 to the calculation day to find the calendar day.

$$d = d_0 + 1$$

For $$J = 2057773$$ we had $$d_0 = 11$$ so

$d = d_0 + 1 = 11 + 1 = 12$

so $$J = 2057773$$ corresponds to day 12 of month 9 of year 4682.

For all example CJDNs we find

$${J}$$ $${a_1}$$ $${m}$$ $${d_0}$$ $${d}$$
2000027 4524 7 29 30
2000087 4524 8 29 30
2001327 4528 2 0 1
2057773 4682 8 11 12
2057986 4683 2 17 18
119311997 325709 12 28 29

The calculation of $$μ_2$$ has a limit of $$w/25920$$ days. The calculation of $$α_3$$, $$ε_3$$, $$α_4$$, $$ε_4$$, $$a_1$$, $$ε_5$$ has a limit of $$w/19$$ months, which corresponds to about $$1.6 w$$ days. The common limit is $$w/25920$$ days, which for 32-bit numbers corresponds to about 226 years. That is far too little for practical work.

If you want a higher limit then you can replace the calculation of $$μ_2$$ by

\begin{align} \{ ω_4, δ_{16} \} \| = \Div(s, 33783) \\ μ_2 \| = 1144 ω_4 + \dfloorratio{8 ω_4 + 25920 δ_{16} + 13835}{765433} \end{align}

Then the limit is $$w$$ days, which for 32-bit numbers corresponds to about 5.9 million years.

Here are some examples of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${s}$$ $${25920 s + 13835}$$ $${\dfrac{25920 s + 13835}{w}}$$ $${μ_2}$$
82000 2125453835 0.99 2776
2140000000 55468800013835 25829.67 72467217

$${s}$$ $${ω_4}$$ $${δ_{16}}$$ $${8 ω_4 + 25920 δ_{16} + 13835}$$ $${\dfrac{8 ω_4 + 25920 δ_{16} + 13835}{w}}$$ $${μ_2}$$
82000 2 14434 374143131 0.17 2776
2140000000 63345 15865 411741395 0.19 72467217

### 16.8. A LunisolarCalendar With Many Fixed Month Lengths

If the distribution of days across months is independent from the distribution of months across years, then a particular month of the year won't have the same length in all years. For example, the first month of year 1 of the Babylonian calendar has 29 days, but the first month of year 2 has 30 days. For doing calendar calculations in your head, it would be convenient if most months have the same length in each year. Can we construct a lunisolar calendar that has that?

With the characteristics of the Cycle of Meton it is not possible to make each month have the same length in every year that contains it. If we make a fixed number of the first 12 months of every year long (with 30 days), then the corresponding number of long months in the 19-year cycle is a multiple of 19. If the 13th month is always short, then the total number of long months would be a multiple of 19, and if the 13th month is always long, then the total number would be 7 (the number of years in the 19-year cycle that have 13 months) plus a multiple of 19, but the Cycle of Meton requires 125 = 6×19 + 11 long months, which fits neither of the two possibilities, so the length of one or more months cannot be the same in all years.

We want to use the smallest number of different month lengths, which means only months of 29 or 30 days.

If we want to use the calendar calculation techniques discussed before, then it is most convenient if we need only a single calendar level for the calculations between months and days, but then we need both short and long years to use the same straight line and thus to have the same month lengths, apart from the shortening at the very end of the year.

We need 125 long months (of 30 days) and 110 short months (of 29 days) in every period of 19 years = 235 months. If $$n$$ of the first 11 months of each year are long then that produces $$19n$$ long months in the period of 19 years, and then $$125 − 19n$$ of the 26 12th and 13th months must be long, so $$125 − 19n$$ must be between 0 and 26 (inclusive), and that means that $$n = 6$$, because $$n = 5$$ yields 30 (too large) and $$n = 7$$ yields −8 (too small).

$$n = 6$$ yields 11 long 12th and 13th months. Those 11 long months cannot all be 13th months because there are only 7 13th months, so some 12th months must be long.

A long month may turn into a short month if it is at the end of the year, but not if at least one more month follows in the same year, so if some 12th months are long then there can only be short 12th months if they are the last month of the year, i.e., when the year has 12 months. So we can have the following kinds of years:

Month 12 Month 13 Year Length
short none 354
long none 355
long short 384
long long 385

There must be 7 long years (of 13 months) and 12 short years (of 12 months) in every 19 years. If those long and short years are both as short as possible (i.e., 354 and 384 days) then that yields 7×384 + 12×354 = 6936 days, so only 4 more days are needed. That means that 4 years must gain a day each, to become 355 or 385 days long. That means that at least three different year lengths are needed, and that cannot be done with a calendar level of types 2 or 3, so we need a calendar level of type 4.

We link the lunisolar calendar to the modern (Gregorian) calendar based on the following considerations:

1. The calendar year in the lunisolar calendar should be roughly the same as the calendar year in the modern (Gregorian) calendar.

2. Because this calendar is a lunisolar one, the intention is that every month begins at New Moon, so we want to tie the calendars in a year in which there is a New Moon at the beginning of that year in the modern calendar.

3. The Cycle of Meton includes 19 years, and we can choose which of those 19 years we use to tie the lunar calendar to the modern calendar. This gives us about a month of leeway in where the average of the start of the lunar year is compared to the start of the year in the modern calendar. We arrange the connection such that the beginning of the lunar year is on average as close as possible to the beginning of winter in the northern hemisphere (December 21).

4. The Cycle of Meton doesn't follow the average length of lunar months exactly, so in the course of time our lunisolar calendar will inevitably get more and more out of sync with the lunar phases, so the year in which we tie our lunar calendar to the modern one must not be far from now.

I inspected all modern calendar years between 1900 and 2100 and looked for the one in which the lunar phase of the mean Moon at the beginning of the year (0 UTC at the beginning of January 1st) is the closest to New Moon, and that turns out to be the year 2033. So we equate January 1st, 2033 in the modern calendar with the first day of the first month of year 2033 in the lunisolar calendar.

#### 16.8.1. From LunarCalendar to CJDN

The calculations are schematically as follows:

  a ════════════════════╗
m ─(−1)─ m₀ ──┐       ║
d ─(−1)─ d₀ ─(1)─ d₁─(2)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${r_i}$$ $${h_i}$$ $${t_i}$$ $${g_i}$$ $${γ_i}$$ $${p}$$
1 384 13 29 7 7 29.538462
2.1 6940 19 354 30 7 2 19 1 365.26316
2.2 1 4 18 19 1

1. First we subtract 1 from the month number and day number so they begin at 0 instead of 1.

\begin{align*} m_0 \| = m − 1 \\ d_0 \| = d − 1 \end{align*}

As an example we'll calculate the CJDN of the first day of year 2033 in the lunar calendar, so $$\{ a, m, d \} = \{ 2033, 1, 1 \}$$. We find

\begin{align*} m_0 \| = m − 1 = 1 − 1 = 0 \\ d_0 \| = d − 1 = 1 − 1 = 0 \end{align*}

2. Transformation 1 produces day number $$d_1$$ since the first day of the year, from the calculation month number $$m_0$$ and the calculation day number $$d_0$$:

\begin{align} δ_1 \| = \dfloorratio{384m_0 + 7}{13} \\ d_1 \| = δ_1 + d_0 \end{align}

This yields a long month 12 (with 30 days) and a short month 13 (with 29 days), and that 6 of the first 11 months are always long months.

For example, if $$m_0 = 4$$, then we find

$δ_1 = \dfloorratio{384×4 + 7}{13} = \dfloorratio{1543}{13} = 118$

so the first day of the fifth month ($$m_0 = 4$$) is the 118th day since the first day of the year.

For the first day of the first 14 months, we get the following results (with $$L$$ the length of the month):

$${m}$$ $${m_0}$$ $${δ_1}$$ $${L}$$
1 0 0 30
2 1 30 29
3 2 59 30
4 3 89 29
5 4 118 30
6 5 148 29
7 6 177 30
8 7 207 29
9 8 236 30
10 9 266 29
11 10 295 30
12 11 325 30
13 12 355 29
14 13 384

3. Transformation 2 yields the running day number $$s$$ from the year $$a$$ and the day number $$d_1$$ since the first day of the year.

\begin{align} δ_2 \| = 354a + 30\dfloorratio{7a + 2}{19} + \dfloorratio{4a + 18}{19} \\ s \| = d_1 + δ_2 \end{align}

The following table shows the running day numbers for 20 years, and the year length $$L$$ for the first 19 of those years. That pattern of year lengths repeats itself every 19 years. There are 8 years of 354 days, 4 years of 355 days, and 7 years of 384 days, which makes 6940 days in 19 years.

$${a}$$ $${δ_2}$$ $${L}$$
0 0 355
1 355 354
2 709 384
3 1093 354
4 1447 355
5 1802 384
6 2186 354
7 2540 384
8 2924 354
9 3278 355
10 3633 384
11 4017 354
12 4371 354
13 4725 384
14 5109 355
15 5464 384
16 5848 354
17 6202 354
18 6556 384
19 6940

In our example $$a = 2033, d_1 = 0$$, so

\begin{align*} δ_2 \| = 354 a + 30\dfloorratio{7 a + 2}{19} + \dfloorratio{4 a + 18}{19} \\ \| = 354×2033 + 30\dfloorratio{7×2033 + 2}{19} + \dfloorratio{4×2033 + 18}{19} \\ \| = 719682 + 30\dfloorratio{14233}{19} + \dfloorratio{8150}{19} \\ \| = 719682 + 30×749 + 428 = 742580 \\ s \| = d_1 + δ_2 = 742580 \end{align*}

4. And then we add the CJDN $$J_0$$ of day 1 of month 1 of year 0. We link the two calendars at the first day of year 2033. In the modern calendar that day corresponds to CJDN 2463599. In the lunar calendar we found above that for the first day of year 2033 $$s = 742580$$. It follows that $$J_0 = 2463599 − 742580 = 1721019$$.

$$J = s + J_0 = s + 1721019$$

For our example this means

$J = s + J_0 = 742580 + 1721019 = 2463599$

so the CJDN that belongs to the first day of year 2033 in this lunar calendar is 2463599, which corresponds to the first day of year 2033 in the modern (Gregorian) calendar.

These calculations condense to

\begin{align} J \| = 354 a + 30\dfloorratio{7 a + 2}{19} + \dfloorratio{4 a + 18}{19} \notag \\ \| + \dfloorratio{384 m − 377}{13} + d + 1721018 \end{align}

For our example (with $$a = 2033, m = 1, d = 1$$) we find

\begin{align*} J \| = 354×2033 + 30\dfloorratio{7×2033 + 2}{19} + \dfloorratio{4×2033 + 18}{19} \\ \| + \dfloorratio{384×1 − 377}{13} + 1 + 1721018 \\ \| = 719682 + 30\dfloorratio{14233}{19} + \dfloorratio{8150}{19} + \dfloorratio{7}{13} + 1721019 \\ \| = 2440701 + 30×749 + 428 + 0 = 2463599 \end{align*}

so day 1 of month 1 of year 2033 in the lunar calendar corresponds to CJDN 2463599, which corresponds to January 1st, 2033 in the modern (Gregorian) calendar.

These calculations have a limit of about $$w/6940$$ year, which corresponds to about $$w/19$$ days, which for 32-bit numbers corresponds to about 309'000 years. A more detailed search (as described in Sec. 15.2.3) shows that for 32-bit numbers the above formulas produce the correct results for CJDN −111'304'463 through 114'746'447, which corresponds to from somewhere in lunar calendar year −309'436 to somewhere in year 309'435.

#### 16.8.2. From CJDN to LunarCalendar

The calculations are schematically as follows:

  a ════════════════════╗
m ─(−1)─ m₀ ──┐       ║
d ─(−1)─ d₀ ─(1)─ d₁─(2)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${r_i}$$ $${h_i}$$ $${t_i}$$ $${g_i}$$ $${γ_i}$$ $${p}$$
1 384 13 29 7 7 29.538462
2.2 6940 19 354 30 7 2 19 1 365.26316
2.3 1 4 18 19 1

The calculations are as follows:

1. First we subtract the CJDN $$J_0$$ of day 1 of month 1 of year 0 from the CJDN of the desired date to find the running day number $$s$$:

$$s = J − J_0 = J − 1721019$$

As an example we'll calculate the date that corresponds to CJDN 2459695. Then

$s = J − J_0 = 2459695 − 1721019 = 738676$

2. Transformation 2 deduces from the running day number $$s$$ the year number $$a$$ and the calculation day number $$d_1$$ since the first day of the year:

\begin{align} ω_1 \| = g s + g\dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_i γ_i r_i t_i} − 1 \notag \\ \| = 19 s + 19×31 − (1×30×2 + 1×1×18) − 1 = 19 s + 510 \\ α_1 \| = \dfloorratio{ω_1}{6940} \\ δ_1 \| = s − q α_1 − \dparen{\sum_i r_i \dfloorratio{h_i α_1 + t_i}{g_i}} \notag \\ \| = s − 354 α_1 − 30 \dfloorratio{7 α_1 + 2}{19} − \dfloorratio{4 α_1 + 18}{19} \\ a \| = α_1 + \dfloorratio{δ_2}{q + \sum_{r_i \gt 0} r_1} = α_1 + \dfloorratio{δ_1}{385} \notag \\ d_1 \| = s − 354 a − 30 \dfloorratio{7 a + 2}{19} − \dfloorratio{4a + 18}{19} \end{align}

For our example we find

\begin{align*} ω_1 \| = 19 s + 510 = 19×738676 + 510 = 14035354 \\ α_1 \| = \dfloorratio{ω_1}{6940} = \dfloorratio{14035354}{6940} = 2022 \\ δ_1 \| = s − 354 α_1 − 30 \dfloorratio{7 α_1 + 2}{19} − \dfloorratio{4 α_1 + 18}{19} \\ \| = 738676 − 354×2022 − 30 \dfloorratio{7×2022 + 2}{19} − \dfloorratio{4×2022 + 18}{19} \\ \| = 738676 − 715788 − 30 \dfloorratio{14156}{19} − \dfloorratio{8106}{19} \\ \| = 22888 − 30×745 − 426 = 112 \\ a \| = α_1 + \dfloorratio{δ_1}{385} = 2022 + \dfloorratio{112}{385} = 2022 \\ d_1 \| = s − 354 a − 30 \dfloorratio{7 a + 2}{19} − \dfloorratio{4 a + 18}{19} = 112 \end{align*}

3. Transformation 1 derives the calculation month number $$m_0$$ and the calculation day number $$d_0$$ since the first day of the month from the calculation day number $$d_1$$ since the first day of the year.

\begin{align} \{ m_0, ω_2 \} \| = \Div(g d_1 + g − t − 1, f) \notag \\ \| = \Div(13 d_1 + 13 − 7 − 1, 384) \notag \\ \| = \Div(13 d_1 + 5, 384) \\ d_0 \| = \dfloorratio{ω_2}{g} = \dfloorratio{ω_2}{13} \end{align}

For our example we find

\begin{align*} \{ m_0, ω_2 \} \| = \Div(13 d_1 + 5, 384) = \Div(13×112 + 5, 384) \\ \| = \Div(1461, 384) = \{ 3, 309 \} \\ d_0 \| = \dfloorratio{ω_2}{13} = \dfloorratio{309}{13} = 23 \end{align*}

4. And then we add 1 to the calculation month $$m_0$$ and calculation day $$d_0$$ to get the calendar month $$m$$ and calendar day $$d$$.

\begin{align} m \| = m_0 + 1 \\ d \| = d_0 + 1 \end{align}

For our example we find

\begin{align*} m \| = m_0 + 1 = 3 + 1 = 4 \\ d \| = d_0 + 1 = 23 + 1 = 24 \end{align*}

so the sought date was day 24 of month 4 of year 2022.

The above equations condense a bit, to

\begin{align} s \| = J − 1721019 \\ α_1 \| = \dfloorratio{19s + 511}{6940} \\ δ_1 \| = s − 354 α_1 − 30 \dfloorratio{7 α_1 + 2}{19} − \dfloorratio{4 α_1 + 18}{19} \\ a \| = α_1 + \dfloorratio{δ_1}{385} \notag \\ d_1 \| = s − 354a − 30 \dfloorratio{7 a + 2}{19} − \dfloorratio{4 a + 18}{19} \\ \{ m, ω_2 \} \| = \Div(13 d_1 + 389, 384) \\ d \| = \dfloorratio{ω_2}{13} + 1 \end{align}

For our example we find

\begin{align*} s \| = J − 1721019 = 2459695 − 1721019 = 738676 \\ α_1 \| = \dfloorratio{19s + 511}{6940} = \dfloorratio{19×738676 + 511}{6940} = \dfloorratio{14035355}{6940} = 2022 \\ δ_1 \| = s − 354 α_1 − 30 \dfloorratio{7 α_1 + 2}{19} − \dfloorratio{4 α_1 + 18}{19} \\ \| = 738676 − 354×2022 − 30 \dfloorratio{7×2022 + 2}{19} − \dfloorratio{4×2022 + 18}{19} \\ \| = 738676 − 715788 − 30 \dfloorratio{14156}{19} − \dfloorratio{8106}{19} \\ \| = 22888 − 30×745 − 426 = 112 \\ a \| = α_1 + \dfloorratio{δ_1}{385} = 2022 + \dfloorratio{112}{385} = 2022 \\ d_1 \| = s − 354 a − 30 \dfloorratio{7 a + 2}{19} − \dfloorratio{4 a + 18}{19} = 112 \\ \{ m, ω_2 \} \| = \Div(13 d_1 + 389, 384) = \Div(13×112 + 389, 384) \\ \| = \Div(1845, 384) = \{ 4, 309 \} \\ d \| = \dfloorratio{ω_2}{13} + 1 = \dfloorratio{309}{13} + 1 = 23 + 1 = 24 \end{align*}

so the sought date is day 24 of month 4 of year 2022, just like above.

Transformation 2 yields a limit of about $$w/19$$ days, and that is the combined limit. For 32-bit numbers this corresponds to about 309'000 years.

If you want a higher limit then you can calculate using 64-bit numbers or replace the formula for $$α_1$$ by

\begin{align} \{ ω_2, ε_2 \} \| = \Div(s, 6940) \\ α_1 \| = 19 ω_2 + \dfloorratio{19 ε_2 + 510}{6940} \end{align}

Then the limit is $$w$$ days, and a higher limit is not possible. For 32-bit numbers that corresponds to about 5.9 million years.

Here are some examples of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${s}$$ $${19 s + 510}$$ $${\dfrac{19 s + 510}{w}}$$ $${α_1}$$ $${ω_2}$$ $${ε_2}$$ $${19 ε_2 + 510}$$ $${α_1}$$
1000000 19000510 8.8 × 10−3 2737 144 640 12670 2737
113000000 2147000510 1.00 × 100 309366 16282 2920 55990 309366

Here are the dates (year-month-day) in the modern (Gregorian) calendar that correspond to new year in the lunar calendar for a couple of years:

$${a}$$ D
2019 2018-12-08
2020 2019-12-27
2021 2020-12-15
2022 2022-01-03
2023 2022-12-23
2024 2023-12-13
2025 2024-12-31
2026 2025-12-20
2027 2026-12-09
2028 2027-12-28
2029 2028-12-17
2030 2030-01-05
2031 2030-12-25
2032 2031-12-14
2033 2033-01-01
2034 2033-12-22
2035 2034-12-11
2036 2035-12-30
2037 2036-12-18
2038 2037-12-08

### 16.9. The Islamic Calendar

#### 16.9.1. From Islamic Date to CJDN

The religious Islamic calendar depends on observations and so cannot be caught in formulas. The administrative calendar has fixed rules so it can be caught in formulas. In the administrative calendar, the odd months have 30 days and the even months have 29 days, except that the last month sometimes has 29 days and sometimes has 30 days. This gives a year 354 or 355 days. Of each 30 years, 11 are long (with 355 days) and the remainder are short (with 354 days). A complete cycle contains 11×355 + 19×354 = 10631 days.

Rob van Gent (at //www.staff.science.uu.nl/~gent0113/islam/islam_tabcal.htm/) mentions four different ways that are used to distribute the 11 leap years across each cycle of 30 years. Table 1 lists those ways and their leap year distributions, and shows the corresponding $$t$$ (see Equation \eqref{eq:islamN}).

Table 1: Leap Years in Islamic Calendar

Type Leap Years $${t}$$ Origin/Use
I 2 5 7 10 13 15 18 21 24 26 29 15 Kūshyār ibn Labbān, Ulugh Beg, Kuwaiti Algorithm
II 2 5 7 10 13 16 18 21 24 26 29 14 al-Fazārī, al-Khwārizmī, al-Battānī, Toledan and Alfonsine Tables
III 2 5 8 10 13 16 19 21 24 27 29 11 Fātimids, Misri, or Bohra Calendar
IV 2 5 8 11 13 16 19 21 24 27 30 9 Habash al-Hāsib, al-Bīrūnī, Elias of Nisibis

The number of leap years between the beginning of year 0 and the beginning of year $$a$$ is

$$N = \dfloorratio{11a + t}{30} \label{eq:islamN}$$

There are two variants for each pattern shift: the astronomical epoch "a" according to which the first day of the calendar (1 Muharram of year 1) began on the evening of Wednesday 14 July 622 (approximately CJD 1'948'438.75), and the civil epoch "c" according to which the calendar began on the evening of Thursday 15 July 622 (approximately CJD 1'948'439.75). The most commonly used administrative calendar is IIc.

For the lowest calendar level we seek a straight line that alternates between 30 and 29 days except that the 12th month has 30 days, and for short years (with 354 days) we cut away the last day. In a calendar based on a straight line for 355/12, the alternation between 30 and 29 days is already broken after 5 or 7 months, but we need that alternation to continue for at least 11 months. It turns out that we need a $$p$$ for that of at most 29 + 6/11, and 355/12 = 29 + 7/12 is greater than that. We use $$p = 29 \frac{6}{11} = 325/11$$.

In the Islamic Calendar the calendar days run from sunset to sunset. The CJDN calendar days run from midnight to midnight. For the calculations, we make the connection at noon. The CJDN that according to the following formulas is connected with a particular Islamic calendar date, actually corresponds to that Islamic calendar date only between midnight and sunset. Between sunset and midnight, the next calendar day has already begun according to the Islamic calendar, but not yet according to the CJDN.

For example, CJDN 2'455'774 corresponds to Gregorian date 31 July 2011 (31-07-2011) and runs from midnight to midnight local time. The below formulas say (for type IIc) that CJDN 2'455'774 corresponds to Islamic date 29 Shaban 1432 (29-08-1432) ― this means that those two dates correspond to each other between midnight and sunset. From sunset to midnight, it is still 31 July in the Gregorian calendar and still CJDN 2'455'774, but in the Islamic calendar it is already the next day (i.e., 1 Ramaḍān).

Type $${t}$$ $${J_0}$$
Ia 15 1'948'439
Ic 15 1'948'440
IIa 14 1'948'439
IIc 14 1'948'440
IIIa 11 1'948'439
IIIc 11 1'948'440
IVa 9 1'948'439
IVc 9 1'948'440

The calculations are schematically as follows:

  a ═(−1)═ a₀ ═══════════┐
m ─(−1)─ m₀ ──┐        │
d ─(−1)─ d₀ ─(1)─ d₁ ─(2)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$
1 325 11 29 6 5 29.545455
2 10631 30 354 11 t 354.36667

1. First we subtract 1 from year number $$a$$, month number $$m$$ and day number $$d$$ to get calculation month number $$m_0$$ and calculation day number $$d_0$$ that begin at 0:

\begin{align} a_0 \| = a − 1 \\ m_0 \| = m − 1 \\ d_0 \| = d − 1 \end{align}

As an example we'll calculate which CJDN corresponds to 29 Shaban 1432, with $$a = 1432, m = 8, d = 29$$. Then

\begin{align*} a_0 \| = a − 1 = 1432 − 1 = 1431 \\ m_0 \| = m − 1 = 8 − 1 = 7 \\ d_0 \| = d − 1 = 29 − 1 = 28 \end{align*}

2. Transformation 1 produces day number $$d_1$$ since the first day of the year from calculation month number $$m_0$$ and calculation day number $$d_0$$:

$$d_1 = \dfloorratio{325m_0 + 5}{11} + d_0$$

In our example we find

\begin{align*} d_1 \| = \dfloorratio{325m_0 + 5}{11} + d_0 = \dfloorratio{325×7 + 5}{11} + 28 \\ \| = \dfloorratio{2280}{11} + 28 = 207 + 28 = 235 \end{align*}

3. Transformation 2 produces the running day number $$s$$ from the calculation year number $$a_0$$ and the day number $$d_1$$ since the first day of the year:

$$s = \dfloorratio{10631a_0 + t}{30} + d_1$$

In our example we find, according to calendar type II:

\begin{align*} s \| = \dfloorratio{10631a_0 + t}{30} + d_1 = \dfloorratio{10631×1431 + 14}{30} + 235 \\ \| = \dfloorratio{15212975}{30} + 235 = 507099 + 235 = 507334 \end{align*}

4. And then we add CJDN $$J_0$$ of the epoch, which is $$J_0 = 1948439$$ for type a en $$J = 1948440$$ for type c.

$$J = s + J_0$$

In our example we find, for calendar type IIc:

$J = s + J_0 = 507334 + 1948440 = 2455774$

so the CJDN that corresponds to 29 Shaban 1432 according to calendar type IIc is 2'455'774.

The aforementioned equations can be condensed to

$$J = \dfloorratio{10631a − 10631 + t}{30} + \dfloorratio{325m − 320}{11} + d − 1 + J_0$$

i.e.,

$${J}$$
Ia $${J = \dfloorratio{10631a − 10616}{30} + \dfloorratio{325m − 320}{11} + d + 1948438}$$
Ic $${J = \dfloorratio{10631a − 10616}{30} + \dfloorratio{325m − 320}{11} + d + 1948439}$$
IIa $${J = \dfloorratio{10631a − 10617}{30} + \dfloorratio{325m − 320}{11} + d + 1948438}$$
IIc $${J = \dfloorratio{10631a − 10617}{30} + \dfloorratio{325m − 320}{11} + d + 1948439}$$
IIIa $${J = \dfloorratio{10631a − 10620}{30} + \dfloorratio{325m − 320}{11} + d + 1948438}$$
IIIc $${J = \dfloorratio{10631a − 10620}{30} + \dfloorratio{325m − 320}{11} + d + 1948439}$$
IVa $${J = \dfloorratio{10631a − 10622}{30} + \dfloorratio{325m − 320}{11} + d + 1948438}$$
IVc $${J = \dfloorratio{10631a − 10622}{30} + \dfloorratio{325m − 320}{11} + d + 1948439}$$

For the same Islamic date as before we now find

\begin{align*} J \| = \dfloorratio{10631×1432 − 10617}{30} + \dfloorratio{325×8 − 320}{11} + 29 + 1948439 \\ \| = \dfloorratio{15212975}{30} + \dfloorratio{2280}{11} + 29 + 1948439 \\ \| = 507099 + 207 + 29 + 1948439 = 2455774 \end{align*}

which is the same answer as before.

Transformation 2 has a limit of $$w/10631$$ Islamic calendar years, which corresponds to $$w/30$$ days. For 32-bit numbers this corresponds to about 202'000 Islamic calendar years. A more detailed search (as described in Sec. 15.2.3) shows that for 32-bit numbers the above formulas produce the correct results for CJDN −69'634'335 through 73'530'873, which corresponds to from somewhere in Islamic year −202'001 to somewhere in year 202'002.

If you want a higher limit then you can calculate using 64-bit numbers or change the formula for $$s$$ by

$$s = 354 a_0 + \dfloorratio{11 a_0 + t}{30} + d_1$$

Then the limit becomes $$w$$ days, and a higher limit is not possible. For 32-bit numbers this corresponds to about 5.9 million years.

Here are some examples (for $$t = 14$$ and $$d_1 = 0$$) of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${a_0}$$ $${10631 a_0 + 14}$$ $${\dfrac{10631 a_0 + 14}{w}}$$ $${s}$$ $${11 a_0 + 14}$$ $${s}$$
200000 2126200014 0.99 70873333 2200014 70873333
6000000 63786000014 29.70 2126200000 66000014 2126200000

#### 16.9.2. From CJDN to Islamic Date

The calculations are schematically as follows:

  a ═(−1)═ a₀ ═══════════╗
m ─(−1)─ m₀ ──┐        ║
d ─(−1)─ d₀ ─(1)─ d₁ ─(2)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$
1 325 11 29 6 5 29.545455
2 10631 30 354 11 t 354.36667

1. First we subtract the CJDN $$J_0$$ of the epoch from the CJDN $$J$$ for which the calendar date is desired, and find running day number $$s$$:

$$s = J − J_0$$

The value of $$J_0$$ depends on the calendar variant, see Table 2.

As an example we calculate the date in the Islamic calendar (variant IIc) that corresponds to CJDN 2'455'774. Then

$s = J − J_0 = 2455774 − 1948440 = 507334$

2. Transformation 2 produces calculation year $$a_0$$ and day number $$d_1$$ since the first day of the year from the running day number $$s$$:

\begin{align} \{ a_0, ε_1 \} \| = \Div(30s + 29 − t, 10631) \\ d_1 \| = \dfloorratio{ε_1}{30} \end{align}

where $$t$$ depends on the chosen calendar variant, see Table 2.

In our example we find

\begin{align*} \{ a_0, ε_1 \} \| = \Div(30s + 29 − t, 10631) = \Div(30×507334 + 29 − 14, 10631) \\ \| = \Div(15220035, 10631) = \{ 1431, 7074 \} \\ d_1 \| = \dfloorratio{ε_1}{30} = \dfloorratio{7074}{30} = 235 \end{align*}

3. Transformation 1 produces calculation month $$m_0$$ and calculation day $$d_0$$ from day number $$d_1$$ since the first day of the year:

\begin{align} \{ m_0, ε_2 \} \| = \Div(11d_1 + 5, 325) \\ d_0 \| = \dfloorratio{ε_2}{11} \end{align}

In our example we find

\begin{align*} \{ m_0, ε_2 \} \| = \Div(11d_1 + 5, 325) = \Div(11×235 + 5, 325) \\ \| = \Div(2590, 325) = \{ 7, 315 \} \\ d_0 \| = \dfloorratio{ε_2}{11} = \dfloorratio{315}{11} = 28 \end{align*}

4. And then we add 1 to the calculation year $$a_0$$, calculation month $$m_0$$, and calculation day $$d_0$$ to find the calendar year $$a$$, calendar month $$m$$, and calendar day $$d$$:

\begin{align} a \| = a_0 + 1 \\ m \| = m_0 + 1 \\ d \| = d_0 + 1 \end{align}

In our example we find

\begin{align*} a \| = a_0 + 1 = 1431 + 1 = 1432 \\ m \| = m_0 + 1 = 7 + 1 = 8 \\ d \| = d_0 + 1 = 28 + 1 = 29 \end{align*}

so CJDN 2'455'774 corresponds to day 29 of month 8 of year 1432 in the Islamic calendar (variant IIc).

The abovementioned equations can be condensed to

\begin{align} \{ a, ε_1 \} \| = \Div(30(J − J_0) + 10660 − t, 10631) \\ \{ m, ε_2 \} \| = \Div(11\dfloorratio{ε_1}{30} + 330, 325) \\ d \| = \dfloorratio{ε_2}{11} + 1 \end{align}

In our example we find (for calendar variant IIc: $$J_0 = 1948440, t = 14$$) for CJDN 2'455'774:

\begin{align*} \{ a, ε_1 \} \| = \Div(30(J − J_0) + 10660 − t, 10631) \\ \| = \Div(30×(2455774 − 1948440) + 10660 − 14, 10631) \\ \| = \Div(15230666, 10631) = \{ 1432, 7074 \} \\ \{ m, ε_2 \} \| = \Div(11\dfloorratio{ε_1}{30} + 330, 325) = \Div(11×\dfloorratio{7074}{30} + 330, 325) \\ \| = \Div(11×235 + 330, 325) = \Div(2915, 325) = \{ 8, 315 \} \\ d \| = \dfloorratio{ε_2}{11} + 1 = \dfloorratio{315}{11} + 1 = 28 + 1 = 29 \end{align*}

so day 29 of month 8 of year 1432, the same as before.

Transformation 2 has a limit of $$w/30$$ days. For 32-bit numbers that corresponds to about 202'000 Islamic calendar years.

If you want a higher limit then you can calculate using 64-bit numbers or replace the formula for $$α_0$$ and $$ε_1$$ with

\begin{align} \{ ω_3, δ_1 \} \| = \Div(s, 10631) \\ \{ α_1, ε_1 \} \| = \Div(30 δ_1 + 29 − t, 10631) \\ a_0 \| = 30 ω_3 + α_1 \end{align}

Then the limit is $$w$$ days, and higher is not possible. That corresponds to about 6.1 million Islamic calendar years.

Here are some examples (with $$t = 14$$) of the original calculation and the calculation with the detour to increase the limit, with the 32-bit $$w$$.

$${s}$$ $${30 s + 15}$$ $${\dfrac{30 s + 15}{w}}$$ $${a_0}$$ $${ε_1}$$ $${ω_3}$$ $${δ_1}$$ $${30 δ_1 + 15}$$ $${α_1}$$ $${ε_1}$$ $${a_0}$$
71000000 2130000015 0.99 200357 4748 6678 6182 185475 17 4748 200357
2140000000 64200000015 29.90 6038942 7613 201298 962 28875 2 7613 6038942

### 16.10. The Maya Calendar

The Maya from Anahuac (Central America) used three different calendars, of which two (the Tzolkin and Haab) were periodic with fairly short periods, and the third one (the Long Count) might have been intended to be periodic but has some periods that are so long that it can be considered to be continuous rather than repeating.

Different areas in Central America had slightly different versions of these calendars, with different names for days and months, and different ways to indicate years, and sometimes days were counted from 0 rather than from 1. Below we describe the calendars from the city of Tikal.

#### 16.10.1. The Haab

The Haab has a day number and a month, but no year number. There are 18 months of 20 days, plus a 19th month of 5 days, which makes 365 days in total, which we call a Haab year. There are no leap years. The months have a name, and the days have a number beginning at 0.

We write a date in the Haab as $$\{ h_d, h_m \}$$ where $$h_d$$ is the day number (from 0 through 19) and $$h_m$$ is the month number (from 1 through 19).

##### 16.10.1.1. From CJDN to Haab

To translate a CJDN $$J$$ to a Haab date $$\{ h_d, h_m \}$$ we must first calculate $$H$$, the number of days since the beginning of the current Haab year (with $$H = 0$$ for the first day of the Haab year).

\begin{align} H \| = \dmod{J + 65}{365} \\ \{ μ_1, h_d \} \| = \Div(H, 20) \\ h_m \| = μ_1 + 1 \end{align}

For example, which Haab date corresponds to 15 December 1965 = CJDN 2'439'110? Then $$J = 2439110$$ and

\begin{align*} H \| = \dmod{J + 65}{365} = \dmod{2439110 + 65}{365} = \dmod{2439175}{365} = 245 \\ \{ μ_1, h_d \} \| = \Div(H, 20) = \Div(245, 20) = \{ 12, 5 \} \\ h_m \| = μ_1 + 1 = 12 + 1 = 13 \end{align*}

so that day is 245 days since the beginning of the current Haab year and corresponds to the 5th day of the 13th month, i.e., $$\{ 5. 13\}$$.

##### 16.10.1.2. From CJDN to Haab

To translate a Haab date $$\{ h_d, h_m \}$$ to a CJDN we first calculate $$H$$:

$$H = h_d + 20(h_m − 1)$$

We know that

$$J ≡ H − 65 \pmod{365}$$

Because there is no year number in the Haab, this Haab date returns every 365 days. We can use equation \eqref{eq:laatste} to find the last $$J$$ that corresponds to this Haab date, on or before a specific $$J_0$$:

$$J = J_0 − \dmod{J_0 − H + 65}{365}$$

Which CJDN corresponds to Haab date $$\{ 5, 13\}$$? Then $$h_d = 5$$, $$h_m = 13$$, so

\begin{align*} H \| = 5 + 20×(13 − 1) = 245 \\ J \| ≡ 245 − 65 ≡ 180 \pmod{365} \end{align*}

That fits the original $$J$$ that we began with in the previous example (2'439'110), because $$2439110 = 6682×365 + 180 ≡ 180 \pmod{365}$$.

What is the last CJDN in the year 1965 that corresponds to Haab date $$\{ 5, 13 \}$$? We seek the last $$J ≡ 180 \pmod{365}$$ on or before CJDN $$J_0 = 2439126$$ (which corresponds to 31 December 1965), using equation \eqref{eq:laatste}. We find

\begin{align*} J \| = J_0 − \dmod{J_0 − 180}{365} = 2439126 − \dmod{2438946}{365} \\ \| = 2439126 − 16 = 2439110 \end{align*}

#### 16.10.2. The Tzolkin

The Tzolkin has a period of 20 days (the venteina) with a name for each day, and a period of 13 days (the trecena) with a number for each day (beginning at 1).

We write a date in the Tzolkin as $$\{ t_t, t_v\}$$, where $$t_t$$ is the day number in the trecena (from 1 through 13) and $$t_v$$ is the day number in the venteina (from 1 through 20).

The trecena and venteina increase simultaneously, so after day $$\{ 4, 7 \}$$ comes day $$\{ 5, 8 \}$$, and then $$\{ 6, 9 \}$$, and so on. Because 13 and 20 are relatively prime, all possible combinations of venteina and trecena occur in this calendar, so after 13×20 = 260 days the dates repeat again.

##### 16.10.2.1. From CJDN to Tzolkin

We translate CJDN $$J$$ to a Tzolkin date $$\{ t_t, t_v \}$$ as follows:

\begin{align} t_t \| = \dmod{J + 5}{13} + 1 \label{eq:trecena2} \\ t_v \| = \dmod{J + 16}{20} + 1 \label{eq:venteina2} \end{align}

What is the Tzolkin date corresponding to CJDN 2'439'110? Then

\begin{align*} t_t \| = \dmod{2439110 + 5}{13} + 1 = 3 + 1 = 4 \\ t_v \| = \dmod{2439110 + 16}{20} + 1 = 6 + 1 = 7 \end{align*}

so that date is $$\{ 4, 7 \}$$.

##### 16.10.2.2. From Tzolkin to CJDN

To translate a Tzolkin date $$\{ t_t, t_v \}$$ to a CJDN we need to solve the two simultaneous congruences of equations \eqref{eq:trecena2} and \eqref{eq:venteina2}, i.e.,

\begin{align} J \| ≡ t_t − 6 \pmod{13} \\ J \| ≡ t_v − 17 \pmod{20} \end{align}

We combine those congruences in the way of section 15.10.3. We have $$x_1 = t_t$$, $$x_2 = t_v$$, $$p_1 = 13$$, $$p_2 = 20$$, $$a_1 = 6$$, $$a_2 = 17$$. Then

\begin{align} C_1 \| = x_1 − a_1 = t_t − 6 \\ P_1 \| = p_1 = 13 \end{align}

The greatest common divisor of 13 and 20 is 1:

\begin{align} g_2 \| = 1 \\ Q_1 \| = \frac{P_1}{g_2} = \frac{13}{1} = 13 \\ q_2 \| = \frac{p_2}{g_2} = \frac{20}{1} = 20 \end{align}

We now seek a $$r_2$$ that solves $$r_2Q_1 ≡ 1 \pmod{q_2}$$, i.e., $$13r_2 ≡ 1 \pmod{20}$$, and find $$r_2 = 17$$, because $$13×17 = 221 ≡ 1 \pmod{20}$$.

\begin{align} C_2 \| = C_1 (1 − r_2Q_1) + (x_2 − a_2) r_2Q_1 \notag \\ \| = (t_t − 6)×(1 − 17×13) + (t_v − 17)×17×13 \notag \\ \| = 221 t_v − 220 t_t − 2437 \\ P_2 \| = p_2Q_1 = 20×13 = 260 \end{align}

so the solution is

$$J ≡ 221 t_v − 220 t_t − 2437 = −39 t_v + 40 t_t − 97 \pmod{260}$$

Which days correspond to Tzolkin date $$\{ 4, 7 \}$$? Those days have $$J ≡ −39×7 + 40×4 − 97 ≡ 50 \pmod{260}$$. That fits with $$J = 2439110$$ because $$2439110 = 9381×260 + 50 ≡ 50 \pmod{260}$$.

Because there is no year number in the Tzolkin, this Tzolkin date returns every 260 days. We can use equation \eqref{eq:laatste} to find the last $$J$$ on or before a particular $$J_0$$ that corresponds with this Tzolkin date:

$$J = J_0 − \dmod{J_0 − 40 t_t + 39 t_v + 97}{260}$$

The last Tzolkin date $$\{ 4, 7 \}$$ that occurs on or before 31 December 1965 (= CJDN 2'439'126) is $$J = 2439126 − \dmod{2439126 − 50}{260} = 2439126 − 16 = 2439110$$.

For the number of days $$T$$ since the last $$\{ 1, 1\}$$ we have

\begin{align} T \| ≡ 40 (t_t − 1) − 39 (t_v − 1) \notag \\ \| ≡ 40 t_t − 39 t_v − 1 \notag \\ \| ≡ 40 t_t + 221 t_v − 1 \pmod{260} \end{align}

so

$$T ≡ \dmod{40 t_t + 221 t_v − 1}{260}$$

For CJDN 2'439'110 (with $$\{ t_t, t_v \} = \{ 4, 7 \}$$) we find

$T = \dmod{40×4 + 221×7 − 1}{260} = \dmod{1706}{260} = 146$

so the last day before then that had $$\{ 1, 1 \}$$ was CJDN $$J = 2439110 − 146 = 2438964$$, and that fits, because $$t_t = \dmod{J + 5}{13} + 1 = \dmod{2438969}{13} + 1 = 1$$ and $$t_v = \dmod{J + 16}{20} + 1 = \dmod{2438980}{20} + 1 = 1$$.

#### 16.10.3. Tzolkin and Haab

Sometimes a date is indicated in both Tzolkin and Haab. From CJDN to Tzolkin and Haab is described above. From a date with Tzolkin and Haab to CJDN is a bit more complicated. We need to solve simultaneously:

\begin{align} J \| ≡ H − 65 \pmod{365} \\ J \| ≡ T − 96 \pmod{260} \end{align}

We found the first formula for the Haab alone, and the second formula for the Tzolkin alone. These formulas again have the form from section 15.10.3, with $$x_1 = H$$, $$x_2 = T$$, $$p_1 = 365$$, $$p_2 = 260$$, $$a_1 = 65$$, $$a_2 = 96$$. Then

\begin{align} C_1 \| = x_1 − a_1 = H − 65 \\ P_1 \| = p_1 = 365 \end{align}

The greatest common divisor of 365 and 260 is 5, so

\begin{align} g_2 \| = 5 \\ Q_1 \| = \frac{P_1}{g_1} = \frac{365}{5} = 73 \\ q_2 \| = \frac{p_2}{g_1} = \frac{260}{5} = 52 \end{align}

We now seek $$r_2$$ that satisfies $$r_2Q_1 ≡ 1 \pmod{q_2}$$, i.e., $$73r_2 ≡ 1 \pmod{52}$$, and find $$r_2 = 5$$, because $$73×5 = 365 = 7×52 + 1 ≡ 1 \pmod{52}$$. Then

\begin{align} C_2 \| = C_1 (1 − r_2Q_1) + (x_2 − a_2) r_2Q_1 \notag \\ \| = (H − 65)×(1 − 5×73) + (T − 96)×5×73 \notag \\ \| = 365 T − 364 H − 11380 \\ P_2 \| = p_2Q_1 = 365×52 = 18980 \end{align}

so the solution is

$$J ≡ 365 T − 364 H − 11380 ≡ 365 T − 364 H + 7600 \pmod{18980}$$

The Tzolkin and Haab together have a period of 18980 days, which is approximately 52 years.

Which CJDN corresponds to $$\{t_t,t_v,h_d,h_m\} = \{4,7,5,13\}$$? Then $$H = 245$$ and $$T = 146$$, so $$J ≡ 365×146 − 364×245 + 7600 ≡ −28290 ≡ 9670 \pmod{18980}$$, and that fits with the original $$J = 2439110$$ that we began with, because $$2439110 = 128×18980 + 9670 ≡ 9670 \pmod{18980}$$.

Because $$g_2$$ is not equal to 1, not all possible combinations of $$H$$ and $$T$$ occur in the calendar. The preceding formula yields a $$J$$ for every combination of $$H$$ and $$T$$, but that $$J$$ is only useful for combinations of $$H$$ and $$T$$ that actually occur in the calendar. Those are combinations for which $$H − T ≡ 65 − 96 ≡ 4 \pmod{5}$$.

In the example that we've been using we have $$H = 245$$ and $$T = 146$$, so $$H − T = 99 ≡ 4 \pmod{5}$$, so this combination indeed occurs in this calendar.

#### 16.10.4. The Long Count

The Long Count counts days and has a series of increasingly longer periods. The smallest period contains 20 days, the next one is 18 times longer (i.e., 360 days), and after that each next period is 20 times longer than the previous one. The number for each period begins at 0. Often dates in the Long Count are given with five numbers, but even longer periods are known, up to nine numbers. The longest known period corresponds to about 63 million years. Here we assume that the Long Count has five numbers, and that the fifth number can get arbitrarily long.

The epoch (0.0.0.0.0) of the Long Count probably corresponds to CJDN $$J_0 = 584283$$ (6 September −3113 in the Julian calendar).

The calculations are schematically as follows:

  l₅ ══════════════╗
l₄ ──────────┐   ║
l₃ ──────┐   │   ║
l₂ ──┐   │   │   ║
l₁ ─(1)─(2)─(3)─(4)═ s ═(+J₀)═ J


The summary of the calendar levels is

(n) $${f}$$ $${g}$$ $${q}$$ $${h}$$ $${t}$$ $${p}$$
1 20 1 20 0 0 20
2 360 1 360 0 0 360
3 7200 1 7200 0 0 7200
4 144000 1 144000 0 0 144000

This calendar is so simple that we provide only the condensed version of the formulas.

##### 16.10.4.1. From Long Count to CJDN

Translating a Long Count to CJDN goes as follows:

\begin{align} J \| = l_1 + 20×(l_2 + 18×(l_3 + 20×(l_4 + 20×l_5))) + 584283 \notag \\ \| = l_1 + 20×l_2 + 360×l_3 + 7200×l_4 + 144000×l_5 + 584383 \end{align}

Which CJDN corresponds to Long Count $$L = 12.17.12.5.7$$?

$J = 7 + 20×(5 + 18×(12 + 20×(17 + 20×12))) + 584283 = 2439110$

##### 16.10.4.2. From CJDN to Long Count

Translating CJDN $$J$$ to Long Count $$L = l_5.l_4.l_3.l_2.l_1$$ goes as follows:

\begin{align} \{ l_5, d_5 \} \| = \Div(J − 584383, 144000) \\ \{ l_4, d_4 \} \| = \Div(d_5, 7200) \\ \{ l_3, d_3 \} \| = \Div(d_4, 360) \\ \{ l_2, l_1 \} \| = \Div(d_3, 20) \end{align}

Which Long Count $$L$$ corresponds to CJDN $$J = 2439110$$? Then

\begin{align*} \{l_5, d_5\} \| = \Div(J − 584283, 144000) = \Div(2438110 − 584283, 144000) \\ \| = \Div(2438110 − 584283, 144000) = \Div(1854827, 144000) = \{ 12, 126827 \} \\ \{l_4, d_4\} \| = \Div(d_5, 7200) = \Div(126827, 7200) = \{ 17, 4427 \} \\ \{l_3, d_3\} \| = \Div(d_4, 360) = \Div(4427, 360) = \{ 12, 107 \} \\ \{l_2, l_1\} \| = \Div(d_3, 20) = \Div(107, 20) = \{ 5, 7 \} \end{align*}

The answer is $$L = 12.17.12.5.7$$.

languages: [en] [nl]

//aa.quae.nl/en/reken/juliaansedag.html;
Last updated: 2022-09-15