\(\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\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 12) 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.
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 | Fractional | 12:00 UTC | |
JDN | Julian Day Number | Whole | 12:00 UTC | = ⌊JD⌋ |
CJD | Chronological Julian Date | Fractional | 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. "Fractional" means that that timescale uses fractional 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, "fractional" 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).
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.
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 \( ⌊x⌋ \)) or upward rounding to the nearest whole number (\( ⌈x⌉ \)). The standard rounding function on calculators usually rounds to the nearest whole number (our notation for that is \( [x] \)) and the standard conversion from a fractional 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) \)). We do not want those kinds of rounding here! The below table shows these three different kinds of rounding for some values.
\({x}\) | \({⌊x⌋}\) | \({[x]}\) | \({⌈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 |
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 = y − x\dfloorratio{y}{x} \\ y \| = qx + r \end{align}
The notation \( y \bmod x \) means: the non-negative remainder from the division of \( y \) by \( x \).
We find
\begin{equation} \frac{y}{x} = \dfloorratio{y}{x} + \left( \frac{y}{x} \bmod 1 \right) = \dfloorratio{y}{x} + \frac{y \bmod x}{x} \end{equation}
and if \( x = 1 \) then
\begin{equation} y = ⌊y⌋ + (y \bmod 1) \end{equation}
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} \).
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,
See section 13.2.1 for the derivation of this algorithm.
One algorithm to calculate a CJDN \( J \) from a Gregorian date (calendar year \( j \), calendar month \( m \), calendar day \( d \)) is:
\begin{align} c_0 \| = \dfloorratio{m − 3}{12} \\ x_4 \| = j + c_0 \\ \{x_3, x_2\} \| = \Div(x_4, 100) \\ x_1 \| = m − 12c_0 − 3 \\ J \| = \dfloorratio{146097x_3}{4} + \dfloorratio{36525x_2}{100} + \dfloorratio{153x_1 + 2}{5} + d + 1721119 \end{align}
Here \( J_1 \) is the number of days from the beginning of calculation year 0 until the beginning of the current 100-calculation-year-period, \( J_2 \) the number of days since the beginning of the current 100-calculation-year-period, and \( J_3 \) the number of days minus one from the beginning of the current calculation year until the beginning of the current month. Calculation years run from 1 March to 1 March.
\begin{align*} c_0 \| = \dfloorratio{9 − 3}{12} = 0 \\ x_4 \| = 2010 + 0 = 2010 \\ \{x_3, x_2\} \| = \Div(2010, 100) = \{20, 10\} \\ x_1 \| = 9 − 12×0 − 3 = 6 \\ J \| = \dfloorratio{146097×20}{4} + \dfloorratio{36525×10}{100} + \dfloorratio{153×6 + 2}{5} + 7 + 1721119 \\ \| = 730485 + 3652 + 184 + 7 + 1721119 = 2455447 \end{align*}
And here are the calculations for a few more dates:
calendar date | \({c_0}\) | \({x_4}\) | \({x_3}\) | \({x_2}\) | \({x_1}\) | \({…x_3…}\) | \({…x_2…}\) | \({…x_1…}\) | \({J}\) |
---|---|---|---|---|---|---|---|---|---|
2000-02-29 | −1 | 1999 | 19 | 99 | 11 | 693960 | 36159 | 337 | 2451604 |
2000-03-01 | 0 | 2000 | 20 | 0 | 0 | 730485 | 0 | 0 | 2451605 |
2001-02-28 | −1 | 2000 | 20 | 0 | 11 | 730485 | 0 | 337 | 2451969 |
2001-03-01 | 0 | 2001 | 20 | 1 | 0 | 730485 | 365 | 0 | 2451970 |
2100-02-28 | −1 | 2099 | 20 | 99 | 11 | 730485 | 36159 | 337 | 2488128 |
2100-03-01 | 0 | 2100 | 21 | 0 | 0 | 767009 | 0 | 0 | 2488129 |
The algorithm to calculate a Gregorian date (calendar year \( j \), calendar month \( m \), calendar day \( d \)) from a CJDN \( J \) is:
\begin{align} \{x_3, r_3\} \| = \Div(4×J − 6884477, 146097) \\ \{x_2, r_2\} \| = \Div\left( 100\dfloorratio{r_3}{4} + 99, 36525 \right) \\ \{x_1, r_1\} \| = \Div\left( 5\dfloorratio{r_2}{100} + 2, 153 \right) \\ d \| = \dfloorratio{r_1}{5} + 1 \\ c_0 \| = \dfloorratio{x_1 + 2}{12} \\ j \| = 100x_3 + x_2 + c_0 \\ m \| = x_1 − 12c_0 + 3 \end{align}
Here \( x_3 \) is the number of calculation centuries since that time, \( x_2 \) the number of calculation years since that time, and \( x_1 \) the number of months since the beginning of the current calculation year.
For example, which date in the Gregorian calendar corresponds to CJDN 2452827? Then \( J = 2452827 \) and then
\begin{align*} k_3 \| = 4×(2452827 − 1721120) + 3 = 2926831 \\ x_3 \| = \dfloorratio{2926831}{146097} = 20 \\ k_2 \| = 100\dfloorratio{2926831 \bmod 146097}{4} + 99 = 100\dfloorratio{4891}{4} + 99 = 100×1222 + 99 = 122299 \\ x_2 \| = \dfloorratio{122299}{36525} = 3 \\ k_1 \| = 5\dfloorratio{122299 \bmod 36525}{100} + 2 = 5×\dfloorratio{12724}{100} + 2 = 5×127 + 2 = 637 \\ x_1 \| = \dfloorratio{k_1}{153} = \dfloorratio{637}{153} = 4 \\ c_0 \| = \dfloorratio{4 + 2}{12} = 0 \\ j \| = 100×20 + 3 + 0 = 2003 \\ m \| = 4 − 12×0 + 3 = 7 \\ d \| = \dfloorratio{637 \bmod 153}{5} + 1 = \dfloorratio{25}{5} + 1 = 5 + 1 = 6 \end{align*}
The date is 6 July 2003.
And here are the calculations for the same dates as before.
\({J}\) | \({x_3}\) | \({x_2}\) | \({x_1}\) | \({c_0}\) | \({j}\) | \({m}\) | \({d}\) | calendar date |
---|---|---|---|---|---|---|---|---|
2451604 | 19 | 99 | 11 | 1 | 2000 | 2 | 29 | 2000-02-29 |
2451605 | 20 | 0 | 0 | 0 | 2000 | 3 | 1 | 2000-03-01 |
2451969 | 20 | 0 | 11 | 1 | 2001 | 2 | 28 | 2001-02-28 |
2451970 | 20 | 1 | 0 | 0 | 2001 | 3 | 1 | 2001-03-01 |
2488128 | 20 | 99 | 11 | 1 | 2100 | 2 | 28 | 2100-02-28 |
2488129 | 21 | 0 | 0 | 0 | 2100 | 3 | 1 | 2100-03-01 |
See section 13.3 for the derivation of this algorithm.
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 \( j \), calendar month \( m \), calendar day \( d \)) is:
\begin{align} c_0 \| = \dfloorratio{m − 3}{12} \\ x_4 \| = j + c_0 \\ x_3 \| = \dfloorratio{x_4}{100} \\ x_2 \| = x_4 \bmod 100 \\ x_1 \| = m − 12c_0 − 3 \\ J \| = \dfloorratio{328718x_3 + 6}{9} + \dfloorratio{36525x_2}{100} + \dfloorratio{153x_1 + 2}{5} + d + 1721119 \end{align}
An algorithm to convert CJDN \( J \) to year \( j \), month \( m \), day \( d \) in the Milanković calendar is:
\begin{align} k_3 \| = 9×(J − 1721120) + 2 \\ x_3 \| = \dfloorratio{k_3}{328718} \\ k_2 \| = 100\dfloorratio{k_3 \bmod 328718}{9} + 99 \\ x_2 \| = \dfloorratio{k_2}{36525} \\ x_1 \| = \dfloorratio{5\dfloorratio{k_2 \bmod 36525}{100} + 2}{153} \\ c_0 \| = \dfloorratio{x_1 + 2}{12} \\ j \| = 100x_3 + x_2 + c_0 \\ m \| = x_1 − 12c_0 + 3 \\ d \| = \dfloorratio{k_1 \bmod 153}{5} + 1 \end{align}
See section 13.1.1 for the derivation of this algorithm.
The algorithm to calculate a CJDN \( J \) from a Julian date (calendar year \( j \), calendar month \( m \), calendar day \( d \)) is:
\begin{align} J_0 \| = 1721117 \\ c_0 \| = \dfloorratio{m − 3}{12} \\ J_1 \| = \dfloorratio{1461×(j + c_0)}{4} \\ J_2 \| = \dfloorratio{153m − 1836c_0 − 457}{5} \\ J \| = J_1 + J_2 + d + J_0 \end{align}
Here \( J_1 \) is the number of days between the beginning of calculation year 0 and the beginning of the current calculation year, and \( J_2 \) the number of days between the beginning of the current calculation year and the beginning of the current month.
\begin{align*} c_0 \| = \dfloorratio{9 − 3}{12} = 0 \\ J_1 \| = \dfloorratio{1461×(2010 + 0)}{4} = 734152 \\ J_2 \| = \dfloorratio{153×9 − 1836×0 − 457}{5} = 184 \\ J \| = 734152 + 184 + 7 + 1721117 = 2455460 \end{align*}
And here are the calculations for a few more dates:
calendar date | \({c_0}\) | \({J_1}\) | \({J_2}\) | \({J}\) |
---|---|---|---|---|
2000-02-29 | −1 | 730134 | 337 | 2451617 |
2000-03-01 | 0 | 730500 | 0 | 2451618 |
2001-02-28 | −1 | 730500 | 337 | 2451982 |
2001-03-01 | 0 | 730865 | 0 | 2451983 |
2100-02-28 | −1 | 766659 | 337 | 2488141 |
2100-02-29 | −1 | 766659 | 337 | 2488142 |
2100-03-01 | 0 | 767025 | 0 | 2488143 |
The algorithm to calculate a Julian date (calendar year \( j \), calendar month \( m \), calendar day \( d \)) from a CJDN \( J \) is:
\begin{align} y_2 \| = J − 1721118 \\ k_2 \| = 4y_2 + 3 \\ k_1 \| = 5\dfloorratio{k_2 \bmod 1461}{4} + 2 \\ x_1 \| = \dfloorratio{k_1}{153} \\ c_0 \| = \dfloorratio{x_1 + 2}{12} \\ j \| = \dfloorratio{k_2}{1461} + c_0 \\ m \| = x_1 − 12c_0 + 3 \\ d \| = \dfloorratio{k_1 \bmod 153}{5} + 1 \end{align}
\begin{align*} y_2 \| = 2451893 − 1721118 = 730775 \\ k_2 \| = 4×730775 + 3 = 2923103 \\ k_1 \| = 5\dfloorratio{2923103 \bmod 1461}{4} + 2 = 5\dfloorratio{1103}{4} + 2 = 5×275 + 2 = 1377 \\ x_1 \| = \dfloorratio{1377}{153} = 9 \\ c_0 \| = \dfloorratio{9 + 2}{12} = \dfloorratio{11}{12} = 0 \\ j \| = \dfloorratio{2923103}{1461} + 0 = 2000 + 0 = 2000 \\ m \| = 9 − 12×0 + 3 = 12 \\ d \| = \dfloorratio{1377 \bmod 153}{5} + 1 = \dfloorratio{0}{5} + 1 = 1 \end{align*}
The date is 1 December 2000.
And here are the calculations for the same dates as before.
\({J}\) | \({y_2}\) | \({k_2}\) | \({k_1}\) | \({x_1}\) | \({c_0}\) | \({j}\) | \({m}\) | \({d}\) | calendar date |
---|---|---|---|---|---|---|---|---|---|
2451617 | 730499 | 2921999 | 1827 | 11 | 1 | 2000 | 2 | 29 | 2000-02-29 |
2451618 | 730500 | 2922003 | 2 | 0 | 0 | 2000 | 3 | 1 | 2000-03-01 |
2451982 | 730864 | 2923459 | 1822 | 11 | 1 | 2001 | 2 | 28 | 2001-02-28 |
2451983 | 730865 | 2923463 | 2 | 0 | 0 | 2001 | 3 | 1 | 2001-03-01 |
2488141 | 767023 | 3068095 | 1822 | 11 | 1 | 2100 | 2 | 28 | 2100-02-28 |
2488142 | 767024 | 3068099 | 1827 | 11 | 1 | 2100 | 2 | 29 | 2100-02-29 |
2488143 | 767025 | 3068103 | 2 | 0 | 0 | 2100 | 3 | 1 | 2100-03-01 |
See section 13.8 for the derivation of this algorithm.
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 \( j \), 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:
\begin{equation} J = \dfloorratio{10631j − 10617}{30} + \dfloorratio{325m − 320}{11} + d + 1948439 \end{equation}
\[ \begin{split} J \| = \dfloorratio{10631×1432 − 10617}{30} + \dfloorratio{325×8 − 320}{11} + 29 + 1948440 \\ \| = \dfloorratio{15212975}{30} + \dfloorratio{2280}{11} + 29 + 1948440 \\ \| = 507099 + 207 + 29 + 1948439 \\ \| = 2455774 \end{split} \]
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 \( j = 1 \), \( m = 1 \), \( d = 1 \), so
\[ \begin{split} J \| = \dfloorratio{10631×1 − 10617}{30} + \dfloorratio{325×1 − 320}{11} + 1 + 1948439 \\ \| = \dfloorratio{14}{30} + \dfloorratio{5}{11} + 1 + 1948440 = 0 + 0 + 1 + 1948439 = 1948440 \end{split} \]
which corresponds to 16 July 622 in the Julian calendar.
The following formulas calculate the year number \( j \), month number \( m \), and day number \( d \) in the most commonly used administrative Islamic calendar from the CJDN \( J \):
\begin{align} k_2 \| = 30×(J − 1948440) + 15 \\ k_1 \| = 11\dfloorratio{k_2 \bmod 10631}{30} + 5 \\ j \| = \dfloorratio{k_2}{10631} + 1 \\ m \| = \dfloorratio{k_1}{325} + 1 \\ d \| = \dfloorratio{k_1 \bmod 325}{11} + 1 \end{align}
\begin{align*} k_2 \| = 30×(2455774 − 1948440) + 15 = 15220035 \\ k_1 \| = 11×\dfloorratio{15220035 \bmod 10631}{30} + 5 = 11×\dfloorratio{7074}{30} + 5 = 11×235 + 5 = 2590 \\ j \| = \dfloorratio{15220035}{10631} + 1 = 1431 + 1 = 1432 \\ m \| = \dfloorratio{2590}{325} + 1 = 7 + 1 = 8 \\ d \| = \dfloorratio{2590 \bmod 325}{11} + 1 = \dfloorratio{315}{11} + 1 = 29 \end{align*}
so \( j = 1432 \), \( m = 8 \), \( d = 29 \) which means 29 Sha`ban 1432.
See section 13.5 for the derivation of this algorithm.
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 \( j \) 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:
\begin{align} y_1 \| = \dfloorratio{235j − 241}{19} + m \\ J \| = \dfloorratio{6940y_1}{235} + d + 1607557 \end{align}
\begin{align*} x_1 \| = 2 \\ z_1 \| = 8 \\ z_2 \| = 26 \\ c_1 \| = \dfloorratio{235×2 + 13}{19} = \dfloorratio{483}{19} = 25 \\ x_2 \| = y_1 = 25 + 8 = 33 \\ c_2 \| = \dfloorratio{6940×33}{235} = \dfloorratio{229020}{235} = 974 \\ y_2 \| = 974 + 26 = 1000 \\ J \| = 1000 + 1607558 = 1607658 \end{align*}
From CJDN \( J \), we find the Babylonian year number \( j \), month number \( m \), and day number \( d \) as follows:
\begin{align} k_2 \| = 235×(J − 1607558) + 234 \\ k_1 \| = 19\dfloorratio{k_2}{6940} + 5 \\ j \| = \dfloorratio{k_1}{235} + 1 \\ m \| = \dfloorratio{k_1 \bmod 235}{19} + 1 \\ d \| = \dfloorratio{k_2 \bmod 6940}{235} + 1 \end{align}
\begin{align*} k_2 \| = 235×(1608558 − 1607558) + 234 = 235234 \\ k_1 \| = 19×\dfloorratio{235234}{6940} + 5 = 19×33 + 5 = 632 \\ j \| = \dfloorratio{632}{235} + 1 = 3 \\ m \| = \dfloorratio{632 \bmod 235}{19} + 1 = \dfloorratio{162}{19} + 1 = 9 \\ d \| = \dfloorratio{235234 \bmod 6940}{235} + 1 = \dfloorratio{6214}{235} + 1 = 27 \end{align*}
See section 13.6 for the derivation of this algorithm.
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. The algorithm that I provide here uses only whole numbers (to avoid round-off error), and assumes that all input values, intermediate results, and output values cannot be greater than 231 = 2,147,483,648.
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 \( j \), calendar month \( m \) (from 1 through 12 or 13), and calendar day \( d \) (from 1 through 29 or 30) into CJDN is then:
\begin{align} c_0 \| = \dfloorratio{13 − m}{7} \\ x_1 \| = j − 1 + c_0 \\ x_3 \| = m − 1 \\ z_4 \| = d − 1 \\ c_1(x_1) \| = \dfloorratio{235x_1 + 1}{19} \\ q(x_1) \| = \dfloorratio{c_1(x_1)}{1095} \\ r(x_1) \| = c_1(x_1) \bmod 1095 \\ υ_1(x_1) \| = 32336q(x_1) + \dfloorratio{15q(x_1) + 765433r(x_1) + 12084}{25920} \\ υ_2(x_1) \| = υ_1(x_1) + \left(\dfloorratio{6×(υ_1(x_1) \bmod 7)}{7} \bmod 2\right) \end{align}
Calculate in the same way also \( υ_2(x_1 + 1) \). Then
\begin{align} L_2(x_1) \| = υ_2(x_1 + 1) − υ_2(x_1) \\ L_2(x_1 − 1) \| = υ_2(x_1) − υ_2(x_1 − 1) \\ v_3 \| = 2\left(\dfloorratio{L_2(x_1) + 19}{15} \bmod 2\right) \\ v_4 \| = \dfloorratio{L_2(x_1 − 1) + 7}{15} \bmod 2 \\ c_2(x_1) \| = υ_2 + v_3 + v_4 \end{align}
Calculate in the same way also \( c_2(x_1 + 1) \) (which means you need to calculate \( υ_2(x_1 + 2) \), too). Then
\begin{align} L \| = c_2(x_1 + 1) − c_2(x_1) \\ c_8 \| = \dfloorratio{L + 7}{2} \bmod 15 \\ c_9 \| = −\left( \dfloorratio{385 − L}{2} \bmod 15 \right) \\ c_3 \| = \dfloorratio{384x_3 + 7}{13} + c_8\dfloorratio{x_3 + 4}{12} + c_9\dfloorratio{x_3 + 3}{12} \\ c_4(x_1,x_3) \| = c_2(x_1) + c_3(x_3) \\ J \| = J_0 − 177 + c_4(x_1,x_3) + z_4 = 347821 + c_2(x_1) + c_3 + z_4 \end{align}
As an example, we'll calculate which CJDN corresponds to 18 Sivan A.M. 4682. Then \( j = 4682 \), \( m = 3 \), \( d = 18 \). And then
\begin{align*} c_0 \| = \dfloorratio{13 − m}{7} \\ \| = \dfloorratio{13 − 3}{7} \\ \| = \dfloorratio{10}{7} = 1 \\ x_1 \| = j − 1 + c_0 = 4682 − 1 + 1 = 4682 \\ x_3 \| = m − 1 = 3 − 1 = 2 \\ z_4 \| = d − 1 = 18 − 1 = 17 \\ c_1(4681) \| = c_1(x_1 − 1) = \dfloorratio{235×(x_1 − 1) + 1}{19} \\ \| = \dfloorratio{235×4681 + 1}{19} \\ \| = \dfloorratio{1100036}{19} = 57896 \\ c_1(4682) \| = c_1(x_1) = \dfloorratio{235×x_1 + 1}{19} \\ \| = \dfloorratio{235×4682 + 1}{19} \\ \| = \dfloorratio{1100270 + 1}{19} \\ \| = \dfloorratio{1100271}{19} = 57909 \\ c_1(4683) \| = c_1(x_1 + 1) = \dfloorratio{235×(x_1 + 1) + 1}{19} \\ \| = \dfloorratio{235×4683 + 1}{19} \\ \| = \dfloorratio{1100506}{19} = 57921 \\ c_1(4684) \| = c_1(x_1 + 2) = \dfloorratio{235×(x_1 + 2) + 1}{19} \\ \| = \dfloorratio{235×4684 + 1}{19} \\ \| = \dfloorratio{1100741}{19} = 57933 \\ q(4681) \| = q(x_1 − 1) = \dfloorratio{c_1(x_1 − 1)}{1095} \\ \| = \dfloorratio{57896}{1095} = 52 \\ r(4681) \| = r(x_1 − 1) = c_1(x_1 − 1) \bmod 1095 \\ \| = 57896 \bmod 1095 = 956 \\ υ_1(4681) \| = υ_1(x_1 − 1) = 32336×q(x_1 − 1) \\ \| + \dfloorratio{15×q(x_1 − 1) + 765433×r(x_1 − 1) + 12084}{25920} \\ \| = 32336×52 + \dfloorratio{15×52 + 765433×956 + 12084}{25920} \\ \| = 1681472 + \dfloorratio{731766812}{25920} \\ \| = 1681472 + 28231 = 1709703 \\ υ_2(4681) \| = υ_2(x_1 − 1) = υ_1(x_1 − 1) + \left( \dfloorratio{6×(υ_1(x_1 − 1) \bmod 7)}{7} \bmod 2\right) \\ \| = 1709703 + \left( \dfloorratio{6×(1709703 \bmod 7)}{7} \bmod 2 \right) \\ \| = 1709703 + \left( \dfloorratio{6×2}{7} \bmod 2 \right) \\ \| = 1709703 + \left( \dfloorratio{12}{7} \bmod 2 \right) \\ \| = 1709703 + (1 \bmod 2) = 1709703 + 1 = 1709704 \\ q(4682) \| = q(x_1) = \dfloorratio{c_1(x_1)}{1095} \\ \| = \dfloorratio{57909}{1095} = 52 \\ r(4682) \| = r(x_1) = c_1(x_1) \bmod 1095 = 57909 \bmod 1095 = 969 \\ υ_1(4682) \| = υ_1(x_1) = 32336×q(x_1) \\ \| + \dfloorratio{15×q(x_1) + 765433×r(x_1) + 12084}{25920} \\ \| = 32336×52 + \dfloorratio{15×52 + 765433×969 + 12084}{25920} \\ \| = 1681472 + \dfloorratio{741717441}{25920} \\ \| = 1681472 + 28615 = 1710087 \\ υ_2(4682) \| = υ_2(x_1) = υ_1(x_1) + \left( \dfloorratio{6×(υ_1(x_1) \bmod 7)}{7} \bmod 2 \right) \\ \| = 1710087 + \left( \dfloorratio{6×(1710087 \bmod 7)}{7} \bmod 2 \right) \\ \| = 1710087 + \left( \dfloorratio{1}{7} \bmod 2 \right) = 1710087 + (0 \bmod 2) \\ \| = 1710087 + 0 = 1710087 \\ q(4683) \| = q(x_1 + 1) = \dfloorratio{c_1(x_1 + 1)}{1095} \\ \| = \dfloorratio{57921}{1095} = 52 \\ r(4683) \| = r(x_1 + 1) = c_1(x_1 + 1) \bmod 1095 \\ \| = 57921 \bmod 1095 = 981 \\ υ_1(4683) \| = υ_1(x_1 + 1) = 32336×q(x_1 + 1) \\ \| + \dfloorratio{15×q(x_1 + 1) + 765433×r(x_1 + 1) + 12084}{25920} \\ \| = 332336×52 + \dfloorratio{15×52 + 765433×981 + 12084}{25920} \\ \| = 17281472 + \dfloorratio{750902637}{25920} \\ \| = 17281472 + 28970 = 17310442 \\ υ_2(4683) \| = υ_2(x_1 + 1) = υ_1(x_1 + 1) \\ \| + \left( \dfloorratio{6×(υ_1(x_1 + 1) \bmod 7}){7} \bmod 2 \right) \\ \| = 1710442 + \left( \dfloorratio{6×(1710442 \bmod 7)}{7} \bmod 2 \right) \\ \| = 1710442 + \left( \dfloorratio{6×6}{7} \bmod 2 \right) \\ \| = 1710442 + \left( \dfloorratio{36}{7} \bmod 2 \right) \\ \| = 1710442 + (5 \bmod 2) = 1710442 + 1 = 1710443 \\ q(4684) \| = q(x_1 + 2) = \dfloorratio{c_1(x_1 + 2)}{1095} \\ \| = \dfloorratio{57933}{1095} = 52 \\ r(4684) \| = r(x_1 + 2) = c_1(x_1 + 2) \bmod 1095 \\ \| = 57933 \bmod 1095 = 993 \\ υ_1(4684) \| = υ_1(x_1 + 2) = 32336×q(x_1 + 2) \\ \| + \dfloorratio{15×q(x_1 + 2) + 765433×r(x_1 + 2) + 12084}{25920} \\ \| = 32336×52 + \dfloorratio{15×52 + 765433×993 + 12084}{25920} \\ \| = 1681472 + \dfloorratio{760087833}{25920} \\ \| = 1681472 + 29324 = 1710796 \\ υ_2(4684) \| = υ_2(x_1 + 2) = υ_1(x_1 + 2) + \left( \dfloorratio{6×(υ_1(x_1 + 2) \bmod 7)}{7} \bmod 2 \right) \\ \| = 1710796 + \left( \dfloorratio{6×(1710796 \bmod 7)}{7} \bmod 2 \right) \\ \| = 1710796 + \left( \dfloorratio{6×3}{7} \bmod 2 \right) \\ \| = 1710796 + \left( \dfloorratio{18}{7} \bmod 2 \right) = 1710796 + (2 \bmod 2) \\ \| = 1710796 + 0 = 1710796 \\ L_2(4681) \| = L_2(x_1 − 1) = υ_2(x_1) − υ_2(x_1 − 1) \\ \| = 1710087 − 1709704 = 383 \\ L_2(4682) \| = L_2(x_1) = υ_2(x_1 + 1) − υ_2(x_1) \\ \| = 1710443 − 1710087 = 356 \\ L_2(4683) \| = L_2(x_1 + 1) = υ_2(x_1 + 2) − υ_2(x_1 + 1) \\ \| = 1710796 − 1710443 = 353 \\ v_3(4682) \| = v_3(x_1) = 2×\left( \dfloorratio{L_2(x_1) + 19}{15} \bmod 2 \right) \\ \| = 2×\left( \dfloorratio{356 + 19}{15} \bmod 2 \right) \\ \| = 2×\left( \dfloorratio{375}{15} \bmod 2 \right) \\ \| = 2×(25 \bmod 2) = 2 \\ v_4(4682) \| = v_4(x_1) = \dfloorratio{L_2(x_1 − 1) + 7}{15} \bmod 2 \\ \| = \dfloorratio{383 + 7}{15} \bmod 2 \\ \| = \dfloorratio{390}{15} \bmod 2 = 26 \bmod 2 = 0 \\ c_2(4682) \| = c_2(x_1) = υ_2(x_1) + v_3(x_1) + v_4(x_1) \\ \| = 1710087 + 2 + 0 = 1710089 \end{align*}
\begin{align*} v_3(4683) \| = v_3(x_1 + 1) = 2×\left( \dfloorratio{L_2(x_1 + 1) + 19}{15} \bmod 2 \right) \\ \| = 2×\left( \dfloorratio{353 + 19}{15} \bmod 2 \right) \\ \| = 2×\left( \dfloorratio{372}{15} \bmod 2 \right) \\ \| = 2×(24 \bmod 2) = 0 \\ v_4(4683) \| = v_4(x_1 + 1) = \dfloorratio{L_2(x_1) + 7}{15} \bmod 2 \\ \| = \dfloorratio{356 + 7}{15} \bmod 2 \\ \| = \dfloorratio{363}{15} \bmod 2 = 24 \bmod 2 = 0 \\ c_2(4683) \| = c_2(x_1 + 1) = υ_2(x_1 + 1) + v_3(x_1 + 1) + v_4(x_1 + 1) = 1710443 \\ L \| = y_2(x_1 + 1) − y_2(x_1) = 1710443 − 1710089 = 354 \\ c_8 \| = \dfloorratio{L + 7}{2} \bmod 15 \\ \| = \dfloorratio{354 + 7}{2} \bmod 15 \\ \| = \dfloorratio{361}{2} \bmod 15 = 180 \bmod 15 = 0 \\ c_9 \| = −\left( \dfloorratio{385 − L}{2} \bmod 15 \right) \\ \| = −\left( \dfloorratio{385 − 354}{2} \bmod 15 \right) \\ \| = −\left( \dfloorratio{31}{2} \bmod 15 \right) \\ \| = −(15 \bmod 15) = 0 \\ c_3 \| = \dfloorratio{384×x_3 + 7}{13} + c_8×\dfloorratio{x_3 + 4}{12} + c_9×\dfloorratio{x_3 + 3}{12} \\ \| = \dfloorratio{384×2 + 7}{13} + 0×\dfloorratio{2 + 4}{12} + 0×\dfloorratio{2 + 3}{12} \\ \| = \dfloorratio{775}{13} + 0 + 0 = 59 \\ c_4 \| = c_2 + c_3 = 1710089 + 59 = 1710148 \\ J \| = J_0 − 177 + c_4 + z_4 = 347821 + 1710148 + 17 = 2057986 \end{align*}
This date corresponds to 17 June 922 in the Julian calendar.
From CJDN \( J \) we go to Jewish year \( j \), month \( m \), and day \( d \):
\begin{align} y_4 \| = J − 347821 \\ q \| = \dfloorratio{y_4}{1447} \\ r \| = y_4 \bmod 1447 \\ y_1' \| = 49q + \dfloorratio{23q + 25920r + 13835}{765433} \\ γ_1 \| = y_1' + 1 \\ ξ_1 \| = \dfloorratio{19γ_1 + 17}{235} \\ μ_1 \| = γ_1 − \dfloorratio{235ξ_1 + 1}{19} \end{align}
Calculate \( c_{41}' = c_4(ξ_1, μ_1) \) in the way described in the previous section. Then
\begin{align} ζ_1 \| = y_4 − c_{41}' \\ γ_2 \| = γ_1 + \dfloorratio{ζ_1}{33} \\ ξ_2 \| = \dfloorratio{19γ_2 + 17}{235} \\ μ_2 \| = γ_2 − \dfloorratio{235ξ_2 + 1}{19} \end{align}
Calculate \( c_{42}' = c_4(ξ_2, μ_2) \) in the way described in the previous section. Then
\begin{align} ζ_2 \| = y_4 − c_{42}' \\ γ_3 \| = γ_2 + \dfloorratio{ζ_1}{33} \\ x_1 \| = ξ_3 = \dfloorratio{19γ_3 + 17}{235} \\ x_3 \| = μ_3 = γ_3 − \dfloorratio{235ξ_3 + 1}{19} \end{align}
Calculate \( c_{43}' = c_4(ξ_3, μ_3) \) in the way described in the previous section. Then
\begin{align} z_4 \| = ζ_3 = y_1 − c_{43}' \\ c \| = \dfloorratio{12 − x_3}{7} \\ j \| = x_1 + 1 − c \\ m \| = x_3 + 1 \\ d \| = z_4 + 1 \end{align}
For \( J = 2057986 \) we find
\begin{align*} y_4 \| = J − 347821 = 2057986 − 347821 = 1710165 \\ q \| = \dfloorratio{y_4}{1447} = \dfloorratio{1710165}{1447} = 1181 \\ r \| = y_4 \bmod 1447 = 1710165 \bmod 1447 = 1258 \\ y_1' \| = 49q + \dfloorratio{23q + 25920r + 13835}{765433} \\ \| = 49×1181 + \dfloorratio{23×1181 + 25920×1258 + 13835}{765433} \\ \| = 57869 + \dfloorratio{32648358}{765433} = 57869 + 42 = 57911 \\ γ_1 \| = y_1' + 1 = 57911 + 1 = 57912 \\ ξ_1 \| = \dfloorratio{19γ_1 + 17}{235} \\ \| = \dfloorratio{19×57912 + 17}{235} \\ \| = \dfloorratio{1100345}{235} = 4682 \\ μ_1 \| = γ_1 − \dfloorratio{235ξ_1 + 1}{19} \\ \| = 57912 − \dfloorratio{235×4682 + 1}{19} \\ \| = 57912 − \dfloorratio{1100271}{19} = 57912 − 57909 = 3 \end{align*}
In the way described in the previous section we calculate that
\[ c_{41}' = c_4(ξ_1,μ_1) = c_4(4682,3) = 1710178 \]
Then
\begin{align*} ζ_1 \| = y_4 − c_{41}' = 1710165 − 1710178 = −13 \\ γ_2 \| = γ_1 + \dfloorratio{ζ_1}{33} = 57912 + \dfloorratio{−13}{33} = 57912 + −1 = 57911 \\ ξ_2 \| = \dfloorratio{19γ_2 + 17}{235} = \dfloorratio{19×57911 + 17}{235} = \dfloorratio{1100326}{235} = 4682 \\ μ_2 \| = γ_2 − \dfloorratio{235ξ_2 + 1}{19} = 57911 − \dfloorratio{235×4682 + 1}{19} \\ \| = 57911 − \dfloorratio{1100271}{19} = 57911 − 57909 = 2 \end{align*}
In the way described in the previous section we calculate that
\[ c_{42} = c_4(ξ_2,μ_2) = c_4(4682,2) = 1710148 \]
Then
\begin{align*} ζ_2 \| = y_4 − c_{42}' = 1710165 − 1710148 = 17 \\ γ_3 \| = γ_2 + \dfloorratio{ζ_2}{33} = 57911 + \dfloorratio{17}{33} = 57911 + 0 = 57911 \end{align*}
Because in this example \( ζ_3 = ζ_2 \), also \( ξ_3 = ξ_2 \), \( μ_3 = μ_2 \), \( c_4(ξ_3,μ_3) = c_4(ξ_2,μ_2) \), and \( ζ_3 = ζ_2 \), so in this example you need not calculate \( ξ_3 \), \( μ_3 \), \( c_4(ξ_3,μ_3) \), \( ζ_3 \) explicitly, but you can still do so if that is more convenient.
\begin{align*} x_1 \| = ξ_3 = \dfloorratio{19γ_3 + 17}{235} = \dfloorratio{19×57911 + 17}{235} = \dfloorratio{1100326}{235} = 4682 \\ x_3 \| = μ_3 = γ_3 − \dfloorratio{235ξ_3 + 1}{19} = 57911 − \dfloorratio{235×4682 + 1}{19} \\ \| = 57911 − \dfloorratio{1100271}{19} = 57911 − 57909 = 2 \end{align*}
In the way described in the previous section we calculate that
\[ c_{43}' = c_4(ξ_3,μ_3) = c_4(4682,2) = 1710148 \]
Then
\begin{align*} z_4 \| = ζ_3 = y_4 − c_{43}' = 1710165 − 1710148 = 17 \\ c \| = \dfloorratio{12 − x_3}{7} = \dfloorratio{12 − 2}{7} = \dfloorratio{10}{7} = 1 \\ j \| = x_1 + 1 − c = 4682 + 1 − 1 = 4682 \\ m \| = x_3 + 1 = 2 + 1 = 3 \\ d \| = z_4 + 1 = 17 + 1 = 18 \end{align*}
so the desired date in the Jewish calendar is day 18 of month 3 (Sivan) of year 4682: 18 Sivan A.M. 4682.
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.
The algorithm to translate an Egyptian date (calendar year \( j \), calendar month \( m \), calendar day \( d \)) to CJDN \( J \) is as follows:
\begin{equation} J = 365 j + 30 m + d + 1448242 \end{equation}
For example, which CJDN corresponds to day 7 of month 5 of year 218 in the Egyptian calendar? Then we find
\begin{align*} J \| = 365j + 30m + d + 1448242 \\ \| = 365×218 + 30×5 + 7 + 1448242 \\ \| = 79570 + 150 + 7 + 1448242 = 1527969 \end{align*}
so the answer is CJDN 1527969.
In the opposite direction, the calculations are simple as well.
\begin{align} y_2 \| = J − 1448638 \\ x_2 \| = \dfloorratio{y_2}{365} \\ y_1 \| = y_2 \bmod 365 \\ j \| = x_2 + 1 \\ m \| = \dfloorratio{y_1}{30} + 1 \\ d \| = y_1 − 30m + 31 = (y_1 \bmod 30) + 1 \end{align}
What date in the Egyptian calendar corresponds to CJDN 1527969? Then
\begin{align*} y_2 \| = J − J_0 = 1527969 − 1448638 = 79331 \\ x_2 \| = \dfloorratio{y_2}{365} = \dfloorratio{79331}{365} = 217 \\ y_1 \| = y_2 − 365x_2 = 79331 − 365×217 = 79331 − 79205 = 126 \\ j \| = x_2 + 1 = 217 + 1 = 218 \\ m \| = \dfloorratio{y_1}{30} + 1 = \dfloorratio{126}{30} + 1 = 4 + 1 = 5 \\ d \| = y_1 − 30m + 31 = 126 − 30×5 + 31 = (y_1 \bmod 30) + 1 = (126 \bmod 30) + 1 = 6 + 1 = 7 \end{align*}
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.
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 − ((J_0 − H + 65) \bmod 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 \| = 5 + 20×(13 − 1) = 245 \\ J \| = J_0 − ((J_0 − H + 65) \bmod 365) \\ \| = 2439126 − (2438946 \bmod 365) \\ \| = 2439126 − 16 = 2439110 \end{align*}
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:
\begin{equation} J = J_0 − ((J_0 − 40 t_t + 39 t_v + 97) \bmod 260) \end{equation}
The last Tzolkin date \( \{4,7\} \) that occurs on or before 31 December 1965 (= CJDN 2439126) is
\begin{align*} J \| = 2439126 − ((2439126 − 40×4 + 39×7 + 97) \bmod 260) \\ \| = 2439126 − (2439336 \bmod 260) \\ \| = 2439126 − 16 = 2439110 \end{align*}
For the number of days \( T \) since the last \( \{1,1\} \) we have
\begin{equation} T = (40 t_t + 221 t_v − 1) \bmod 260 \end{equation}
For CJDN 2439110 (with \( \{t_t,t_v\} = \{4,7\} \)) we find
\begin{align*} T \| = (40×4 + 221×7 − 1) \bmod 260 \\ \| = 1706 \bmod 260 = 146 \end{align*}
so the last day before then that had \( \{1,1\} \) was CJDN \( J = 2439110 − 146 = 2438964 \), and that fits, because \( t_t = ((J + 5) \bmod 13) + 1 = (2438969 \bmod 13) + 1 = 1 \) and \( t_v = ((J + 16) \bmod 20) + 1 = (2438980 \bmod 20) + 1 = 1 \).
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 \| = (h_d + 20 × (h_m − 1)) \bmod{365} \\ T \| = (40t_t + 221 t_v − 1) \bmod{260} \\ J \| = J_0 − ((J_0 − 365 T + 364 H − 7600) \bmod{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 \| = (5 + 20×12) \bmod{365} = 245 \bmod{365} = 245 \\ T \| = (40×4 + 221×7 − 1) \bmod{260} = 1706 \bmod{260} = 146 \\ J \| = 2439126 − ((2439126 − 365×146 + 364×245 − 7600) \bmod{18980}) \\ \| = 2439126 − (2467416 \bmod{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.
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{equation} \begin{split} J \| = l_1 + 20×(l_2 + 18×(l_3 + 20×(l_4 + 20×l_5))) + J_0 \\ \| = l_1 + 20×l_2 + 360×l_3 + 7200×l_4 + 144000×l_5 \end{split} \end{equation}
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 \]
We calculate Haab date \( \{h_d,h_m\} \) from CJDN \( J \) as follows:
\begin{align} H \| = (J + 65) \bmod 365 \\ h_m \| = \dfloorratio{H}{20} + 1 \\ h_d \| = H \bmod 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 \| = (J + 65) \bmod 365 = 2439175 \bmod 365 = 245 \\ h_m \| = \dfloorratio{245}{20} + 1 = 13 \\ h_d \| = 245 \bmod 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\} \).
We translate CJDN \( J \) to a Tzolkin date as follows:
\begin{align} t_t \| = ((J + 5) \bmod{13}) + 1 \label{eq:trecena} \\ t_v \| = ((J + 16) \bmod{20}) + 1 \label{eq:venteina} \end{align}
What is the Tzolkin date corresponding to CJDN 2439110? Then
\begin{align*} t_t \| = ((2439110 + 5) \bmod{13}) + 1 = 3 + 1 = 4 \\ t_v \| = ((2439110 + 16) \bmod{20}) + 1 = 6 + 1 = 7 \end{align*}
so that date is \( \{4,7\} \).
Translating CJDN \( J \) to Long Count \( L ≡ l_5.l_4.l_3.l_2.l_1 \) goes as follows:
\begin{align} x_5 \| = J − J_0 \\ l_5 \| = \dfloorratio{x_5}{144000} \\ x_4 \| = x_5 \bmod 144000 \\ l_4 \| = \dfloorratio{x_4}{7200} \\ x_3 \| = x_4 \bmod 7200 \\ l_3 \| = \dfloorratio{x_3}{360} \\ x_2 \| = x_3 \bmod 360 \\ l_2 \| = \dfloorratio{x_2}{20} \\ l_1 \| = x_2 \bmod 20 \end{align}
Which Long Count \( L \) corresponds to CJDN \( J = 2439110 \)? Then
\begin{align*} x_5 \| = J − J_0 = 2439110 − 584283 = 1854827 \\ l_5 \| = \dfloorratio{1854827}{144000} = 12 \\ x_4 \| = 1854827 \bmod 144000 = 126827 \\ l_4 \| = \dfloorratio{126827}{7200} = 17 \\ x_3 \| = 126827 \bmod 7200 = 4427 \\ l_3 \| = \dfloorratio{4427}{360} = 12 \\ x_2 \| = 4427 \bmod 360 = 107 \\ l_2 \| = \dfloorratio{107}{20} = 5 \\ l_1 \| = 107 \bmod 20 = 7 \end{align*}
The answer is \( L = 12.17.12.5.7 \).
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.
354 | 355 | 384 | |
---|---|---|---|
Month | Days | ||
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 |
Given year \( j \), month \( m \), and day \( d \) in this lunar calendar, the running day number \( y_2 \) can be calculated as follows:
\begin{equation} y_2 = 354j + 29m + 30\dfloorratio{7j − 6}{19} + \dfloorratio{4j + 8}{19} + \dfloorratio{7m}{13} + d − 384 \end{equation}
For example, which running day number corresponds to day 27 of month 9 of year 3 in this calendar? Then
\begin{align*} j \| = 3 \\ m \| = 9 \\ d \| = 27 \\ y_2 \| = 354×3 + 29×9 + 30\dfloorratio{7×3 − 6}{19} + \dfloorratio{4×3 + 8}{19} + \dfloorratio{7×9}{13} + 27 − 384 \\ \| = 1323 + 30\dfloorratio{15}{19} + \dfloorratio{20}{19} + \dfloorratio{63}{13} − 357 \\ \| = 1323 + 0 + 1 + 4 − 357 = 971 \end{align*}
Given running day number \( y_2 \), we calculate year \( j \), month \( m \), and day \( d \) in this lunar calendar as follows:
\begin{align} x' \| = \dfloorratio{19y_2 + 546}{6940} \\ x_2 \| = x' + \dfloorratio{y_2 − 354x' − 30\dfloorratio{7x' + 1}{19} − \dfloorratio{4x' + 12}{19}}{385} \\ k_1 \| = 13×\left( y_2 − 354x_2 − 30\dfloorratio{7x_2 + 1}{19} − \dfloorratio{4x_2 + 12}{19} \right) + 5 \\ j \| = x_2 + 1 \\ m \| = \dfloorratio{k_1}{384} + 1 \\ d \| = \dfloorratio{k_1 \bmod 384}{13} + 1 \end{align}
For example, which day in this calendar corresponds to running day number 971? Then \( y_2 = 971 \) and then
\begin{align*} x' \| = \dfloorratio{19×971 + 546}{6940} = \dfloorratio{18995}{6940} = 2 \\ x_2 \| = 2 + \dfloorratio{971 − 354×2 − 30 \dfloorratio{7×2 + 1}{19} − \dfloorratio{4×2 + 12}{19}}{385} \\ \| = 2 + \dfloorratio{263 − 30 \dfloorratio{15}{19} − \dfloorratio{20}{19}}{385} \\ \| = 2 + \dfloorratio{263 − 0 − 1}{385} = 2 \\ k_1 \| = 13×\left( 971 − 354×2 − 30\dfloorratio{7×2 + 1}{19} − \dfloorratio{4×2 + 12}{19} \right) + 9 \\ \| = 13×\left( 263 − 30\dfloorratio{15}{19} − \dfloorratio{20}{19} \right) + 9 \\ \| = 13×(263 − 0 − 1) + 5 = 3411 \\ j \| = 2 + 1 = 3 \\ m \| = \dfloorratio{3411}{384} + 1 = 9 \\ d \| = \dfloorratio{3411 \bmod 384}{13} + 1 = \dfloorratio{339}{13} + 1 = 27 \end{align*}
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.
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 \( j \) as follows:
\begin{align} s \| = ((j + 6) \bmod 10) + 1 \label{eq:jnaarchinees} \\ b \| = ((j + 8) \bmod 12) + 1 \end{align}
The number \( n \) in the combined cycle of 60 years is
\begin{equation} n = ((j + 56) \bmod 60) + 1 \end{equation}
For example, for the year 2000 in the Gregorian calendar:
\begin{align*} s \| = ((2000 + 6) \bmod 10) + 1 = 6 + 1 = 7 \\ b \| = ((2000 + 8) \bmod 12) + 1 = 4 + 1 = 5 \\ n \| = ((2000 + 56) \bmod 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} j \| ≡ 1983 + s \pmod{10} \\ j \| ≡ 1983 + b \pmod{12} \\ j \| ≡ 1983 + n \pmod{60} \end{align}
The years that have celestial stem \( s \) as well as terrestrial branch \( b \) are
\begin{equation} j ≡ 1983 + 25b − 24s \pmod{60} \label{eq:chineesnaarj} \end{equation}
For example, for \( s = 7 \) we find
\[ j ≡ 1983 + 7 = 1990 \pmod{10} \]
so 1990 and every 10 years earlier or later, so 2000 fits, too.
For \( b = 5 \) we find
\[ j ≡ 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
\[ j ≡ 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: \( j ≡ 1983 + 25×6 − 24×3 = 2061 \pmod{60} \), but if you enter \( j = 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.
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, j_2 \} \| = \Div(j + 67016, 10800) \\ \{ Y − 1, j_3 \} \| = \Div(j_2, 360) \\ \{ S − 1, N − 1 \} \| = \Div(j_3, 30) \end{align}
For example, which HYSN year corresponds approximately to our year 2016? Then
\begin{align*} j \| = 2016 \\ \{ H − 1, j_2 \} \| = \Div(2016 + 67016, 10800) = \Div(69032, 10800) = \{ 6, 4232 \} \\ H \| = 7 \\ j_2 \| = 4232 \\ \{ Y − 1, j_3 \} \| = \Div(4232, 360) = \{ 11, 272 \} \\ Y \| = 12 \\ j_3 \| = 272 \\ \{ S − 1, N − 1 \} \| = \Div(272, 30) = \{ 9, 2 \} \\ S \| = 10 \\ N \| = 3 \end{align*}
so the HYSN year number is 0712-1003.
In the other direction things are simpler. Given \( H \), \( Y \), \( S \), and \( N \), the Gregorian year is
\begin{equation} j = H×10800 + Y×360 + S×30 + N − 78207 \end{equation}
For example, HYSN 0712-1003 means
\begin{align*} H \| = 7 \\ Y \| = 12 \\ S \| = 10 \\ N \| = 3 \\ j \| = 7×10800 + 12×360 + 10×30 + 3 − 78207 \\ \| = 75600 + 4320 + 300 + 3 − 78207 = 2016 \end{align*}
We can derive many calendar formulas by finding straight lines that, with rounding, yield the correct results.
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 \).
\begin{equation} \dmod{x}{p} ≡ x \bmod p ≡ x − p\dfloorratio{x}{p} \label{eq:mod} \qquad (p \gt 0)\end{equation}
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 \| = p\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 |
\begin{equation} \ddom{x}{p} ≡ x \bdom p ≡ p\dceilratio{x}{p} − x \qquad (p \gt 0) \label{eq:dom} \end{equation}
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 \)):
And their proofs:
\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}
\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}
\( \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} \)).
\( \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}
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
\begin{equation} 0 \lt \dmod{x}{1} \lt 1 ⇒ \dceil{\dmod{x}{1}} = 1 \end{equation}
and also
\begin{equation} −1 \lt −\dmod{x}{1} \lt 0 ⇒ \dfloor{−\dmod{x}{1}} = −1 \end{equation}
so then, too, \( \dfloor{−x} + \dceil{x} = \dceil{\dmod{x}{1}} + \dfloor{−\dmod{x}{1}} = 0 \) and so \( \dfloor{−x} = −\dceil{x} \).
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 \).
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}
\( \ddom{−x}{p} = \dmod{x}{p} = −\ddom{x}{p} + pC(x⊥p) \) follows from the previous one if you replace every \( x \) with \( −x \).
\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
\begin{equation} \dfloor{x + y} = \dfloor{x} + \dfloor{y} + C\dparen{\dmod{x}{1} + \dmod{y}{1} \ge 1} \end{equation}
\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
\begin{equation} \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} \end{equation}
which completes the proof.
\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}
That leads to
\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} − 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}
\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} + 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}
\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
\begin{equation} \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} \end{equation}
which completes the proof.
Then
\begin{equation} x − y − 1 \lt \dfloor{x} − \dfloor{y} \lt x − y + 1 \end{equation}
because
\begin{equation} 0 \le \dmod{•}{1} \lt 1 \end{equation}
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}
Then
\begin{equation} x − y − 1 \lt \dceil{x} − \dceil{y} \lt x − y + 1 \end{equation}
because
\begin{equation} 0 \le \ddom{•}{1} \lt 1 \end{equation}
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}
\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}
\begin{equation} \ddom{x}{y} = \ddom{x}{1} = 0 = y − 1 − \ddom{x − 1}{y} \qquad (x ∥ 1) \end{equation}
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}
\begin{align} \{ k, α \} \| = \Div(x, y) \\ \{ m, β \} \| = \Div(α, 1) \end{align}
so
\begin{equation} x = ky + α = ky + m + β \end{equation}
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
\begin{equation} \dfloor{\dmod{x}{y}} = \dmod{\dfloor{x}}{y} \end{equation}
Many of the calendar calculations that are described below are of the type
\begin{align} y \| = \dfloorratio{fx + t}{d} \label{eq:template} \\ e \| = \dmod{fx + t}{d} = (fx + t) \bmod d \label{eq:template-e} \end{align}
i.e.,
\[ \{y, e\} = \Div(fx + t, d) \]
with
\begin{equation} fx + t = dy + e \end{equation}
where \( f \), \( t \), \( d \) are fixed whole numbers with \( f, d \gt 1 \) and \( 0 ≤ e \lt d \) and \( y \), \( x \) 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 give trouble on calculators and in computer programs where whole numbers cannot exceed a certain size that we'll refer to as \( w \). (Floating-point numbers like 1.234 × 1020 can be much greater, but have limited accuracy, and then you have to worry about round-off errors.)
Intermediate results greater than \( w \) give trouble, so to avoid trouble we'd need roughly \( |fx| ≤ w \), so \( |x| ≤ w/f \), which is much less than \( w \) itself.
If \( |t| ≥ d \), then we can rewrite equation \eqref{eq:template}ff to
\begin{align} fx + t \| = fx + \dfloorratio{t}{d} d + \dmod{t}{d} = dy + e \eqavide{eq:mod} \\ y \| = \dfloorratio{fx + t}{d} = \dfloorratio{t}{d} + \dfloorratio{fx + \dmod{t}{d}}{d} \\ e \| = \dmod{fx + t}{d} = \dmod{fx + \dmod{t}{d}}{d} \eqavide{eq:modmod} \end{align}
where the second term of the last two equations has the same form as equation \eqref{eq:template}, if you rename \( \dmod{t}{d} \) to a new \( t \). Below, we assume that that has been done, which means that \( 0 ≤ t \lt d \).
If \( f \gt d \), then we can rewrite equation \eqref{eq:template}ff to
\begin{align} fx + t \| = \dparen{\dfloorratio{f}{d} d + \dmod{f}{d}} x + t = dy + e \eqavide{eq:mod} \\ y \| = \dfloorratio{f}{d} x + \dfloorratio{\dmod{f}{d} x + t}{d} \label{eq:template2} \\ e \| = \dmod{\dmod{f}{d} x + t}{d} \end{align}
Then \( |x| \) may be roughly as great as \( w/\dmod{f}{d} \) before we run into trouble.
Equations \eqref{eq:template2}ff again have the form of equations \eqref{eq:template}ff, if you rename \( \dmod{f}{d} \) to a new \( f \). Below, we assume that this has been done, so that \( f \lt d \).
If we could first do the division by \( d \) and then the multiplication by \( f \), then the intermediate results would stay smaller than \( x \) itself. We'd like to calculate something like \( f\dfloorratio{x}{d} \) which is roughly equal to \( y \), and then apply a correction to get the real \( y \).
We can rewrite equation \eqref{eq:template}ff to
\begin{align} fx + t \| = f\dparen{ \dfloorratio{x}{d} d + \dmod{x}{d}} + t \eqavide{eq:mod} \\ y \| = f\dfloorratio{x}{d} + \dfloorratio{f\dmod{x}{d} + t}{d} \label{eq:detour1} \\ e \| = \dmod{f\dmod{x}{d} + t}{d} \end{align}
Now the greatest intermediate result is no longer \( fx + t \), which can get as large as \( fw \), but \( f\dmod{x}{d} + t \), which cannot exceed \( fd \lt d^2 \).
Equations \eqref{eq:detour1}ff again have the form of equations \eqref{eq:template}ff, if you rename \( \dmod{x}{d} \) to a new \( x \).
For example, let \( d = 12345 \), \( f = 8432 \), \( t = 871 \), and \( w = 2^{31} − 1 = 2147483647 \), and suppose we want to calculate \( y \), \( e \) for \( x = 300000 \).
We use the detour of equation \eqref{eq:detour1}. We find
\begin{align*} \dfloorratio{x}{d} \| = \dfloorratio{300000}{12345} = 24 \\ \dmod{x}{d} \| = \dmod{300000}{12345} = 3720 \\ y = \| f\dfloorratio{x}{d} + \dfloorratio{f\dmod{x}{d} + t}{d} \\ \| = 8432×24 + \dfloorratio{8432×3720 + 871}{12345} \\ \| = 202368 + \dfloorratio{31367911}{12345} \\ \| = 202368 + 2540 = 204908 \\ e \| = \dmod{31367911}{12345} = 11611 \end{align*}
The greatest intermediate result is 31'367'911, which is much less than \( w \).
If we could have used arbitrarily large intermediate results, then we'd have found
\begin{align*} y \| = \dfloorratio{fx + t}{d} = \dfloorratio{8432×300000 + 871}{12345} = \dfloorratio{2529600871}{12345} = 204908 \\ e \| = \dmod{2529600871}{12345} = 11611 \end{align*}
which are the same results, but with a greatest intermediate result of 2'529'600'871 which is greater than \( w \).
Sometimes an intermediate result of (nearly) \( fd \) is still too great, because the product of two numbers can be much greater than \( w \) even if the two numbers are each much less than \( w \). If the product must remain less than \( w \), then the two numbers cannot both be greater than \( \sqrt{w} \), which is a lot less than \( w \) itself. For example, for 32-bit numbers, \( w = 2^{31} − 1 = 2147483647 \) and \( \sqrt{w} = 46341 \), so even if \( d \) and \( f \) are both just a bit greater than 46431, which isn't really very large, then \( fd \) is already too great to fit into a 32-bit number.
Suppose we pick a whole number \( P \gt 0 \) and then calculate one time
\begin{align} \{Q, R\} \| = \Div(fP, d) \label{eq:PQR} \\ Q \| = \dfloorratio{fP}{d} \\ R \| = \dmod{fP}{d} \end{align}
so
\begin{equation} fP = dQ + R \end{equation}
Then, for each desired \( x \), calculate
\begin{align} \{q, r\} \| = \Div(x, P) \\ q \| = \dfloorratio{x}{P} \\ r \| = \dmod{x}{P} \end{align}
so
\begin{equation} x = qP + r \end{equation}
and then
\begin{align} fx + t \| = fqP + fr + t = qdQ + qR + fr + t \\ y \| = \dfloorratio{qdQ + qR + fr + t}{d} = qQ + \dfloorratio{qR + fr + t}{d} \label{eq:detour2} \\ e \| = \dmod{qdQ + qR + fr + t}{d} = \dmod{qR + fr + t}{d} \end{align}
Now the greatest intermediate result is \( m ≡ qR + fr + t \). To stay out of trouble we need \( \dabs{m} ≤ w \), so (because \( r \lt P \))
\begin{eqnarray} \dabs{x}\frac{R}{P} + fP + t ≤ w \\ \dabs{x} ≤ X ≡ \dparen{w − fP − t}\dfrac{P}{R} \end{eqnarray}
We have \( f \lt d \) so \( f \) is not a multiple of \( d \) so \( R \gt 0 \).
We must have \( 0 \lt P \lt \dfrac{w − t}{f} \), otherwise certainly \( X ≤ 0 \).
For example, let \( d = 765433 \), \( f = 25920 \), \( t = 13835 \), \( w = 2^{31} − 1 = 2147483647 \). Then we need, to get \( X ≥ 0 \),
\[ P \lt \dfrac{w − t}{f} = \dfrac{2147483647 − 13835}{25920} = 82849.9 \]
Some examples:
\({P}\) | \({Q}\) | \({R}\) | \({X}\) | \({X/w}\) |
---|---|---|---|---|
1 | 0 | 25920 | 82848.9 | 0.000 |
2 | 0 | 51840 | 82847.9 | 0.000 |
3 | 0 | 77760 | 82846.9 | 0.000 |
29 | 0 | 751680 | 82820.9 | 0.000 |
30 | 1 | 12167 | 5.29307 × 10+06 | 0.002 |
31 | 1 | 38087 | 1.74723 × 10+06 | 0.001 |
59 | 1 | 763847 | 165754 | 0.000 |
60 | 2 | 24334 | 5.29115 × 10+06 | 0.002 |
943 | 31 | 714137 | 2.8034 × 10+06 | 0.001 |
944 | 31 | 740057 | 2.70805 × 10+06 | 0.001 |
945 | 32 | 544 | 3.68789 × 10+09 | 1.717 |
33783 | 1144 | 8 | 5.37071 × 10+12 | 2500.932 |
82849 | 2805 | 406515 | 4836.65 | 0.000 |
82850 | 2805 | 432435 | −419.198 | −0.000 |
We want to make the range of \( x \) as large as possible, so we seek \( P \) and \( R \) such that \( X \) becomes as great as possible, given \( w \), \( f \), \( t \). This means that \( R \) should preferably be small.
If \( P \) increases slowly (with steps of 1) then \( R = \dmod{fP}{d} \) varies strongly between 0 and \( d − 1 \), so the value of \( R \) is independent of the global magnitude of \( P \), and many different values of \( P \) are possible for the same smallest value of \( R \).
If \( R \) has the smallest possible value (greater than zero), then roughly what should the value of \( P \) be that yields the greatest value of \( X \)?
Then \( X \) is a quadratic function of \( P \). If \( P \) could have any value then the greatest possible value of \( X \) would occur for
\begin{equation} P = P_0 = \dfrac{w − t}{2f} \end{equation}
and be equal to
\begin{equation} \max(X) = \dfrac{\dparen{w − t}^2}{4Rf} = \dfrac{fP_0^2}{R} \end{equation}
To get \( \max(X) ≥ w \) we'd certainly need
\begin{equation} R ≤ \dfrac{w}{4f}\dparen{1−\dfrac{t}{w}}^2 \label{eq:maxR} \end{equation}
The least possible value that \( R \) can have is equal to the greatest common divisor \( \gcd(f, d) \) of \( f \) and \( d \).
\begin{equation} R = R_1 ≡ \gcd(f, d) \end{equation}
The Extended Algorithm of Euclid produces that value, and also numbers \( x \) and \( y \) such that
\begin{equation} fx + dy = R \end{equation}
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):
\begin{equation} f\dparen{x + k\dfrac{d}{R}} + d\dparen{y − k\dfrac{f}{R}} = R \end{equation}
Because \( R \) is a divisor of \( d \) and also of \( f \), the divisions by \( R \) in this formula always produce whole numbers.
The corresponding possible values of \( P \) and \( Q \) are then:
\begin{align} P \| = x + k\dfrac{d}{R} \\ Q \| = −y + k\dfrac{f}{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}{d/R_1} \\ Q_1 \| = \dmod{−y}{f/R_1} \end{align}
These \( P_1, Q_1, R_1 \) comply with equations \eqref{eq:PQR}ff, because
\begin{equation} \dfloorratio{fP_1}{d} = \dfloorratio{dQ_1 + R_1}{d} = Q_1 + \dfloorratio{R_1}{d} = Q_1 \end{equation}
because \( \dfloor{R_1/d} = 0 \), because \( R_1 = \gcd(f,d) \lt d \), because\( f \lt d \). And if \( Q_1 \) fits then \( R_1 \) fits, too.
To get \( X \gt 0 \) we certainly need \( P ≤ w/f \), so the greatest usable \( P \) is
\begin{equation} P_\text{max} = \dfrac{w}{f} − \dmod{\dfrac{w}{f} − P_1}{d/R_1} \end{equation}
The step size between successive values of \( P \) that fit with this \( R \) is \( d/R \) so if \( d/R \gt w/f \) (so \( fd/R \gt w \)) then there may be no acceptable value of \( P \) for this \( R \) at all. In that case \( P_\text{max} \lt 0 \).
For the same case as in the previous example we find with the Extended Algorithm of Euclid
\[ fx + dy = 25920×99902 − 765433×3383 = 1 \]
so
\begin{align*} x \| = 99902 \\ y \| = −3383 \\ R_1 \| = 1 \\ P_1 \| = \dmod{x}{d/R} = \dmod{99902}{765433} = 99902 \\ Q_1 \| = \dmod{−y}{f/R} = \dmod{3383}{25920} = 3383 \\ P_\text{max} \| = \dfrac{w}{f} − \dmod{\dfrac{w}{f} − P_1}{d/R_1} \\ \| = \dfrac{2147483647}{25920} − \dmod{\dfrac{2147483647}{25920} − 99902}{765433/1} \\ \| = 82850.4493441 − \dmod{82850.4493441 − 99902}{765433} \\ \| = 82850.4493441 − \dmod{−17051.5506559}{765433} \\ \| = 82850.4493441 − 748381.449344 = −665531 \end{align*}
so \( P_\text{max} \lt 0 \) so for this \( R \) we cannot find an acceptable value of \( P \) in this way.
If you cannot find an acceptable value of \( P \) for \( R = R_1 \), then try ever greater multiples of \( R_1 \) until you do find an acceptable \( P \). That is possible, because we have
\begin{equation} fP_1 − dQ_1 = R_1 \end{equation}
so also
\begin{equation} fnP_1 − dnQ_1 = nR_1 \end{equation}
for arbitrary \( n \).
But \( nP_1 \) must not be greater than \( w/f \) so \( n \) must not be greater than \( w/(fP_1) \) which often isn't very large.
In our example, \( n \) must not be greater than
\[ \dfrac{w}{fP_1} = \dfrac{2147483647}{25920×99902} = \dfrac{2147483647}{2589459840} = 0.829317224321 \]
which is even less than 1.
To yet find more smaller values of \( P \) we can make use of the modulus function. If we use for \( P \)
\begin{equation} P = \dmod{nP_1}{(d/R_1)} \end{equation}
then
\begin{align} \dfrac{nP_1R_1}{d} \| = n\dfrac{R_1}{f}\dfrac{dQ_1 + R_1}{d} \\ P \| = \dfrac{d}{R_1}\dmod{\dfrac{nP_1R_1}{d}}{1} \\ \dfrac{fP}{d} \| = \dfrac{f}{R_1}\dmod{\dfrac{nP_1R_1}{d}}{1} = \dfrac{f}{R_1}\dmod{n\dfrac{R_1}{f}\dfrac{dQ_1 + R_1}{d}}{1} \notag \\ \| = \dmod{nQ_1 + \dfrac{nR_1}{d}}{(f/R_1)} \\ Q \| = \dfloorratio{fP}{d} = \dfloor{\dmod{nQ_1 + \dfrac{nR_1}{d}}{(f/R_1)}} \notag \\ \| = \dmod{\dfloor{nQ_1 + \dfrac{nR_1}{d}}}{(f/R_1)} = \dmod{nQ_1 + \dfloor{\dfrac{nR_1}{d}}}{(f/R_1)} \eqvide{eq:modfloor} \\ R \| = fP − dQ \notag \\ \| = d\dmod{nQ_1 + \dfrac{nR_1}{d}}{(f/R_1)} − d\dmod{nQ_1 + \dfloor{\dfrac{nR_1}{d}}}{(f/R_1)} \notag \\ \| = d\dmod{nQ_1 + \dfloor{\dfrac{nR_1}{d}} + \dmod{\dfrac{nR_1}{d}}{1}}{(f/R_1)} − d\dmod{nQ_1 + \dfloor{\dfrac{nR_1}{d}}}{(f/R_1)} \notag \\ \| = d\dmod{nQ_1 + \dfloor{\dfrac{nR_1}{d}}}{(f/R_1)} + d\dmod{\dmod{\dfrac{nR_1}{d}}{1}}{(f/R_1)} \notag \\ \| − \dfrac{fd}{R_1} C\dparen{\dmod{nQ_1 + \dfloor{\dfrac{nR_1}{d}}}{(f/R_1)} + \dmod{\dmod{\dfrac{nR_1}{d}}{1}}{(f/R_1)} ≥ \dfrac{f}{R_1}} \notag \\ \| − d\dmod{nQ_1 + \dfloor{\dfrac{nR_1}{d}}}{(f/R_1)} \notag \\ \| = d\dmod{\dmod{\dfrac{nR_1}{d}}{1}}{(f/R_1)} \notag \\ \| − \dfrac{fd}{R_1} C\dparen{\dmod{nQ_1 + \dfloor{\dfrac{nR_1}{d}}}{(f/R_1)} + \dmod{\dmod{\dfrac{nR_1}{d}}{1}}{(f/R_1)} ≥ \dfrac{f}{R_1}} \end{align}
We have \( f/R_1 ≥ 1 \) and \( 0 ≤ \dmod{nR_1/d}{1} \lt 1 \) so the \( \dmod{•}{(f/R_1)} \) surrounding that has no effect, so
\begin{equation} d\dmod{\dmod{\dfrac{nR_1}{d}}{1}}{(f/R_1)} = d\dmod{\dfrac{nR_1}{d}}{1} = \dmod{nR_1}{d} \end{equation}
Likewise, the formula within the \( C(•) \) can be rewritten as
\begin{equation} \dmod{nQ_1 + \dfloor{\dfrac{nR_1}{d}}}{(f/R_1)} + \dmod{\dfrac{nR_1}{d}}{1} ≥ \dfrac{f}{R_1} \end{equation}
We have
\begin{align} nQ_1 + \dfloorratio{nR_1}{d} \le \dfrac{f}{R_1} − 1 \\ \dmod{\dfrac{nR_1}{d}}{1} \lt 1 \end{align}
because \( nQ_1 \) and \( \dfloor{nR_1/d} \) and also \( f/R_1 \) are whole numbers. So the sum of those two is less than \( f/R_1 \), so the condition within the \( C(•) \) is never met, so that term drops away. All in all we find
\begin{align} P \| = \dmod{nP_1}{(d/R_1)} \\ Q \| = \dmod{nQ_1 + \dfloorratio{nR_1}{d}}{(f/R_1)} \\ R \| = \dmod{nR_1}{d} \end{align}
For calculating these numbers the following form is more convenient:
\begin{align} P \| = \dmod{nP_1}{(d/R_1)} \\ \{ ρ, R \} \| = \Div(nR_1, d) \\ Q \| = \dmod{nQ_1 + ρ}{(f/R_1)} \end{align}
As long as \( n \lt d/R_1 \), also \( \dfloor{nR_1/d} = 0 \) so \( Q = \dmod{nQ_1}{(f/R_1)} \). That will usually be the case in practice.
With our example (\( P_1 = 99902, Q_1 = 3383, R_1 = 1, d = 765433, f = 25920, t = 13835 \)) we find
\begin{align*} P \| = \dmod{99902n}{765433} \\ \{ ρ, R \} \| = \Div(n, 765433) \\ Q \| = \dmod{3383n + ρ}{25920} \end{align*}
\({n}\) | \({P}\) | \({ρ}\) | \({R}\) | \({Q}\) | \({fP−dQ}\) | \({X/w}\) |
---|---|---|---|---|---|---|
1 | 99902 | 0 | 1 | 3383 | 1 | −20561.6 |
2 | 199804 | 0 | 2 | 6766 | 2 | −141024.5 |
3 | 299706 | 0 | 3 | 10149 | 3 | −261487.5 |
4 | 399608 | 0 | 4 | 13532 | 4 | −381950.5 |
5 | 499510 | 0 | 5 | 16915 | 5 | −502413.4 |
6 | 599412 | 0 | 6 | 20298 | 6 | −622876.3 |
7 | 699314 | 0 | 7 | 23681 | 7 | −743339.3 |
8 | 33783 | 0 | 8 | 1144 | 8 | +2500.9 |
9 | 133685 | 0 | 9 | 4527 | 9 | −9114.0 |
765432 | 665531 | 0 | 765432 | 22536 | 765432 | −6.1 |
765433 | 0 | 1 | 0 | 0 | 0 | |
765434 | 99902 | 1 | 1 | 3383 | 1 | −20561.6 |
765435 | 199804 | 1 | 2 | 6766 | 2 | −141024.5 |
so \( n = 8 \) is the smallest value of \( n \) for which we find \( X \gt w \).
To find
\begin{equation} X = (w − fP − t)\dfrac{P}{R} \gt 0 \end{equation}
we need \( P \) to be close enough to \( P_0 = (w − t)/(2f) \).
With \( P = \dmod{nP_1}{(d/R_1)} \), the smallest positive value \( n_0 \) of \( n \) for which exactly \( P = P_0 \) is \( n_0 = P_0/P_1 \) and each next value of \( n \) for which \( P = P_0 \) is \( d/P_1R_1 \) greater than the previous one, so the values \( n_k \) of \( n \) for which \( P = P_0 \) are
\begin{equation} n_k = \dfrac{P_0}{P_1} + k\dfrac{d}{P_1R_1} \end{equation}
for whole values \( 0 ≤ k \lt d \).
The whole number \( [n_k] = \dfloor{n_k + 1/2} \) nearest to \( n_k \) is then the candidate value of \( n \). Calculate \( X \) for that value of \( n \) to see if it meets the condition that \( X \gt w \).
In our example we find
\begin{align*} P_0 \| = \dfrac{w − t}{2f} = \dfrac{2147483647 - 13835}{2×25920} = 41424.9577932 \\ n_k \| = \dfrac{P_0}{P_1} + k\dfrac{d}{P_1R_1} = \dfrac{41424.9577932}{99902} + \dfrac{765433}{99902×1}k \\ \| = 0.414655940754 + 7.66183860183 k \\ n \| = \dfloor{n_k + ½} = \dfloor{0.914655940754 + 7.66183860183 k} \\ R \| = n \\ P \| = \dmod{99902n}{765433} \\ X \| = (w − fP − t)\dfrac{P}{R} = (2147469812 − 25920 P)\dfrac{P}{R} \end{align*}
The first couple of relatively good values of \( n \) are then
\({k}\) | \({n_k}\) | \({n}\) | \({P}\) | \({Q}\) | \({R}\) | \({X/w}\) |
---|---|---|---|---|---|---|
0 | 0.41 | 0 | 0 | 0 | 0 | +0.0 |
1 | 8.08 | 8 | 33783 | 1144 | 8 | +2500.9 |
2 | 15.74 | 16 | 67566 | 2288 | 16 | +779.0 |
3 | 23.40 | 23 | 1447 | 49 | 23 | +61.8 |
4 | 31.06 | 31 | 35230 | 1193 | 31 | +653.2 |
5 | 38.72 | 39 | 69013 | 2337 | 39 | +295.5 |
6 | 46.39 | 46 | 2894 | 98 | 46 | +60.7 |
7 | 54.05 | 54 | 36677 | 1242 | 54 | +378.5 |
8 | 61.71 | 62 | 70460 | 2386 | 62 | +170.0 |
The first \( n \) is 0 and is no good. The first value about that is 8, as we saw before.
If we use equations \eqref{eq:detour1}ff then it is sufficient if \( X ≥ d \) to be able to handle all values \( |x| \lt w \), because then we can use equations \eqref{eq:detour1}ff to first make \( |x| \lt d \). If we do not use equations \eqref{eq:detour1}ff, then we must have \( X ≥ w \) to be able to handle all values \( |x| \lt w \).
There can be multiple combinations of \( P\), \( Q \), \( R \) that yield \( X ≥ w \) or \( X ≥ d \), and those are all 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 case from the previous example, \( X ≥ w \) for 1498 values of \( R \) between 8 and 20312, and \( X ≥ d \) for 82576 values of \( R \) between 8 and 765'426. We found solutions for \( X ≥ w \) so we do not need equations \eqref{eq:detour1}ff. Within the group with \( X ≥ w \) we search for the smallest values of \( PQR \). We find
\({R}\) | \({P}\) | \({Q}\) | \({PQR}\) | \({X}\) |
---|---|---|---|---|
23 | 1447 | 49 | 1.6 × 106 | 1.33 × 1011 |
46 | 2894 | 98 | 1.3 × 107 | 1.30 × 1011 |
544 | 945 | 32 | 1.6 × 107 | 3.69 × 109 |
69 | 4341 | 147 | 4.4 × 107 | 1.28 × 1011 |
92 | 5788 | 196 | 1.0 × 108 | 1.26 × 1011 |
We choose \( P = 1447 \), then \( R = 23 \) and \( Q = 49 \).
Now we calculate \( y \), \( e \) for \( x = 1710321 \). We find
\begin{align*} q \| = \dfloorratio{x}{P} = \dfloorratio{1710321}{1447} = 1181 \\ r \| = \dmod{x}{P}= \dmod{1710321}{1447} = 1414 \\ y \| = qQ + \dfloorratio{qR + fr + t}{d} \\ \| = 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{fx + t}{d} = \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.
Another example: \( d = 146097 \), \( f = 4800 \), \( t = 15793 \), \( w = 2^{31} − 1 = 2147483647 \). Then \( \dfrac{w}{f} = \dfrac{2^{31} − 1}{4800} ≈ 447392 \), so we seek a \( P \lt 146097 \lt 447392 \) and an \( R \) as small as possible.
The Extended Algorithm of Euclid (or a search) yields that \( −15188f + 499d = 3 \), and there is no sum of a multiple of \( f \) and a multiple of \( d \) that is closer to 0. It follows that
\begin{align*} \\ P_1 \| = \dmod{−15188}{(146097/3)} = \dmod{−15188}{48699} = 33511 \\ Q_1 \| = \dmod{−499}{(4800/3)} = \dmod{−499}{1600} = 1101 \\ R_1 \| = 3 \end{align*}
Let's check:
\[ fP_1 − dQ_1 = 4800×33511 − 146097×1101 = 3 = R_1 \]
so possibly good combinations are
\begin{align*} P \| = \dmod{nP_1}{(d/R_1)} = \dmod{33511n}{48699} \\ \{ ρ, R \} \| = \Div(nR_1, 146097) = \Div(3n, 146097) \\ Q \| = \dmod{nQ_1 + ρ}{(f/R_1)} = \dmod{1101n + ρ}{1600} \end{align*}
The best candidates for \( n \) are
\begin{align*} P_0 \| = \dfrac{w − t}{2f} = \dfrac{2147483647 − 15793}{2×4800} = 223694.568125 \\ n_k \| = \dfrac{P_0}{P_1} + k\dfrac{d}{P_1R_1} = \dfrac{223694.568125}{33511} + \dfrac{146097}{33511×3}k \\ \| = 6.67525791904 + 1.4532243144 k \end{align*}
For small \( R \) we find the following combinations:
\({R}\) | \({P}\) | \({Q}\) |
---|---|---|
3 | 33511 | 1101 |
6 | 67022 | 2202 |
9 | 100533 | 3303 |
12 | 134044 | 4404 |
There are 57132 combinations for which \( X ≥ w \). The combinations with the smallest \( PQR \) are:
\({P}\) | \({Q}\) | \({R}\) | \({PQR}\) | \({X/w}\) |
---|---|---|---|---|
487 | 16 | 48 | 3.74 × 105 | 10.1 |
974 | 32 | 96 | 2.99 × 106 | 10.1 |
761 | 25 | 375 | 7.13 × 106 | 41.3 |
1461 | 48 | 144 | 1.01 × 107 | 10.1 |
1248 | 41 | 423 | 2.16 × 107 | 37.7 |
6270 | 206 | 18 | 2.32 × 107 | 343.5 |
We choose \( P = 487 \), then \( Q = 16 \) and \( R = 48 \). We calculate \( y\), \( e \) for \( x = 731767 \). Then
\begin{align*} q \| = \dfloorratio{731767}{487} = 1502 \\ r \| = \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 \).
I've investigated for all \( w \) from 3 through 1024 what the greatest values of \( f \) and \( d \) are for which solutions can be found with \( X ≥ d \) or \( X ≥ w \), and what the greatest \( P \), \( Q \), \( R \), and \( X \) are among those solutions, and what the greatest number \( c \) of such solutions is, and the total count \( N \) of combinations of \( f \) and \( d \) for which there is at least one solution. I find
\begin{align} \max(f_w) \| ≈ \dfloorratio{w}{4} \\ \max(f_d) \| ≈ \dfloorratio{w}{3} \\ \max(d_w) \| ≈ w − 5 + ⌊w⌉_2 \\ \max(d_d) \| ≈ w − 1 \\ \max(c_w) \| ≈ \dfloorratio{w+8}{16} \\ \max(c_d) \| ≈ \dfloorratio{w−1}{2} \\ \max(P_w) \| ≈ \dfloorratio{w}{2} − 2 + ⌊w⌉_2 \\ \max(P_d) \| ≈ \dfloorratio{w}{2} − 1 \\ \max(Q) \| ≈ \dfloorratio{2\sqrt{w − 1} − 3}{2} \\ \max(R_w) \| ≈ \dfloorratio{\sqrt{w + 1} − 1}{2} \\ \max(R_d) \| ≈ \frac{\sqrt{w(w + 1100)}}{25} \\ \max(X) \| ≈ \dfloorratio{w^2}{8} \\ N_w \| ≈ \frac{1}{5}w^{5/3} \\ N_d \| ≈ \frac{1}{3}w^{5/3} \end{align}
where the variables with subscript \( w \) apply only to \( X \gt w \), those with subscript \( d \) apply only to \( X \gt d \), and those without a subscript apply to both. The formulas for \( \max(R_d) \), \( N_w \), and \( N_d \) are approximations; the other formulas are exact for \( 10 ≤ w ≤ 1024 \).
For example, for \( w = 1023 \) I find
\begin{align*} \max(f_w) \| ≈ \dfloorratio{1023}{4} = 255 \\ \max(f_d) \| ≈ \dfloorratio{1023}{3} = 341 \\ \max(d_w) \| ≈ 1023 − 5 + ⌊1023⌉_2 = 1019 \\ \max(d_d) \| ≈ 1023 − 1 = 1022 \\ \max(c_w) \| ≈ \dfloorratio{1023 + 8}{16} = 64 \\ \max(c_d) \| ≈ \dfloorratio{1023 − 1}{2} = 511 \\ \max(P_w) \| ≈ \dfloorratio{1023}{2} − 2 + ⌊1023⌉_2 = 510 \\ \max(P_d) \| ≈ \dfloorratio{1023}{2} − 1 = 510 \\ \max(Q) \| ≈ \dfloorratio{2×\sqrt{1023 − 1} − 3}{2} ≈ ⌊30.47⌋ = 30 \\ \max(R_w) \| ≈ \dfloorratio{\sqrt{1023 + 1} − 1}{2} ≈ ⌊15.50⌋ = 15 \\ \max(R_d) \| ≈ \frac{\sqrt{1023 × (1023 + 1100)}}{25} ≈ 58.95 \\ \max(X) \| ≈ \dfloorratio{1023^2}{8} = 130816 \\ N_w \| ≈ \frac{1}{5}1023^{5/3} ≈ 20772.52 \\ N_d \| ≈ \frac{1}{3}1023^{5/3} ≈ 34620.87 \end{align*}
These values are all correct, except that \( R_d = 59 \), \( N_w = 20014 \), and \( N_d = 33937 \).
If we extrapolate the above formules to \( w = 2^{31} − 1 \) (for values with a width of 32 bits), then we find, approximately
\begin{align*} \max(f_w) \| ≈ 5.4×10^8 \\ \max(f_d) \| ≈ 7.2×10^8 \\ \max(d) \| ≈ 2.1×10^9 \\ \max(c_w) \| ≈ 1.3×10^8 \\ \max(c_d) \| ≈ 1.1×10^9 \\ \max(P) \| ≈ 1.1×10^9 \\ \max(Q) \| ≈ 46340 \\ \max(R_w) \| ≈ 23170 \\ \max(R_d) \| ≈ 8.6×10^7 \\ \max(X) \| ≈ 5.8×10^{17} \\ N_w \| ≈ 7.1×10^{14} \\ N_d \| ≈ 1.2×10^{15} \end{align*}
so if we seek a solution for \( X ≥ w \) (so that we do not need equations \eqref{eq:detour1}ff), then we need try only up to 23170 different values of \( R \). If such a solution does not exist, then we seek a solution for \( X ≥ d \) (for which we do need to use equations \eqref{eq:detour1}ff) and then we must try up to 86 million values of \( R \), which is still much less than the up to 1100 million values of \( P \).
For a given \( w \) there are many combinations of \( d \) and \( f \) for which there are no solutions with \( X ≥ w \) or \( X ≥ d \). For example, for \( w = 499 \) there are only 6554 combinations of \( d \) and \( f \) with at least one solution with \( X ≥ w \), and 10560 combinations with at least one solution with \( X ≥ d \), but there are \( \frac{1}{2} (w − 2)×(w − 3) = 123256 \) combinations with \( 2 ≤ f \lt d \lt w \). The greater \( f \) is, the smaller is the chance that there is a solution for the combination of that \( f \) and an arbitrary \( d \gt f\).
However, when \( f \) and \( d \) are considerably less than \( w \), then there is a good chance of a solution. For example, for \( w = 2^{31} − 1 \) and for \( f \) and \( d \) near \( f ≈ 25920 \) and \( d ≈ 765433 \) there is no solution with \( X ≥ d \) for only roughly 1 out of every 9100 combinations of \( f \) and \( d \), and no solution with \( X ≥ w \) for only roughly 1 out of about 54 combinations.
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.
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
\begin{equation} ⌊b⌋ = 0 ⇔ 0 ≤ b \lt 1 \end{equation}
So \( b \) must be between 0 and 1 (0 is allowed, 1 is not).
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
\begin{equation} Q = \frac{1}{ψ} \label{eq:Q} \end{equation}
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}
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 \):
\begin{equation} σ(m + 1) − σ(m) = σ_*(m + ∆m + 1) − σ_*(m + ∆m) \end{equation}
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
\begin{equation} b = \dmod{b_* + p∆m}{1} \end{equation}
We go from running month number \( m \) and day number \( d \) within the month to running day number \( s \) via a formula like
\begin{equation} s = \dfloor{pm + v} + d = σ + d \label{eq:sv} \end{equation}
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:
\begin{equation} m = \dceilratio{s + u − p}{p} = \dceilratio{s + u}{p} − 1 \end{equation}
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*}
\begin{equation} \dmod{pm + v}{1} − v \lt u ≤ \dmod{pm + v + p}{1} − v + 1 \end{equation}
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
\begin{equation} 1 − v ≤ u ≤ 1 − v \end{equation}
Those inequalities have exactly one solution:
\begin{equation} u = 1 − v \end{equation}
so
\begin{equation} m = \dceilratio{s + 1 − v − p}{p} = \dceilratio{s + 1 − v}{p} − 1 \label{eq:svtom} \end{equation}
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 fractional 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
\begin{equation} s + 1 − v = pμ − δ = p\dceilratio{s + 1 − v}{p} − \ddom{s + 1 − v}{p} \end{equation}
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
\begin{equation}\{−μ,δ\} = \Div(−(s + 1 − v), p)\end{equation}
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 |
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 \),
\begin{equation} \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} \end{equation}
and likewise
\begin{equation} \ddom{x}{f/g} = \dfrac{\ddom{gx}{f}}{g} \label{eq:gdomp} \end{equation}
Then we go from month \( m \) and day \( d \) to running day number \( s \) through
\begin{equation} t ≡ vg \end{equation}
\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
\begin{equation} L(m) = q + C\dparen{\dmod{hm + t}{g} ≥ g − h}\end{equation}
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} \eqavide{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} \eqavide{eq:gdomp} \notag \\ \| = \dfloorratio{f − g − \ddom{gs + g − t}{f} − 1}{g} + 1 \eqavide{eq:ceil2floor} (t,g,s,f ∥ 1) \notag \\ \| = \dfloorratio{f − g − (f − 1 − \dmod{gs + g − t − 1}{f}) − 1}{g} + 1 \eqavide{eq:ddom2dmod} \notag \\ \| = \dfloorratio{\dmod{gs + g − t − 1}{f}}{g} \eqavide{eq:ddom2dmod} \end{align}
Summarizing, from running month number \( m \) and day number \( d \) in the month to running day number \( s \):
\begin{equation} s = \dfloorratio{fm + t}{g} + d \end{equation}
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 |
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
\begin{equation} p = q + rψ \end{equation}
days. The formula to calculate the running day number \( σ \) of the first day of month \( m \) is then
\begin{equation} σ = qm + r\dfloor{ψm + b} \label{eq:sm2} \end{equation}
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
\begin{equation} 0 \le σ_* − σ \le r − 1 \end{equation}
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
\begin{equation} m_↑ = m_*(s + \max(∆σ)) = \dceilratio{s + \max(∆σ) + 1 − v}{p} − 1 \end{equation}
is greater than or equal to the correct month number. And
\begin{equation} m_↓ = m_*(s + \min(∆σ)) = \dceilratio{s + \min(∆σ) + 1 − v}{p} − 1 \end{equation}
is less than or equal to the correct month number.
With \( m_↑ \) we find
\begin{equation} d_↑ = s − σ(m_↑) \end{equation}
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
\begin{equation} ξ = \dfloorratio{d_↑}{Ξ} \end{equation}
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
\begin{equation} ρ ≡ \max(∆σ) − \min(∆σ) + \max(L) − 2p ≤ 0 \label{eq:singlepass} \end{equation}
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}} + \min(∆σ(m + 1) − ∆σ(m)) \notag \\ \| = −p + (\dmod{p}{1} − 1) + \min(∆σ(m + 1) − ∆σ(m)) \eqavide{eq:domp} \notag \\ \| = −p + \dmod{p}{1} − 1 + \min(L_*(m) − L(m)) \notag \\ \| = −\dfloor{p} − 1 + \min(L_*(m) − L(m)) \eqavide{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
\begin{equation} −\max(L) ≤ d_↑ ≤ \max(L) − 1 \end{equation}
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
\begin{equation} Ξ ≥ \max(L) \end{equation}
So if we use
\begin{equation} Ξ = \max(L) \end{equation}
(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
\begin{equation} r ≤ \dfrac{1}{2} \dfrac{q + 1}{1 − ψ} ≥ q + 1 \end{equation}
If \( ρ \gt 0 \) then the recipe doesn't always work so then you shouldn't use it. Then see Section 12.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 = \dfrac{f}{g} \), \( ψ = \dfrac{h}{g}\) and \( b = \dfrac{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 |
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 |
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 \eqavide{eq:ceildiffrange} \end{align}
so the number of months that you have to try at most is
\begin{equation} N = \dceilratio{\max(∆σ) − \min(∆σ)}{p} + 2 \end{equation}
For a calendar with two month lengths this means
\begin{equation} N = \dceilratio{r − 1}{p} + 2 \end{equation}
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}
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
\begin{equation} \dfloorratio{s − a}{f} + 1 = \dfloorratio{s + f − a}{f} \end{equation}
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
\begin{equation} \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} \end{equation}
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
\begin{equation} a_i = \sum_{j=0}^{i-1} L_j \end{equation}
Then
\begin{equation} m = \sum_{i=0}^{g−1} \dfloorratio{s + f − \sum_{j=0}^{i−1} L_j}{f} \label{eq:willekeurigynaarx} \end{equation}
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:
\begin{equation} σ = \sum_{i=0}^{g−1} L_i \dfloorratio{m + g − 1 − i}{g} \end{equation}
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 \))
\begin{equation} s = σ + d = \sum_{i=0}^{g−1} m_i \dfloorratio{m + g − 1 − i}{g} + d \label{willekeurigxnaary} \end{equation}
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 12.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
\begin{equation} \frac{s − 1}{m} \lt p \lt \frac{s + 1}{m} \label{eq:beperkp} \end{equation}
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 12.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.
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 beginning of 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*}
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 \).
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 \).
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\} \).
To translate running day number \( s \) into \( \{x\} \) we can use the following formula:
\begin{equation} x_i = ⌊s + a_i⌉_{p_i} = (s + a_i) \bmod p_i \label{eq:cycli} \end{equation}
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 |
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.,
\begin{equation} s ≡ x_i − a_i \pmod{p_i} \end{equation}
We define
\begin{equation} c_i = x_i − a_i \end{equation}
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
\begin{equation} c_1 ≡ c_2 \pmod{g} \end{equation}
where
\begin{equation} g = \gcd(p_1, p_2) \end{equation}
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
\begin{equation} g = n_1 p_1 + n_2 p_2 \end{equation}
and then the solutions are
\begin{equation} 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} \end{equation}
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.
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 \),
Assign
\begin{align*} C_1 \| = x_1 − a_1 \\ P_1 \| = p_1 \end{align*}
For \( i \) from 2 through \( n \):
Determine \( g_i = \gcd(P_{i−1}, p_i) \), the greatest common divisor of \( P_{i−1} \) and \( p_i \).
Find \( n_i, m_i \) such that
\[ g_i = n_i P_i + m_i p_i \]
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*}
The solution is
\begin{equation} s ≡ C_n \pmod{P_n} \label{eq:cycle} \end{equation}
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} \).
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:
We investigate these cases one by one, for \( s ≡ C_n \pmod{P_n} \).
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
\begin{equation} k = \dfloorratio{s_0 − C_n}{P_n} \end{equation}
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 |
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
\begin{equation} k = \dceilratio{s_0 − C_n}{P_n} \end{equation}
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 |
The last \( s \) before \( s_0 \) is one \( P_n \) before the first \( s \) at or after \( s_0 \), so
\begin{equation} s = s_0 − P_n − \dmod{s_0 − C_n}{P_n} \end{equation}
The first \( s \) after \( s_0 \) is one \( P_n \) after the last \( s \) at or before \( s_0 \), so
\begin{align} s \| = s_0 + P_n + ⌈s_0 − C_n⌋_{P_n} \\ \| = s_0 + P_n + ⌊C_n − s_0⌉_{P_n} \end{align}
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.
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.
Calendar type 2 is equal to type 1, except that shifting of the pattern of month lengths is allowed.
Calendar type 3 is equal to type 2, but now the difference between the month lengths can be more than one.
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.
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:
j ───────────┐ ┌─ a₁ ──────────┐ (1) │ m ─(−1)─ m₀ ─┘ └─ m₁ ─┐ │ d ─(−1)─ d₀ ─────────(2)─ d₁ ─(3)─ s ─(+J₀)─ J
The calendar date with year, month, day \( j, m, d \) is on the left, and the CJDN \( J \) is on the right. The symbols between parentheses, like (1) and (+J₀), indicate a transformation. The other symbols, like a₁ and d₁, indicate intermediate results. The lines show which intermediate results from one transformation are used in the next transformation. The intermediate results with names with an a in them (like a₁) are measured in years, those with m are measured in months, and those with d, s, or J are measured in days. Names with a c in them (like c₁, not in the above diagram) are measured in centuries of 100 years each. The calculations with larger units are higher up in the diagram than those with smaller units.
The transformations for which there is a plus or minus sign between the parentheses indicate the corresponding increment or decrement when going from left (calendar date) to right (CJDN). So (+J₀) means that you add \( J_0 \). When going from right (CJDN) to left (calendar date) then you do the opposite, so then (+J₀) means that you should subtract \( J_0 \).
For a transformation without a plus or minus sign between the parentheses the number identifies the transformation. More details are given later. Most such transformations (such as transformations 2 and 3 here) transform one number into two, or two numbers into one, and correspond to one of the calendar levels described in the previous chapter. And sometimes there is a transformation (such as transforomation 1 here) that adjusts two numbers, produces two numbers from two numbers. If the number is shown between parentheses () then it represents a calendar level of types 1 or 2. If it is instead shown between square brackets [] then it represents a calendar level of types 3 or 4.
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 \( j \) 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 \( j \). 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 \) 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.
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 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. We work around the problem by regarding February as the last calculation 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. We combine a calendar level between months and days with a calendar level between years and days and then we use that second calendar level to set the length of the year such that the last calculation month (February) can be shorter than 30 days.
The calculations are schematically as shown in the following diagram.
j ───────────┐ ┌─ a₁ ──────────┐ (1) │ m ─(−1)─ m₀ ─┘ └─ m₁ ─┐ │ d ─(−1)─ d₀ ─────────(2)─ d₁ ─(3)─ s ─(+J₀)─ J
The summary of the calculation levels (as in the previous chapter) is
(n) | \({f}\) | \({g}\) | \({q}\) | \({h}\) | \({t}\) | \({p}\) |
---|---|---|---|---|---|---|
1 | 12 | 1 | 12 | 0 | 2 | 12 |
2 | 153 | 5 | 30 | 3 | 2 | 30.6 |
3 | 1461 | 4 | 365 | 1 | 0 | 365.25 |
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}
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 \| = j + α_1 \end{align}
\({j}\) | \({m}\) | \({a_0}\) | \({a_1}\) | \({m_1}\) |
---|---|---|---|---|
0 | 1 | −1 | −1 | 10 |
0 | 2 | −1 | −1 | 11 |
0 | 3 | 0 | 0 | 0 |
0 | 10 | 0 | 0 | 7 |
0 | 11 | 0 | 0 | 8 |
0 | 12 | 0 | 0 | 9 |
1 | 1 | −1 | 0 | 10 |
1 | 2 | −1 | 0 | 11 |
1 | 3 | 0 | 1 | 0 |
Transformation 2 calculates the day number \( d_1 \) since the beginning of the calculation year from the calculation month \( m_1 \) and the day number \( d_0 \) since the beginning of the calculation month:
\begin{equation} d_1 = \dfloorratio{153 m_1 + 2}{5} + d_0 = 30 m_1 + \dfloorratio{3 m_1 + 2}{5} + d_0 \end{equation}
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.
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 \) since the beginning of the calculation year:
\begin{equation} s = \dfloorratio{1461 a_1}{4} + d_1 \end{equation}
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.
And then we add to \( s \) the CJDN of the beginning of calculation year 0 (March 1 of Year 0), which is 1721118:
\begin{equation} J = s + J_0 = s + 1721118 \end{equation}
We can combine the preceding steps into
\begin{align} \{ a_2, m_1 \} \| = \Div(m ― 3, 12) \\ J \| = \dfloorratio{1461\dparen{j + a_2}}{4} + \dfloorratio{153m_1 + 2}{5} + d + 1721117 \end{align}
For example, what CJDN corresponds to Julian date 6 July 2003? Then \( j = 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_0 − 2 = 6 − 2 = 4 \\ \{ a_0, m_1 \} \| = \Div(α_1, 12) = \Div(4, 12) = \{ 0, 4 \} \\ a_1 \| = j + a_0 = 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} + 122 = 731595 + 127 = 731722 \\ J \| = 731722 + 1721118 = 2452840 \end{align*}
Or, with the condensed formulas:
\begin{align*} \{ a_2, m_1 \} \| = \Div(m ― 3, 12) = \Div(7 ― 3, 12) = \{ 0, 4 \} \\ J \| = \dfloorratio{1461\dparen{j + a_2}}{4} + \dfloorratio{153m_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:
\({j}\) | \({m}\) | \({d}\) | \({m_0}\) | \({d_0}\) | \({α_1}\) | \({a_0}\) | \({m_1}\) | \({a_1}\) | \({d_1}\) | \({s}\) | \({J}\) |
---|---|---|---|---|---|---|---|---|---|---|---|
−1 | 12 | 31 | 11 | 30 | 9 | 0 | 9 | −1 | 305 | −61 | 1721057 |
0 | 1 | 1 | 0 | 0 | −2 | −1 | 10 | −1 | 306 | −60 | 1721058 |
0 | 2 | 28 | 1 | 27 | −1 | −1 | 11 | −1 | 364 | −2 | 1721116 |
0 | 2 | 29 | 1 | 28 | −1 | −1 | 11 | −1 | 365 | −1 | 1721117 |
0 | 3 | 1 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1721118 |
1999 | 12 | 31 | 11 | 30 | 9 | 0 | 9 | 1999 | 305 | 730439 | 2451557 |
2000 | 1 | 1 | 0 | 0 | −2 | −1 | 10 | 1999 | 306 | 730440 | 2451558 |
2000 | 2 | 28 | 1 | 27 | −1 | −1 | 11 | 1999 | 364 | 730498 | 2451616 |
2000 | 2 | 29 | 1 | 28 | −1 | −1 | 11 | 1999 | 365 | 730499 | 2451617 |
2000 | 3 | 1 | 2 | 0 | 0 | 0 | 0 | 2000 | 0 | 730500 | 2451618 |
2003 | 7 | 6 | 6 | 5 | 4 | 0 | 4 | 2003 | 127 | 731722 | 2452840 |
We run through the opposite procedure from the one described above, with the same calendar levels as above.
j ───────────┐ ┌─ a₁ ──────────┐ (1) │ m ─(−1)─ m₀ ─┘ └─ m₁ ─┐ │ d ─(−1)─ d₀ ─────────(2)─ d₁ ─(3)─ s ─(+J₀)─ J
The summary of the calculation levels (as in the previous chapter) is
(n) | \({f}\) | \({g}\) | \({q}\) | \({h}\) | \({t}\) | \({p}\) |
---|---|---|---|---|---|---|
1 | 12 | 1 | 12 | 0 | 2 | 12 |
2 | 153 | 5 | 30 | 3 | 2 | 30.6 |
3 | 1461 | 4 | 365 | 1 | 0 | 365.25 |
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.
\begin{equation} s = J − J_0 = J − 1721118 \end{equation}
Transformation 3 calculates from the running day number \( s \) the calculation year \( a_1 \) and the day number \( d_1 \) since the beginning of that calculation year.
\begin{align} \{ a_1, ω_1 \} \| = \Div(4s + 3, 1461) \\ d_1 \| = \dfloorratio{ω_1}{4} \end{align}
Transformation 2 calculates calculation month \( m_1 \) and day number \( d_0 \) since the beginning of the calculation month from day number \( d_1 \) since the beginning of the calculation year.
\begin{align} \{ m_1, ω_2 \} \| = \Div(5d_1 + 2, 153) \\ d_0 \| = \dfloorratio{ω_2}{5} \end{align}
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) \\ j \| = a_1 + α_1 \end{align}
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(4J − 6884469, 1461) \\ \{ m_1, ω_2 \} \| = \Div\dparen{5\dfloorratio{ω_1}{4} + 2, 153} \\ \{ α_1, m_0 \} \| = \Div(m_1 + 2, 12) \\ j \| = 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(4s + 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(5d_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 \} \\ j \| = 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(4J − 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\} \\ j \| = 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}\) | \({j}\) | \({m}\) | \({d}\) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
−1 | −1721119 | −4713 | 1220 | 305 | 9 | 150 | 30 | 0 | 2 | 0 | 3 | 1 |
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 |
We can also use a stepped combination of calendars; then we need a calendar level between a running month number and a running day number, taking into account leap years. In that case there is no longer a higher calendar level that will shorten a too-long last month, so the formulas must be correct also for very large running month numbers.
The calculations are schematically as follows:
j ────────────┐ 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 | 12 | 1 | 12 | 0 | 0 | 12 | |||
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 |
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}
Transformation 1 calculates the running month number \( m_1 \) from the year \( j \) and the month number \( m_0 \) since the beginning of the year. The formula is very simple:
\begin{equation} m_1 = 12j + m_0 \end{equation}
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.
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}\) | \({\dfloorratio{7m_1}{12}}\) | ∆ |
---|---|---|
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 | |
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{fa}{g} = \dmod{−7}{12} = 5 \), so we find \( \dfloor{(7m_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
\begin{equation} s = 30m_1 + \dfloorratio{7m_1 + 5}{12} − 2\dfloorratio{m_1 + 10}{12} + \dfloorratio{m_1 + 46}{48} + d_0 \end{equation}
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\} \).
And then we add the CJDN of the beginning of the year 0 (January 1st, Year 0), and that is 1721058.
\begin{equation} J = s + J_0 = s + 1721058 \end{equation}
This condenses to
\begin{align} m_1 \| = 12j + m − 1 \\ J \| = 30m_1 + \dfloorratio{7m_1 + 5}{12} − 2\dfloorratio{m_1 + 10}{12} + \dfloorratio{m_1 + 46}{48} + d + 1721057 \end{align}
For example, what CJDN corresponds to Julian date July 6th, 2003? Then \( j = 2003 \), \( m = 7 \), \( d = 6 \), so
\begin{align*} m_0 \| = m − 1 = 6 \\ d_0 \| = d − 1 = 5 \\ m_1 \| = 12j + m_0 = 12×2003 + 6 = 24042 \\ s \| = 30m_1 + \dfloorratio{7m_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 \| = 12j + m − 1 = 12×2003 + 7 − 1 = 24042 \\ J \| = 30m_1 + \dfloorratio{7m_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:
\({j}\) | \({m}\) | \({d}\) | \({m_0}\) | \({d_0}\) | \({m_1}\) | \({\dfloorratio{7m_1+5}{12}}\) | \({\dfloorratio{m_1+10}{12}}\) | \({\dfloorratio{m_1+46}{48}}\) | \({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 calculations are schematically as follows:
j ────────────┐ 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 | 12 | 1 | 12 | 0 | 0 | 12 | |||
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:
\begin{equation} s = J − J_0 = J − 1721058 \end{equation}
Transformation 2 produces the running month number \( m_1 \) and the day number \( d_0 \) since the beginning of 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{48s + 48×2 − (4×1×5 + 4×−2×10 + 1×1×46) − 1}{1461} \notag \\ \| = \dfloorratio{48s + 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 − 30m_1 − \dfloorratio{7m_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 \( j \) and month number \( m_0 \) since the beginning of the year. This is a calendar level of type 1.
\begin{equation} \{ j, m_0 \} = \Div(m_1, 12) \end{equation}
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 \\ \{ j, 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}\) | \({j}\) | \({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 |
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.
To approximate Gregorian years with a straight line with a single pattern, the leap values have to return after every \( ⌊Q⌋ \) or \( ⌈Q⌉ \) periods (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₁ ──────────┐ j ───────────┐ ┌─ 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 |
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:
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}
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 (13.1.1).
\begin{align} \{ α_1, m_1 \} \| = \Div(m_0 − 2, 12) \\ a_1 \| = j + α_1 \end{align}
Transformation 2 calculates the calculation century number \( c_1 \) and year number \( a_1 \) since the beginning of the calculation century from the calculation year number \( a_1 \).
\begin{equation} \{ c_1, a_2 \} = \Div(a_1, 100) \end{equation}
Transformation 3 calculates the day number \( d_1 \) since the beginning of the calculation year from the calculation month \( m_1 \) and the day number \( d_0 \) since the beginning of the calculation month:
\begin{equation} d_1 = \dfloorratio{153 m_1 + 2}{5} + d_0 = 30 m_1 + \dfloorratio{3 m_1 + 2}{5} + d_0 \end{equation}
Transformation 4 calculates the day number \( d_2 \) since the beginning of the calculation century from the year number \( a_2 \) since the beginning of the calculation century and the day number \( d_1 \) since the beginning of the calculation year.
\begin{equation} d_2 = \dfloorratio{36525 a_2}{100} + d_1 \end{equation}
Transformation 5 calculates the running day number \( s \) from the calculation century number \( c_1 \) and the day number \( d_2 \) since the beginning of the calculation century.
\begin{equation} s = \dfloorratio{146097 c_1}{4} + d_2 \end{equation}
And then we add to \( s \) the CJDN of the beginning of calculation year 0 (March 1 of Year 0), which is 1721120:
\begin{equation} J = s + J_0 = s + 1721120 \end{equation}
Combined and condensed, this yields:
\begin{align} \{ α_1, m_1 \} \| = \Div(m − 3, 12) \\ \{ c_1, a_2 \} \| = \Div(j + α_1, 100) \\ J \| = \dfloorratio{146097 c_1}{4} + \dfloorratio{36525 a_2}{100} + \dfloorratio{153 m_1 + 2}{5} + d + 1721119 \end{align}
For example, which Julian Day number corresponds to Gregorian date July 6th, 2003? Then \( j = 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 \| = j + α_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(j + α_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:
\({j}\) | \({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 |
Now we go in the opposite direction again, with the same calendar levels as before.
┌── c₁ ──────────┐ j ───────────┐ ┌─ 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 |
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 |
First we subtract the CJDN that goes with running day number 0 from the CJDN to get the running day number:
\begin{equation} s = J − J_0 = J − 1721120 \end{equation}
Transformation 5 produces from the running day number \( s \) the calculation century \( c_1 \) and the day number \( d_2 \) since the beginning of the calculation century:
\begin{align} \{ c_1, ω_1 \} \| = \Div(4s + 3, 146097) \\ d_2 \| = \dfloorratio{ω_1}{4} \end{align}
Transformation 4 produces from the day number \( d_2 \) since the beginning of the calculation century the year number \( a_2 \) since the beginning of the calculation century and the day number \( d_1 \) since the beginning of the calculation year.
\begin{align} \{ a_2, ω_2 \} \| = \Div(100d_2 + 99, 36525) \\ d_1 \| = \dfloorratio{ω_2}{100} \end{align}
Transformation 3 separates the day number \( d_1 \) since the beginning of the calculation year into the calculation month number \( m_1 \) since the beginning of the calculation year and the day number \( d_0 \) since the beginning of the calculation month.
\begin{align} \{ m_1, ω_3 \} \| = \Div(5d_1 + 2, 153) \\ d_0 \| = \dfloorratio{ω_3}{5} \end{align}
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 \).
\begin{equation} a_1 = 100c_1 + a_2 \end{equation}
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) \\ j \| = a_1 + α_1 \end{align}
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) \\ j \| = 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 \} \\ j \| = 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\} \\ j \| = 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}\) | \({j}\) | \({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 |
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
j ───────────┐ ┌─ 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 | 12 | 1 | 12 | 0 | 2 | 12 | |||
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:
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}
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 (13.1.1).
\begin{align} \{ α_1, m_1 \} \| = \Div(m_0 − 2, 12) \\ a_1 \| = j + α_1 \end{align}
Transformation 2 calculates the day number \( d_1 \) since the beginning of the calculation year from the calculation month \( m_1 \) and the day number \( d_0 \) since the beginning of the calculation month:
\begin{equation} d_1 = \dfloorratio{153 m_1 + 2}{5} + d_0 = 30 m_1 + \dfloorratio{3 m_1 + 2}{5} + d_0 \end{equation}
Transformation 3 calculates the running day number \( s \) from the year number \( a_1 \) and the day number \( d_1 \) since the beginning of the calculation year.
\begin{equation} s = 365 a_1 + \dfloorratio{a_1}{4} − \dfloorratio{a_1}{100} + \dfloorratio{a_1}{400} + d_1 \end{equation}
And then we add to \( s \) the CJDN of the beginning of calculation year 0 (March 1 of Year 0), which is 1721120:
\begin{equation} J = s + J_0 = s + 1721120 \end{equation}
This condenses to
\begin{align} \{ α_1, m_1 \} \| = \Div(m − 3, 12) \\ a_1 \| = j + α_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 \( j = 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 \| = j + α_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 \| = j + α_1 = 2003 + 0 = 2003 \\ J \| = 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:
\({j}\) | \({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 |
Now we go in the opposite direction, again.
j ───────────┐ ┌─ 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 | 12 | 1 | 12 | 0 | 2 | 12 | |||
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 |
First we subtract the CJDN that goes with running day number 0 from the CJDN to get the running day number:
\begin{equation} s = J − J_0 = J − 1721120 \end{equation}
Transformation 3 produces from the running day number \( s \) the calculation year number \( a_2 \) and the day number \( d_1 \) since the beginning of 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}
Transformation 2 separates the day number \( d_1 \) since the beginning of the calculation year into the calculation month number \( m_1 \) since the beginning of the calculation year and the day number \( d_0 \) since the beginning of the calculation month.
\begin{align} \{ m_1, ω_1 \} \| = \Div(5d_1 + 2, 153) \\ d_0 \| = \dfloorratio{ω_1}{5} \end{align}
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) \\ j \| = a_1 + α_2 \end{align}
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) \\ j \| = 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 \} \\ j \| = 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\dparen{5×\dparen{731707 − 365×2003 − \dfloorratio{2003}{4} + \dfloorratio{2003}{100} − \dfloorratio{2003}{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 \} \\ j \| = 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}
The numerator of \( α_1 \) can get very large in this algorithm: In the example it was equal to 292683599 for a date in the year 2003. If you use this algorithm in a computer program that uses values of 32 bits large, then \( α_1 \) will get too large for dates more than 14,698 years from Julian Day number 0, i.e., from the year 9986. Section 12.2 explains how to find a solution for this. Such a solution is to replace formula
\[ α_1 = \dfloorratio{400s + 799}{146097} \]
with
\begin{align} \{ ω_2, δ_2 \} \| = \Div(s, 1461) \\ α_1 \| = 4ω_2 + \dfloorratio{12ω_2 + 400δ_2 + 799}{146097} \end{align}
For example, when \( s = 9000000 \), then
\[ α_1 = \dfloorratio{400×9000000 + 799}{146097} = \dfloorratio{3600000799}{146097} = 24641 \]
The greatest intermediate result is 3'600'000'799, which exceeds the greatest value (2'147'483'648) that fits a 32-bit value. With the alternative, we find
\begin{align*} \{ω_2, δ_2\} \| = \Div(9000000, 1461) = \{6160, 240\} \\ α_1 \| = 4×6160 + \dfloorratio{12×6160 + 400×240 + 799}{146097} \\ \| = 24640 + \dfloorratio{170719}{146097} = 24640 + 1 = 24641 \end{align*}
Now the greatest intermediate result was 9'000'000, which comfortably fits a 32-bit value.
The calculations are schematically as follows:
j ────────────┐ 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 | 12 | 1 | 12 | 0 | 0 | 12 | |||
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*} 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} \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 \( \{j,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 \| = 12j + m_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} + d_0 \\ J \| = s + 1721060 \end{align}
This condenses to
\begin{align} m_1 \| = 12j + m − 1 \\ J \| = 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} + d + 1721059 \end{align}
For example, what CJDN corresponds to Julian date July 6th, 2003? Then \( j = 2003 \), \( m = 7 \), \( d = 6 \), so
\begin{align*} m_0 \| = m − 1 = 6 \\ d_0 \| = d − 1 = 5 \\ m_1 \| = 12j + m_0 = 12×2003 + 6 = 24042 \\ 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} + 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 \| = 12j + m − 1 = 12×2003 + 7 − 1 = 24042 \\ J \| = 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} + 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:
\({j}\) | \({m}\) | \({d}\) | \({m_0}\) | \({d_0}\) | \({m_1}\) | \({\dfloorratio{7m_1+5}{12}}\) | \({\dfloorratio{m_1+10}{12}}\) | \({\dfloorratio{m_1+46}{48}}\) | \({\dfloorratio{m_1+1198}{1200}}\) | \({\dfloorratio{m_1+4798}{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 calculations are schematically as follows:
j ────────────┐ 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 | 12 | 1 | 12 | 0 | 0 | 12 | |||
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:
\begin{equation} s = J − J_0 = J − 1721060 \end{equation}
Transformation 2 produces the running month number \( m_1 \) and the day number \( d_0 \) since the beginning of 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 \( j \) and month number \( m_0 \) since the beginning of the year. This is a calendar level of type 1.
\begin{equation} \{ j, m_0 \} = \Div(m_1, 12) \end{equation}
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 \\ \{j, 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}\) | \({j}\) | \({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 |
In the calculation of \( μ_1 \), the numerator can get very large. In a computer program that uses 32-bit values, the calculation of \( μ_1 \) will yield wrong results when \( |s| \) exceeds about 447000 (days), which corresponds to only 1224 years. Section 12.2 explains how to find a solution for this. Such a solution is to replace the formula for \( μ_1 \) with
\begin{align} \{ω_1, δ_2\} \| = \Div(s, 487) \\ μ_1 \| = 16ω_1 + \dfloorratio{48ω_1 + 4800δ_2 + 15793}{146097} \end{align}
For example, if \( s = 730000 \), then
\[ μ_1 = \dfloorratio{4800×730000 + 15793}{146097} = \dfloorratio{3504015793}{146097} = 23984 \]
so then the greatest intermediate result is equal to 3'504'015'793, which is much greater than the greatest value (2'147'483'648) that fits in memory of 32 bits wide. With the alternative method, we find
\begin{align*} \{ω_1, δ_2\} \| = \Div(730000, 487) = \{1498, 474\} \\ μ_1 \| = 1498×16 + \dfloorratio{1498×48 + 4800×474 + 15793}{146097} \\ \| = 23968 + \dfloorratio{2362897}{146097} = 23968 + 16 = 23984 \end{align*}
which is the same result as before, but now with the greatest intermediate result equal to 2'362'897, which is comfortably small enough to fit in 32 bits.
For the Gregorian calendar the formulas (for days and years) from the sections with "(2)" and "(3)" in the title aren't easier than the formulas from the section with "(1)" in the title, so we recommend the formulas from the sections with "(1)" in the title for general use for this calendar. In general, it is not always possible to find such formulas, so then it is nice to also have more complicated but also more powerful formulas available.
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.
With these rules, the Milanković calendar has a period of 365×900 + 900/4 − (900/100)×(7/9) = 328'718 days. The conversion of a date to CJDN is nearly the same for the Milanković calendar as for the Gregorian calendar (see Section 13.2.1). The calculations are schematically as follows:
┌── c₁ ──────────┐ j ───────────┐ ┌─ 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 |
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 Gregorian calendar to the CJDN are now:
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}
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 (13.1.1).
\begin{align} \{ α_1, m_1 \} \| = \Div(m_0 − 2, 12) \\ a_1 \| = j + α_1 \end{align}
Transformation 2 calculates the calculation century number \( c_1 \) and year number \( a_1 \) since the beginning of the calculation century from the calculation year number \( a_1 \).
\begin{equation} \{ c_1, a_2 \} = \Div(a_1, 100) \end{equation}
Transformation 3 calculates the day number \( d_1 \) since the beginning of the calculation year from the calculation month \( m_1 \) and the day number \( d_0 \) since the beginning of the calculation month:
\begin{equation} d_1 = \dfloorratio{153 m_1 + 2}{5} + d_0 = 30 m_1 + \dfloorratio{3 m_1 + 2}{5} + d_0 \end{equation}
Transformation 4 calculates the day number \( d_2 \) since the beginning of the calculation century from the year number \( a_2 \) since the beginning of the calculation century and the day number \( d_1 \) since the beginning of the calculation year.
\begin{equation} d_2 = \dfloorratio{36525 a_2}{100} + d_1 \end{equation}
Transformation 5 calculates the running day number \( s \) from the calculation century number \( c_1 \) and the day number \( d_2 \) since the beginning of the calculation century.
\begin{equation} s = \dfloorratio{328718 c_1 + 6}{9} + d_2 \end{equation}
And then we add to \( s \) the CJDN of the beginning of calculation year 0 (March 1 of Year 0), which is 1721119:
\begin{equation} J = s + J_0 = s + 1721119 \end{equation}
Combined and condensed, this yields:
\begin{align} \{ α_1, m_1 \} \| = \Div(m − 3, 12) \\ \{ c_1, a_2 \} \| = \Div(j + α_1, 100) \\ J \| = \dfloorratio{328718 c_1 + 6}{9} + \dfloorratio{36525 a_2}{100} + \dfloorratio{153 m_1 + 2}{5} + d + 1721119 \end{align}
For example, which CJDN corresponds to Milanković date July 6th, 2003? Then \( j = 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 \| = j + α_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 + 1721119 = 2452826 \end{align*}
Some more examples:
\({j}\) | \({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 | −60 | 1721059 |
0 | 1 | 1 | 0 | 0 | −1 | 10 | −1 | −1 | 99 | 306 | 36465 | −59 | 1721060 |
0 | 2 | 28 | 1 | 27 | −1 | 11 | −1 | −1 | 99 | 364 | 36523 | −1 | 1721118 |
0 | 2 | 29 | 1 | 28 | −1 | 11 | −1 | −1 | 99 | 365 | 36524 | 0 | 1721119 |
0 | 3 | 1 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1721119 |
1900 | 2 | 28 | 1 | 27 | −1 | 11 | 1899 | 18 | 99 | 364 | 36523 | 693959 | 2415078 |
1900 | 3 | 1 | 2 | 0 | 0 | 0 | 1900 | 19 | 0 | 0 | 0 | 693960 | 2415079 |
1999 | 12 | 31 | 11 | 30 | 0 | 9 | 1999 | 19 | 99 | 305 | 36464 | 730424 | 2451543 |
2000 | 1 | 1 | 0 | 0 | −1 | 10 | 1999 | 19 | 99 | 306 | 36465 | 730425 | 2451544 |
2000 | 2 | 28 | 1 | 27 | −1 | 11 | 1999 | 19 | 99 | 364 | 36523 | 730483 | 2451602 |
2000 | 2 | 29 | 1 | 28 | −1 | 11 | 1999 | 19 | 99 | 365 | 36524 | 730484 | 2451603 |
2000 | 3 | 1 | 2 | 0 | 0 | 0 | 2000 | 20 | 0 | 0 | 0 | 730485 | 2451604 |
2003 | 7 | 6 | 6 | 5 | 0 | 4 | 2003 | 20 | 3 | 127 | 1222 | 731707 | 2452826 |
Also in the opposite direction, we do the same as for the Gregorian calendar (see Section 13.2.2), except that we use different formulas to calculate \( x_3 \) and \( k_3 \). The calculations are schematically as in this diagram:
┌── c₁ ──────────┐ j ───────────┐ ┌─ 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 |
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 |
First we subtract the CJDN that goes with running day number 0 from the CJDN to get the running day number:
\begin{equation} s = J − J_0 = J − 1721119 \end{equation}
Transformation 5 produces from the running day number \( s \) the calculation century \( c_1 \) and the day number \( d_2 \) since the beginning of the calculation century:
\begin{align} \{ c_1, ω_1 \} \| = \Div(9s + 2, 328718) \\ d_2 \| = \dfloorratio{ω_1}{9} \end{align}
Transformation 4 produces from the day number \( d_2 \) since the beginning of the calculation century the year number \( a_2 \) since the beginning of the calculation century and the day number \( d_1 \) since the beginning of the calculation year.
\begin{align} \{ a_2, ω_2 \} \| = \Div(100d_2 + 99, 36525) \\ d_1 \| = \dfloorratio{ω_2}{100} \end{align}
Transformation 3 separates the day number \( d_1 \) since the beginning of the calculation year into the calculation month number \( m_1 \) since the beginning of the calculation year and the day number \( d_0 \) since the beginning of the calculation month.
\begin{align} \{ m_1, ω_3 \} \| = \Div(5d_1 + 2, 153) \\ d_0 \| = \dfloorratio{ω_3}{5} \end{align}
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 \).
\begin{equation} a_1 = 100c_1 + a_2 \end{equation}
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) \\ j \| = a_1 + α_1 \end{align}
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 − 15490069, 328718) \\ \{ 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) \\ j \| = 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 2452826? Then \( J = 2452826 \) and then
\begin{align*} s \| = J − 1721119 = 2452826 − 1721119 = 731707 \\ \{c_1, ω_1 \} \| = \Div(9s + 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(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 \} \\ j \| = 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(9J − 15490069, 328718) = \Div(9×2452826 − 15490069, 328718) \\ \| = \Div(6585365, 328718) = \{ 20, 11005 \} \\ \{ 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\} \\ j \| = 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}\) | \({j}\) | \({m}\) | \({d}\) |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1721059 | −60 | −1 | 328180 | 36464 | 99 | 30524 | 305 | 9 | 150 | 30 | −1 | 0 | 11 | −1 | 12 | 31 |
1721060 | −59 | −1 | 328189 | 36465 | 99 | 30624 | 306 | 10 | 2 | 0 | −1 | 1 | 0 | 0 | 1 | 1 |
1721118 | −1 | −1 | 328711 | 36523 | 99 | 36424 | 364 | 11 | 139 | 27 | −1 | 1 | 1 | 0 | 2 | 28 |
1721119 | 0 | 0 | 2 | 0 | 0 | 99 | 0 | 0 | 2 | 0 | 0 | 0 | 2 | 0 | 3 | 1 |
1721119 | 0 | 0 | 2 | 0 | 0 | 99 | 0 | 0 | 2 | 0 | 0 | 0 | 2 | 0 | 3 | 1 |
2415078 | 693959 | 18 | 328709 | 36523 | 99 | 36424 | 364 | 11 | 139 | 27 | 1899 | 1 | 1 | 1900 | 2 | 28 |
2415079 | 693960 | 19 | 0 | 0 | 0 | 99 | 0 | 0 | 2 | 0 | 1900 | 0 | 2 | 1900 | 3 | 1 |
2451543 | 730424 | 19 | 328176 | 36464 | 99 | 30524 | 305 | 9 | 150 | 30 | 1999 | 0 | 11 | 1999 | 12 | 31 |
2451544 | 730425 | 19 | 328185 | 36465 | 99 | 30624 | 306 | 10 | 2 | 0 | 1999 | 1 | 0 | 2000 | 1 | 1 |
2451602 | 730483 | 19 | 328707 | 36523 | 99 | 36424 | 364 | 11 | 139 | 27 | 1999 | 1 | 1 | 2000 | 2 | 28 |
2451603 | 730484 | 19 | 328716 | 36524 | 99 | 36524 | 365 | 11 | 144 | 28 | 1999 | 1 | 1 | 2000 | 2 | 29 |
2451604 | 730485 | 20 | 7 | 0 | 0 | 99 | 0 | 0 | 2 | 0 | 2000 | 0 | 2 | 2000 | 3 | 1 |
2452826 | 731707 | 20 | 11005 | 1222 | 3 | 12724 | 127 | 4 | 25 | 5 | 2003 | 0 | 6 | 2003 | 7 | 6 |
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 schematically as follows:
j ─────────────────────┐ 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 |
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*}
Transformation 1 combines the month number \( m_0 \) since the beginning of the year and the day number \( d_0 \) since the beginning of the month into the day number \( d_1 \) since the beginning of the year.
\begin{equation} d_1 = 30 m_0 + d_0 \end{equation}
Transformation 2 combines the year number \( j \) and the day number \( d_1 \) since the beginning of the year into the running day number \( s \).
\begin{equation} s = 365 j + d_1 \end{equation}
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 \).
\begin{equation} J = s + J_0 = s + 1448273 \end{equation}
This condenses to
\begin{equation} J = 365j + 30m + d + 1448242 \end{equation}
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 \| = 365j + 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 \| = 365j + 30m + d + 1448242 \\ \| = 365×218 + 30×5 + 7 + 1448242 = 1527969 \end{align*}
which is the same answer as before. A few more examples:
\({j}\) | \({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 |
In the opposite direction, the calculations are simple as well.
The calendar levels are schematically as follows:
j ─────────────────────┐ 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 |
First we subtract the CJDN \( J_0 \) of running day number 0.
\begin{equation} s = J − J_0 = s − 1448273 \end{equation}
Transformation 2 deduces from the running day number \( s \) the year number \( j \) and the day number \( d_1 \) since the beginning of the year.
\begin{equation} \{ j, d_1 \} = \Div(s, 365) \end{equation}
Transformation 1 deduces from the day number since the beginning of the year the month number \( m_0 \) since the beginning of the year and the day number \( d_0 \) since the beginning of the month.
\begin{equation} \{ m_0, d_0 \} = \Div(d_1, 30) \end{equation}
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 \\ \{ j, 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}\) | \({j}\) | \({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 |
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:
j ────────────┐ 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 |
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*}
Transformation 1 calculates from the year number \( j \) and the month number \( m_0 \) since the beginning of the year the running month number \( m_1 \).
\begin{equation} m_1 = \dfloorratio{235j + 13}{19} + m_0 \end{equation}
Transformation 2 calculations from the running month number \( m_1 \) and the day number \( d_0 \) since the beginning of the month the running day number \( s \).
\begin{equation} s = \dfloorratio{6940m_1}{235} + d_0 \end{equation}
And then we add the CJDN of day 1 of month 1 of year 0.
\begin{equation} J = s + J_0 = s + 1607175 \end{equation}
This condenses to
\begin{equation} J = \dfloorratio{6940\dparen{\dfloorratio{235j + 13}{19} + m − 1}}{235} + d + 1607174 \end{equation}
For example, which CJDN \( J \) corresponds to year 3, month 9, day 27 of the era of Seleukos? Then \( j = 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{235j + 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:
\({j}\) | \({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 |
Now we go in the opposite direction, from Julian Day number \( J \) to day \( d \), month \( m \), year \( j \) in the era of Seleukos.
j ────────────┐ 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 |
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 \).
\begin{equation} s = J − J_0 = J − 1607175 \end{equation}
Transformation 2 calculates from the running day number \( s \) the running month number \( m_1 \) and the day number \( d_0 \) since the beginning of the month.
\begin{align} \{ m_1, ω_1 \} \| = \Div(235s + 234, 6940) \\ d_0 \| = \dfloorratio{ω_1}{235} \end{align}
Transformation 1 produces from the running month number \( m_1 \) the year number \( j \) and the month number \( m_0 \) since the beginning of the year.
\begin{align} \{ j, ω_2 \} \| = \Div(19m_1 + 5, 235) \\ m_0 \| = \dfloorratio{ω_2}{19} \end{align}
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) \\ \{ j, ω_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 \\ \{ j, ω_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\} \\ \{ j, ω_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}\) | \({j}\) | \({ω_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 |
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 leap days 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.
When it is necessary to indicate explicitly that a year is given according to the Jewish calendar, then A.M. (Anno Mundi, Year of the World) is used for that.
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 month number 1, but the first day of month number 7, which is the month of Tishri.
As an example we'll calculate the CJDN of the following dates in the Jewish calendar:
\({j}\) | Month | \({m}\) | \({d}\) |
---|---|---|---|
4524 | Kislev | 9 | 30 |
4527 | Sivan | 3 | 1 |
4682 | Kislev | 9 | 12 |
4682 | Sivan | 3 | 18 |
325709 | Adar Ⅱ | 13 | 29 |
The calculations are schematically as follows:
j ──────────[1]─ a₁ ──────┐ m ─(−1)─ m₀ ─┴───│────────┤ [2]─ d₁ ─[3]─ d₂ ─┐ d ─(−1)─ d₀ ─────────────────────[4]─ s ─(+J₀)─ J
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*}
For the example dates we find
\({j}\) | \({m}\) | \({d}\) | \({m_0}\) | \({d_0}\) |
---|---|---|---|---|
4524 | 9 | 30 | 8 | 29 |
4527 | 3 | 1 | 2 | 0 |
4682 | 9 | 12 | 8 | 11 |
4682 | 3 | 18 | 2 | 17 |
325709 | 13 | 29 | 12 | 28 |
Transformation 1 arranges that calculation month \( m_0 = 0 \) is the first month after the change of the calculation year number. We need to make a special effort for that because in the Jewish calendar the calendar year number increases by one at the beginning of calendar month 7. After calendar month 6 of year \( j − 1 \) there follows calendar month 7 of calendar year \( j \), then calendar months 8 through 12 or 13 of that calendar year \( j \), and then calendar months 1 through 6 of that same calendar year \( j \). Then follows month 7 of calendar year \( j + 1 \), and so on, as shown in the following table. Month 13 is shown between parentheses because not every calendar year has that month.
\({m}\) | \({m_0}\) | \({∆j}\) |
---|---|---|
6 | 5 | −1 |
7 | 6 | 0 |
8 | 7 | 0 |
9 | 8 | 0 |
10 | 9 | 0 |
11 | 10 | 0 |
12 | 11 | 0 |
(13) | (12) | 0 |
1 | 0 | 0 |
2 | 1 | 0 |
3 | 2 | 0 |
4 | 3 | 0 |
5 | 4 | 0 |
6 | 5 | 0 |
7 | 6 | +1 |
The sudden decrease of the month number halfway through the year is inconvenient for calculations, especially because whether or not a year has a 13th month depends in a complicated manner on which year it is. It is more convenient to place the beginning of the calculation year at the beginning of calendar month \( m = 1 \), which means calculation month \( m_0 = 0 \). We move calendar months 1 through 6 from calendar year \( j − 1 \) to calculation year \( a_1 = j \) that also contains the subsequent calendar months 7 through 12 or 13. Then New Year (1 Tishri) of calendar year \( j \) belongs to calculation year \( a_1 = j \). We arrange this through:
\begin{align} α_1 \| = \dfloorratio{12 − m_0}{7} \\ a_1 \| = j + α_1 \end{align}
For example, after the last day of calendar month 13 of calendar year 4682 in the Jewish calendar comes the first day of month 1 of still year 4682 (not year 4683!). A few months later, after the last day of month 6 of year 4682 comes the first day of month 7 of year 4683. That day is New Year's Day. The following table shows a few correspondences.
\({j}\) | \({m}\) | \({d}\) | \({m_0}\) | \({d_0}\) | \({α_1}\) | \({a_1}\) |
---|---|---|---|---|---|---|
4682 | 13 | 29 | 12 | 28 | 0 | 4682 |
4682 | 1 | 1 | 0 | 0 | 1 | 4683 |
4682 | 2 | 1 | 1 | 0 | 1 | 4683 |
4682 | 3 | 1 | 2 | 0 | 1 | 4683 |
4682 | 4 | 1 | 3 | 0 | 1 | 4683 |
4682 | 5 | 1 | 4 | 0 | 1 | 4683 |
4682 | 6 | 1 | 5 | 0 | 1 | 4683 |
4682 | 6 | 29 | 5 | 28 | 1 | 4683 |
4683 | 7 | 1 | 6 | 0 | 0 | 4683 |
4683 | 8 | 1 | 7 | 0 | 0 | 4683 |
4683 | 9 | 1 | 8 | 0 | 0 | 4683 |
4683 | 10 | 1 | 9 | 0 | 0 | 4683 |
4683 | 11 | 1 | 10 | 0 | 0 | 4683 |
4683 | 12 | 1 | 11 | 0 | 0 | 4683 |
4683 | 12 | 30 | 11 | 29 | 0 | 4683 |
4683 | 1 | 1 | 0 | 0 | 1 | 4684 |
For calculation month \( m_0 = 8 \) we find \( α_1 = \dfloor{(12 − m_0)/7} = \dfloor{4/7} = 0 \) so \( a_1 = j \). For calculation month \( m_0 = 4 \) we find \( α_1 = \dfloor{(12 ― 4)/7} = 1 \) so \( a_1 = j + 1 \). See the table above for more examples.
For the example dates we find
\({j}\) | \({m}\) | \({d}\) | \({m_0}\) | \({α_1}\) | \({a_1}\) |
---|---|---|---|---|---|
4524 | 9 | 30 | 8 | 0 | 4524 |
4527 | 3 | 1 | 2 | 1 | 4528 |
4682 | 9 | 12 | 8 | 0 | 4682 |
4682 | 3 | 18 | 2 | 1 | 4683 |
325709 | 13 | 29 | 12 | 0 | 325709 |
Transformation 2 produces the running day number \( d_1 \) of New Year's Day of calendar year \( j \), which is also New Year's Day of calendar year \( a_1 = j \). This is a complicated procedure that depends not only on year \( j \) but also on the previous and next years.
The embolismic years (calendar years with 13 months) are the 3rd, 6th, 8th, 11th, 14th, 17th, and 19th year in each cycle of 19 years, which holds 235 months. The running month number \( μ_1 \) of New Year's Day of calendar year \( j \) is
\begin{equation} μ_1 = \dfloorratio{235j − 234}{19} \label{eq:j2μ1} \end{equation}
For the beginning of Jewish year A.M. 4682 (\( j = 4682 \)) we find
\begin{align*} μ_1 \| = \dfloorratio{235j − 234}{19} = \dfloorratio{235×4682 − 234}{19} \\ \| = \dfloorratio{1100036}{19} = 57896 \end{align*}
so New Year of A.M. 4682 is 57896 months after New Year of A.M. 1.
For the example dates we find
\({j}\) | \({μ_1}\) |
---|---|
−1 | −25 |
0 | −13 |
1 | 0 |
2 | 12 |
4524 | 55942 |
4527 | 55979 |
4682 | 57896 |
325709 | 4028493 |
If you're working in a calculation environment where whole numbers cannot be greater than a certain value \( w \), then (to avoid overflow) \( j \) in the preceding formula must not exceed \( w/235 \), instead of \( w \). For \( w = 2^{31} \), \( w/235 \) years correspond to 9'138'228 years. If that is too few for you, then you can find alternatives in the manner of Section 12.2. One alternative is
\begin{equation} μ_1 = 12j + \dfloorratio{7j − 234}{19} \end{equation}
for which \( |j| \) must not exceed \( w/7 \). Another alternative is, for \( w = 2^{31} = 2147483648 \)
\begin{align} \{ ω_1, α_2 \} \| = \Div(j, 11) \\ μ_1 \| = 136ω_1 + \dfloorratio{ω_1 + 235α_2 − 234}{19} \end{align}
for which \( |j| \) may have any value up to \( w \).
The epoch of the calendar (the beginning of 1 Tishri of year A.M. 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 the year 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 A.M. 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 \( μ_1 \) is equal to
\begin{equation} δ_1 = \dfrac{765433μ_1 + 5604}{25920} \label{eq:μ} \end{equation}
The running day number \( δ_2 \) of the calendar day on which that New Moon occurs is
\begin{equation} δ_2 = \dfloor{δ_1} = \dfloorratio{765433μ_1 + 5604}{25920} \end{equation}
We again look at New Year of the Jewish year A.M. 4682. We earlier found that \( μ_1 = 57896 \). Then
\begin{align*} δ_1 \| = \dfrac{765433μ_1 + 5604}{25920} = \dfrac{765433×57896 + 5604}{25920} \\ \| = \frac{44315514572}{25920} = 1709703 + \frac{12812}{25920} \\ δ_2 \| = \dfloorratio{765433μ_1 + 5604}{25920} = \dfloorratio{765433×57896 + 5604}{25920} \\ \| = \dfloorratio{44315514572}{25920} = 1709703 \end{align*}
Note that the greatest intermediate result 44'315'514'572 far exceeds what will fit in a memory location of 32 bits.
For the example dates we find
\({j}\) | \({μ_1}\) | \({δ_2}\) |
---|---|---|
4524 | 55942 | 1652000 |
4527 | 55979 | 1653093 |
4682 | 57896 | 1709703 |
325709 | 4028493 | 118963791 |
If you're working in a calculation environment where whole numbers cannot be greater than a certain value \( w \), then (to avoid overflow) \( μ_1 \) in the preceding formula must not exceed \( w/235 \), instead of \( w \). For \( w = 2^{31} \), that is \( w/765433 ≈ 2805 \) months, which correspond to about 226 years, which is far too little to be practical. In the manner of Section 12.2 we find the following alternative:
\begin{align} \{ω_2, μ_2\} \| = \Div(μ_1, 1095) \\ δ_2 \| = 32336ω_2 + \dfloorratio{15ω_2 + 765433μ_2 + 5604}{25920} \end{align}
For the same case as in the previous example we find
\begin{align*} \{ω_2, μ_2\} \| = \Div(μ_1, 1095) = \Div(57896, 1095) = \{52, 956\} \\ δ_2 \| = 32336ω_2 + \dfloorratio{15ω_2 + 765433μ_2 + 5604}{25920} \\ \| = 32336×52 + \dfloorratio{15×52 + 765433×956 + 5604}{25920} \\ \| = 1681472 + \dfloorratio{731760332}{25920} = 1681472 + 28231 = 1709703 \end{align*}
which is the same result as before, but now the greatest intermediate result 731'760'332 is comfortably less than \( w \) = 2'147'483'648.
For the example dates we find
\({j}\) | \({μ_1}\) | \({ω_2}\) | \({μ_2}\) | \({δ_2}\) |
---|---|---|---|---|
4524 | 55942 | 51 | 97 | 1652000 |
4527 | 55979 | 51 | 134 | 1653093 |
4682 | 57896 | 52 | 956 | 1709703 |
325709 | 4028493 | 3678 | 1083 | 118963791 |
Transformation 4 adjusts the provisionary running day number \( δ_2 \) for four possible delays.
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
\begin{equation} δ_3 = \dfloor{δ_1 + \frac{1}{4}} = \dfloorratio{765433μ_1 + 12084}{25920} \label{eq:υ_1} \end{equation}
For A.M. 4682 we find
\begin{align*} δ_3 \| = \dfloorratio{765433μ_1 + 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.
If you're working in a calculation environment where whole numbers must not exceed some value \( w \), then the same limitations hold here as in the previous example. You can then use the same alternatives as in the previous example, if you replace 5604 by 12084 there.
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
\begin{equation} δ_4 = \dmod{δ_3}{7} \end{equation}
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
\begin{equation} δ_5 = δ_3 + \dmod{\dfloorratio{6δ_3}{7}}{2} \label{eq:υ_2} \end{equation}
If you're working in a calculation environment where whole numbers must not exceed some value \( w \), then \( δ_3 \) must not exceed \( w/6 \). For 32-bit numbers this corresponds to about 979914 years. If that is not enough, then you can use \( \dmod{\dfloor{k\dmod{δ_3}{7}}}{2} \) after all:
\begin{equation} δ_5 = δ_3 + \dmod{\dfloorratio{6\dmod{δ_3}{7}}{7}}{2} \end{equation}
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(j) \) of calendar year \( j \) (including the effects of the first two delays) is equal to
\begin{equation} L_2(j) = δ_5(j + 1) − δ_5(j) \end{equation}
so New Year of year \( j \) is delayed by 2 days if \( L_2(j) = 356 \). We achieve the desired effect with formula
\begin{equation} δ_6 = 2\dmod{\dfloorratio{L_2 + 19}{15}}{2} \end{equation}
\({L_2}\) | \({δ_6}\) |
---|---|
353 | 0 |
354 | 0 |
355 | 0 |
356 | 2 |
382 | 0 |
383 | 0 |
384 | 0 |
385 | 0 |
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 year \( j \) is delayed by 1 day when \( L_2(j − 1) = 382 \). We get the desired effect with formula
\begin{equation} δ_7 = \dmod{\dfloorratio{L_2(j − 1) + 7}{15}}{2} \end{equation}
\({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} μ_1(j) \| = \dfloorratio{235j − 234}{19} \\ δ_3(j) \| = \dfloorratio{765433μ_1(j) + 12084}{25920} \\ δ_5(j) \| = δ_3(j) + \dmod{\dfloorratio{6δ_3(j)}{7}}{2} \\ L_2(j) \| = δ_5(j + 1) − δ_5(j) \\ d_1(j) \| = δ_5(j) + 2\dmod{\dfloorratio{L_2(j) + 19}{15}}{2} + \dmod{\dfloorratio{L_2(j − 1) + 7}{15}}{2} \notag \\ \| = δ_5(j) + 2\dmod{\dfloorratio{δ_5(j + 1) − δ_5(j) + 19}{15}}{2} \notag \\ \| + \dmod{\dfloorratio{δ_5(j) − δ_5(j − 1) + 7}{15}}{2} \end{align}
Note that to calculate \( d_1 \) for year \( j \) requires the values of \( δ_5(j − 1) \), \( δ_5(j) \), and \( δ_5(j + 1) \).
We now know the running day number \( d_1 \) of New Year (1 Tishri) of calendar year \( j \), which is also New Year of calculation year \( a_1 = j \).
The length \( L \) of year \( j \) is then equal to
\begin{equation} L = d_1(j + 1) − d_1(j) \end{equation}
For the calculation of \( L \) of year \( j \) you need \( δ_5 \) for the 4 years \( j − 1 \) through \( j + 2 \).
Years do not exist for which \( L_2(j) = 356 \) and at the same time \( L_2(j − 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 \( j = 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 \( j = 4682 \) taking into account the first two delays is \( L_2(4682) = δ_5(4683) − δ_5(4682) = 1710087 − 1709704 = 383 \) days. The year with \( j = 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:
\({j}\) | \({δ_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 |
Transformation 3 produces the running day number \( d_2 \) of the first day of calculation month \( m_0 \) 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 Ⅰ | 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 (of types 1 or 2 from Sec. 12.11), because the number of successive months with the same length varies by more than one. In the first seven months, the number of successive months with the same length is equal to 1, but after that it is sometimes equal to 3. For example, months 8 through 10 in a year of 353 or 383 days are all 29 days long, and months 7 through 9 in a year of 355 or 385 days are all 30 days long.
The lengths that the months have in a year of 384 days long fit the equation
\begin{equation} δ_8 = \dfloorratio{384m_0 + 7}{13} \end{equation}
where \( m_0 \) is the calculation month number, and \( δ_8 \) is the day number of the first day of that month since the first day of month 1. Note: In a year of 12 months we assign month Adar \( m_0 = 11 \) but in a year of 13 months we assign Adar (which is then called Adar Ⅱ) \( m_0 = 12 \).
\({m_0}\) | \({δ_8}\) | \({∆δ_8}\) |
---|---|---|
0 | 0 | 30 |
1 | 30 | 29 |
2 | 59 | 30 |
3 | 89 | 29 |
4 | 118 | 30 |
5 | 148 | 29 |
6 | 177 | 30 |
7 | 207 | 29 |
8 | 236 | 30 |
9 | 266 | 29 |
10 | 295 | 30 |
11 | 325 | 30 |
12 | 355 | 29 |
This formula can also be used for month lengths in a year of 354 days, when the length of the year terminates the 12th month (\( m_0 = 11 \)) at 29 days.
A correction to this formula is needed for years with a length \( L \) unequal to 354 or 384 days. In a year with 353 or 383 days, calculation month 8 must be one day shorter. In a year with 355 or 385 days, calculation month 7 must be one day longer. The corrections \( δ_9 \) for month 7 and \( δ_{10} \) for month 8 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 8 through 12, and the \( δ_{10} \) correction to dates in calculation months 9 through 12. In the following table, \( ω_2 \) shows (with value 1) to which months the \( δ_9 \) correction applies, and \( ω_3\) likewise for the \( δ_{10} \) correction.
\({m_0}\) | \({ω_2}\) | \({ω_3}\) |
---|---|---|
0 | 0 | 0 |
1 | 0 | 0 |
2 | 0 | 0 |
3 | 0 | 0 |
4 | 0 | 0 |
5 | 0 | 0 |
6 | 0 | 0 |
7 | 0 | 0 |
8 | 1 | 0 |
9 | 1 | 1 |
10 | 1 | 1 |
11 | 1 | 1 |
12 | 1 | 1 |
We get that using the equations
\begin{align} ω_2 \| = \dfloorratio{m_0 + 4}{12} \\ ω_3 \| = \dfloorratio{m_0 + 3}{12} \end{align}
With that, the formula to go from calculation month \( m_0 \) to day number \( δ_{11} \) of the first day of that month since the first day of month Nisan (\( m_0 = 0 \))
\begin{align} δ_{11} \| = δ_8 + ω_2 δ_9 + ω_3 δ_{10} \notag \\ \| = \dfloorratio{384m_0 + 7}{13} + \dmod{\dfloorratio{L + 1}{2}}{3} \dfloorratio{m_0 + 4}{12} − \dmod{\dfloorratio{385 − L}{2}}{3} \dfloorratio{m_0 + 3}{12} \end{align}
For month Kislev (\( m_0 = 8 \)) of calculation year 4682 (that has \( L = 385 \)) we find
\begin{align*} δ_8 \| = \dfloorratio{384m_0 + 7 }{13} = \dfloorratio{384×8 + 7}{13} = \dfloorratio{3079}{13} = 236 \\ δ_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_0 + 4}{12} = \dfloorratio{8 + 4}{12} = \dfloorratio{12}{12} = 1 \\ ω_3 \| = \dfloorratio{m_0 + 3}{12} = \dfloorratio{8 + 3}{12} = \dfloorratio{11}{12} = 0 \\ δ_{11} \| = δ_8 + ω_2 δ_9 + ω_3 δ_{10} = 236 + 1×1 − 0×0 = 237 \end{align*}
For the example dates we find
\({j}\) | \({m}\) | \({L}\) | \({δ_8}\) | \({δ_9}\) | \({δ_{10}}\) | \({ω_2}\) | \({ω_3}\) | \({δ_{11}}\) |
---|---|---|---|---|---|---|---|---|
4524 | 9 | 355 | 236 | 1 | 0 | 1 | 0 | 237 |
4527 | 3 | 354 | 59 | 0 | 0 | 0 | 0 | 59 |
4682 | 9 | 385 | 236 | 1 | 0 | 1 | 0 | 237 |
4682 | 3 | 385 | 59 | 1 | 0 | 0 | 0 | 59 |
325709 | 13 | 385 | 355 | 1 | 0 | 1 | 1 | 356 |
The calendar months 1 through 6 (calculation months 0 through 5) together contain 177 days in every year, so 1 Nisan (calculation month 0) of calculation year \( a_1 \) is always 177 days before 1 Tishri (calculation month 6) of the same calculation year (not calendar year), so the running day number \( δ_{12} \) of 1 Nisan of calculation year \( a_1 \) is
\begin{equation} δ_{12} = d_1(a_1) − 177 \end{equation}
With that, the running day number \( d_2 \) of the first day of calculation month \( m_0 \) of calculation year \( a_1 \), measured since 1 Tishri of calendar year 1, is
\begin{equation} d_2 = δ_{12} + δ_{11} = d_1(a_1) − 177 + δ_{11} \end{equation}
For month Kislev of calendar year \( j = 4682 \) we find \( a_1 = j = 4682 \) so
\[ d_2 = d_1(4682) − 177 + δ_{11} = 1709704 − 177 + 237 = 1709764 \]
For the example dates we find
\({j}\) | \({a_1}\) | \({m}\) | \({d}\) | \({d_1}\) | \({δ_{11}}\) | \({δ_{12}}\) | \({d_2}\) |
---|---|---|---|---|---|---|---|
4524 | 4524 | 9 | 30 | 1652000 | 237 | 1651823 | 1652060 |
4527 | 4528 | 3 | 1 | 1653447 | 59 | 1653270 | 1653329 |
4682 | 4682 | 9 | 12 | 1709704 | 237 | 1709527 | 1709764 |
4682 | 4683 | 3 | 18 | 1710089 | 59 | 1709912 | 1709971 |
325709 | 325709 | 13 | 29 | 118963792 | 356 | 118963615 | 118963971 |
Transformation 3 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 \( j \) and the day number \( d_0 \) within the month:
\begin{equation} s = d_2 + d_0 \end{equation}
For day 12 of Kislev 4682 we find
\[ s = 1709764 + 11 = 1709775 \]
For the example dates we find
\({j}\) | \({m}\) | \({d}\) | \({d_0}\) | \({d_2}\) | \({s}\) |
---|---|---|---|---|---|
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 |
The epoch of the calendar is 1 Tishri of the year A.M. 1 and corresponds to CJDN 347'998 = \( J_0 \). So, the CJDN \( J \) of the desired date is
\begin{equation} J = s + J_0 = s + 347998 \end{equation}
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
\({j}\) | \({m}\) | \({d}\) | \({s}\) | \({J}\) |
---|---|---|---|---|
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 preceding calculations condense to
\begin{align} a_1 \| = j + \dfloorratio{13 − m}{7} \\ δ_3(a_1) \| = \dfloorratio{765433\dfloorratio{235a_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 \| = δ_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) \\ J \| = d_1(a_1) + \dfloorratio{384m + 7 − 384}{13} + \dmod{\dfloorratio{L + 1}{2}}{3} \dfloorratio{m + 3}{12} \notag \\ \| − \dmod{\dfloorratio{385 − L}{2}}{3} \dfloorratio{m + 2}{12} + d + 347820 \end{align}
For 12 Kislev 4682 (\( j = 4682, m = 9, d = 12\)) we find
\begin{align*} a_1 \| = j + \dfloorratio{13 − m}{7} = 4682 + \dfloorratio{13 − 9}{7} = 4682 + \dfloorratio{4}{7} = 4682 \\ δ_3(a_1) \| = \dfloorratio{765433\dfloorratio{235a_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) = 1709349s \\ δ_3(a_1 + 1) \| = δ_3(4683) = 1710087 \\ δ_3(a_1 + 2) \| = δ_3(4684) = 1710442 \\ δ_5(a_1) \| = δ_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} \\ \| = 1709703 + 1 = 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) \| = δ_5(a_1 + 1) − δ_5(a_1) = 1710087 − 1709704 = 383 \\ L_2(a_1 − 1) \| = L_2(4681) = 355 \\ L_2(a_1 + 1) \| = L_2(4683) = 356 \\ 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} \\ \| = 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(a1 + 1) \| = d_1(4683) = 1710089 \\ L \| = d_1(a_1 + 1) − d_1(a_1) = 1710089 − 1709704 = 385 \\ J \| = d_1(a_1) + \dfloorratio{384m + 7 − 384}{13} + \dmod{\dfloorratio{L + 1}{2}}{3} \dfloorratio{m + 3}{12} \\ \| − \dmod{\dfloorratio{385 − L}{2}}{3} \dfloorratio{m + 2}{12} + d + 347820 \\ \| = 1709704 + \dfloorratio{384×9 + 7 − 384}{13} + \dmod{\dfloorratio{385 + 1}{2}}{3} \dfloorratio{9 + 3}{12} \\ \| − \dmod{\dfloorratio{385 − 385}{2}}{3} \dfloorratio{9 + 2}{12} + 12 + 347820 \\ \| = 1709704 + \dfloorratio{3079}{13} + \dmod{\dfloorratio{386}{2}}{3} \dfloorratio{12}{12} \notag − \dmod{\dfloorratio{0}{2}}{3} \dfloorratio{11}{12} + 347832 \\ \| = 1709704 + 236 + \dmod{193}{3}×1 − \dmod{0}{3}×0 + 347832 \\ \| = 2057772 + 1 − 0 = 2057773 \end{align*}
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.
Transform CJDN \( J \) into running day number \( s \) since 1 Tishri A.M. 1:
\begin{equation} s = J − J_0 = J − 347998 \end{equation}
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}\) |
---|---|
2000087 | 1652089 |
2001327 | 1653506 |
2057773 | 1709775 |
2057986 | 1710165 |
119311997 | 118964176 |
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, but we have to take into account that there is a 177 day difference between the zero point of \( s \) and the zero point of the \( μ_1 \) upon which that formula is based. And with the inverse of equation \eqref{eq:j2μ1} we can then find the provisional calculation year number \( α_3 \) and calculation month number \( μ_3 \) in the calculation year:
\begin{align} μ_2 \| = \dfloorratio{25920(s + 177) + 25920 − 12084 − 1}{765433} = \dfloorratio{25920s + 4601675}{765433} \notag \\ \| = 6 + \dfloorratio{25920s + 9077}{765433} \label{eq:y_1p} \\ \{α_3,ω_3\} \| = \Div(19μ_2 + 252, 235) \\ μ_3 \| = \dfloorratio{ω_3}{19} \end{align}
For \( J = 2057773 \) we found earlier \( s = 1709775 \), and now we find
\begin{align*} μ_2 \| = 6 + \dfloorratio{25920s + 9077}{765433} = 6 + \dfloorratio{25920×1709775 + 9077}{765433} \\ \| = 6 + \dfloorratio{44317377077}{765433} = 57904 \\ \{ α_3, ω_3 \} \| = \Div(19μ_2 + 252, 235) = \Div(19×57904 + 252, 235) \\ \| = \Div(1100428, 235) = \{ 4682, 158 \} \\ μ_3 \| = \dfloorratio{ω_3}{19} = \dfloorratio{158}{19} = 8 \end{align*}
Note that the greatest intermediate result 44'317'377'077 is far greater than will fit in a 32-bit memory location in a computer.
Some more examples:
\({J}\) | \({s}\) | \({μ_2}\) | \({α_3}\) | \({ω_3}\) | \({μ_3}\) |
---|---|---|---|---|---|
2000087 | 1652089 | 55951 | 4524 | 181 | 9 |
2001327 | 1653329 | 55992 | 4528 | 20 | 1 |
2057773 | 1709775 | 57904 | 4682 | 158 | 8 |
2057986 | 1709988 | 57911 | 4683 | 56 | 2 |
119311997 | 118963999 | 4028506 | 325710 | 16 | 0 |
If you're working in a calculation environment in which whole numbers must not exceed a certain value \( w \), then (to avoid overflow) in equation \eqref{eq:y_1p} \( |s| \) must not exceed \( w/25920 \), which is much less than \( w \). For 32-bit numbers this corresponds to about 226 years − far too few to be practical. Using Sec. 12.2 we can find better alternatives. One alternative, when \( w = 2^{31} = 2147483648 \), is
\begin{align} \{ω_4, δ_{13}\} \| = \Div(s, 1447) \\ μ_2 \| = 6 + 49ω_4 + \dfloorratio{23ω_4 + 25920δ_{13} + 9077}{765433} \end{align}
for which \( |s| \) may have any value up to \( w \), which corresponds to about 5.9 million years.
For \( s = 1709775 \) we find
\begin{align*} \{ω_3, δ_{13}\} \| = \Div(s, 1447) = \left\{ \dfloorratio{s}{1447}, \dmod{s}{1447} \right\} \\ \| = \left\{ \dfloorratio{1709775}{1447}, \dmod{1709775}{1447} \right\} = \{ 1181, 868 \} \\ μ_2 \| = 6 + 49ω_4 + \dfloorratio{23ω_4 + 25920δ_{13} + 9077}{765433} \\ \| = 6 + 49×1181 + \dfloorratio{23×1181 + 25920×868 + 9077}{765433} \\ \| = 57875 + \dfloorratio{22534800}{765433} = 57875 + 29 = 57904 \end{align*}
just like before. Now the greatest intermediate result is 22'534'800, less than \( w \).
For all example CJDNs we find
\({J}\) | \({s}\) | \({ω_4}\) | \({δ_{13}}\) | \({μ_2}\) |
---|---|---|---|---|
2000087 | 1652089 | 1141 | 1062 | 55951 |
2001327 | 1653329 | 1142 | 855 | 55992 |
2057773 | 1709775 | 1181 | 868 | 57904 |
2057986 | 1709988 | 1181 | 1081 | 57911 |
119311997 | 118963999 | 82214 | 341 | 4028506 |
If we calculate the running day number \( d_2 \) (from 13.6.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.
We can use the inverse of Equation \eqref{eq:j2μ1} to calculate the provisional calendar year number \( y \) and provisional calculation month number \( z \) since the first month of the calendar year from running month number \( x \):
\begin{align} \{y, ω\} \| = \Div(19x + 19 − (−234) − 1, 235) = \Div(19x + 252, 235) \label{eq:μ12j} \\ z \| = \dfloorratio{ω}{19} \end{align}
The minimal calculation is as follows:
Calculate the provisional calendar year number \( α_3 \) and provisional calculation month number \( μ_3 \):
\begin{align} \{ α_3, ω_3 \} \| = \Div(19μ_2 + 252, 235) \\ μ_3 \| = \dfloorratio{ω_3}{19} \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. 13.6.1, and then the provisional calculation day number \( δ_{14} \) since the first day of that month:
\begin{equation} δ_{14} = s − d_2(α_3, μ_3) \end{equation}
If \( 0 ≤ δ_{14} ≤ 28 \) then the sought calculation date \( \{ a_1, m_0, d_0 \} \) is \( \{ α_3, μ_3, δ_{14} \} \).
If \( δ_{14} = 29 \) then calculate the second provisional running month number \( μ_5 \):
\begin{equation} μ_5 = μ_2 + 1 \end{equation}
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 + 252, 235) \\ μ_6 \| = \dfloorratio{ω_4}{19} \\ δ_{15} \| = s − d_2(α_4, μ_6) \end{align}
If \( δ_{15} \lt 0 \) then the sought calculation date \( \{ a_1, m_0, 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_0, d_0 \} \) is \( \{ α_4, μ_6, δ_{15} \} \).
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_0 \), and the calculation day number \( d_0 \):
\begin{align} \{a_1, ω_5\} \| = \Div(19μ_7 + 252, 235) \\ m_0 \| = \dfloorratio{ω_5}{19} \\ d_0 \| = s − d_2(a_1, m_0) \end{align}
For \( J = 2057773 \) we had \( s = 1709775, μ_2 = 57904 \). Then
\begin{align*} \{ α_3, ω_3 \} \| = \Div(19μ_2 + 252, 235) = \Div(19×57904 + 252, 235) \\ \| = \Div(1100428, 235) = \{ 4682, 158 \} \\ μ_3 \| = \dfloorratio{ω_3}{19} = \dfloorratio{158}{19} = 158\19 = 8 \end{align*}
Then we calculate \( d_2(α_3, μ_3) = d_2(4682, 8) \) as described in Sec. 13.6.1. We find \( d_2(4682, 8) = 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_0, d_0 \} \) is equal to \( \{ α_3, μ_3, δ_{14} \} = \{ 4682, 8, 11 \}\).
For all example CJDNs we find
\({J}\) | \({s}\) | \({μ_2}\) | \({α_3}\) | \({μ_3}\) | \({d_2}\) | \({δ_{14}}\) | \({μ_7}\) | \({a_1}\) | \({m_0}\) | \({d_2}\) | \({d_0}\) |
---|---|---|---|---|---|---|---|---|---|---|---|
2000087 | 1652089 | 55951 | 4524 | 9 | 1652090 | −1 | 55950 | 4524 | 8 | 1652060 | 29 |
2001327 | 1653329 | 55992 | 4528 | 1 | 1653300 | 29 | 55993 | 4528 | 2 | 1653329 | 0 |
2057773 | 1709775 | 57904 | 4682 | 8 | 1709764 | 11 | 4682 | 8 | 11 | ||
2057986 | 1709988 | 57911 | 4683 | 2 | 1709971 | 17 | 4683 | 2 | 17 | ||
119311997 | 118963999 | 4028506 | 325710 | 0 | 118964000 | −1 | 4028505 | 325709 | 12 | 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.
The first provisional running month number \( μ_3 \) is
\begin{equation} μ_3 = μ_2 + 1 \end{equation}
From that, calculate the provisional calendar year number \( α_3 \) and provisional calculation month number \( μ_4 \):
\begin{align} \{α_3, ω_3\} \| = \Div(19μ_3 + 252, 235) \\ μ_4 \| = \dfloorratio{ω_3}{19} \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. 13.6.1, and then the provisional calculation day number \( δ_{14} \) since the first day of that month:
\begin{equation} δ_{14} = s − d_2(α_3, μ_4) \end{equation}
The second provisional running month number \( μ_5 \) is
\begin{equation} μ_5 = μ_3 + \dfloorratio{δ_{14}}{64} \end{equation}
(The divider 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 + 252, 235) \\ μ_6 \| = \dfloorratio{ω_4}{19} \\ δ_{15} \| = s − d_2(α_4, μ_6) \end{align}
The final running month number \( μ_7 \) is
\begin{equation} μ_7 = μ_5 + \dfloorratio{δ_{15}}{64} \end{equation}
From that, calculate the calendar year number \( a_1 \), the calculation month number \( m_0 \), and the calculation day number \( d_0 \):
\begin{align} \{a_1, ω_5\} \| = \Div(19μ_7 + 252, 235) \\ m_0 \| = \dfloorratio{ω_5}{19} \\ d_0 \| = s − d_2(a_1, m_0) \end{align}
For \( J = 2057773 \) we had \( μ_2 = 57904 \). Then
\begin{align*} μ_3 \| = μ_2 + 1 = 57904 + 1 = 57905 \\ \{ α_3, ω_3 \} \| = \Div(19×57905 + 252, 235) = \Div(1100447, 235) \\ \| = \{ 4682, 177 \} \\ μ_4 \| = \dfloorratio{ω_3}{19} = \dfloorratio{177}{19} = 9 \end{align*}
Then we can calculate \( d_2(α_3, μ_4) = d_2(4682, 9) \) as described in Sec. 13.6.1, and find \( d_2(4682, 9) = 1709794 \). Then \( δ_{14} = s − d_2(4682, 9) = 1709775 − 1709794 = −19 \). And then
\[ μ_5 = μ_3 + \dfloorratio{δ_{14}}{64} = 57905 + \dfloorratio{−19}{64} = 57904 \]
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 = 8, δ_{15} = 11 \). Then
\[ μ_7 = μ_5 + \dfloorratio{δ_{15}}{64} = 57904 + \dfloorratio{11}{64} = 57904 \]
so \( μ_7 = μ_5 \), which means the numbers don't change anymore, so we end up with \( a_1 = 4682, m_0 = 8, d_0 = 11 \).
For all example CJDNs we find
\({J}\) | \({s}\) | \({μ_2}\) | \({μ_3}\) | \({α_3}\) | \({μ_4}\) | \({d_2}\) | \({δ_{14}}\) | \({μ_5}\) | \({α_4}\) | \({μ_6}\) | \({d_2}\) | \({δ_{15}}\) | \({μ_7}\) | \({a_1}\) | \({m_0}\) | \({d_2}\) | \({d_0}\) |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2000087 | 1652089 | 55951 | 55952 | 4524 | 10 | 1652119 | −30 | 55951 | 4524 | 9 | 1652090 | −1 | 55950 | 4524 | 8 | 1652060 | 29 |
2001327 | 1653329 | 55992 | 55993 | 4528 | 2 | 1653329 | 0 | 55993 | 4528 | 2 | 1653329 | 0 | 55993 | 4528 | 2 | 1653329 | 0 |
2057773 | 1709775 | 57904 | 57905 | 4682 | 9 | 1709794 | −19 | 57904 | 4682 | 8 | 1709764 | 11 | 57904 | 4682 | 8 | 1709764 | 11 |
2057986 | 1709988 | 57911 | 57912 | 4683 | 3 | 1710001 | −13 | 57911 | 4683 | 2 | 1709971 | 17 | 57911 | 4683 | 2 | 1709971 | 17 |
119311997 | 118963999 | 4028506 | 4028507 | 325710 | 1 | 118964030 | −31 | 4028506 | 325710 | 0 | 118964000 | −1 | 4028505 | 325709 | 12 | 118963971 | 28 |
Transformation 1 produces calendar year \( j \) from calculation year \( a_1 \) and calculation month \( m_0 \). Calculation months 0 through 5 of calculation year \( a_1 \) belong to calendar year \( j = a_1 − 1 \), and calculation months 6 through 12 belong to calendar year \( j = a_1 \). We arrange that through
\begin{equation} j = a_1 + \dfloorratio{m_0 − 6}{7} \end{equation}
\({m_0}\) | \({∆j}\) |
---|---|
0 | −1 |
1 | −1 |
2 | −1 |
3 | −1 |
4 | −1 |
5 | −1 |
6 | 0 |
7 | 0 |
8 | 0 |
9 | 0 |
10 | 0 |
11 | 0 |
12 | 0 |
For \( J = 2057773 \) we had \( a_1 = 4682 \) and \( m_0 = 8 \) so
\[ j = a_1 + \dfloorratio{m_0 − 6}{7} = 4682 + \dfloorratio{8 − 6}{7} = 4682 + \dfloorratio{2}{7} = 4682 \]
For all example CJDNs we find
\({J}\) | \({a_1}\) | \({m_0}\) | \({d_0}\) | \({j}\) |
---|---|---|---|---|
2000087 | 4524 | 8 | 29 | 4524 |
2001327 | 4528 | 2 | 0 | 4527 |
2057773 | 4682 | 8 | 11 | 4682 |
2057986 | 4683 | 2 | 17 | 4682 |
119311997 | 325709 | 12 | 28 | 325709 |
And them we add 1 to the calculation month and calculation day to find the calendar month and calendar day.
\begin{align} m \| = m_0 + 1 \\ d \| = d_0 + 1 \end{align}
For \( J = 2057773 \) we had \( m_0 = 8 \) and \( d_0 = 11 \) so
\begin{align*} m \| = m_0 + 1 = 8 + 1 = 9 \\ d \| = d_0 + 1 = 11 + 1 = 12 \end{align*}
so \( J = 2057773 \) corresponds to day 12 of month 9 of year 4682.
For all example CJDNs we find
\({J}\) | \({a_1}\) | \({m_0}\) | \({d_0}\) | \({j}\) | \({m}\) | \({d}\) |
---|---|---|---|---|---|---|
2000087 | 4524 | 8 | 29 | 4524 | 9 | 30 |
2001327 | 4528 | 2 | 0 | 4527 | 3 | 1 |
2057773 | 4682 | 8 | 11 | 4682 | 9 | 12 |
2057986 | 4683 | 2 | 17 | 4682 | 3 | 18 |
119311997 | 325709 | 12 | 28 | 325709 | 13 | 29 |
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:
The calendar year in the lunisolar calendar should be roughly the same as the calendar year in the modern (Gregorian) calendar.
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.
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).
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.
The calculations are schematically as follows:
j ────────────────────┐ 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 |
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 \( \{ j, 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*}
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 | |
Transformation 2 yields the running day number \( s \) from the year \( j \) and the day number \( d_1 \) since the first day of the year.
\begin{align} δ_2 \| = 354j + 30\dfloorratio{7j + 2}{19} + \dfloorratio{4j + 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.
\({j}\) | \({δ_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 \( j = 2033, d_1 = 0 \), so
\begin{align*} δ_2 \| = 354j + 30\dfloorratio{7j + 2}{19} + \dfloorratio{4j + 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*}
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 \).
\begin{equation} J = s + J_0 = s + 1721019 \end{equation}
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{equation} J = 354j + 30\dfloorratio{7j + 2}{19} + \dfloorratio{4j + 18}{19} + \dfloorratio{384m − 377}{13} + d + 1721018 \end{equation}
For our example (with \( j = 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.
The calculations are schematically as follows:
j ────────────────────┐ 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:
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 \):
\begin{equation} s = J − J_0 = J − 1721019 \end{equation}
As an example we'll calculate the date that corresponds to CJDN 2459695. Then
\[ s = J − J_0 = 2459695 − 1721019 = 738676 \]
Transformation 2 deduces from the running day number \( s \) the year number \( j \) and the calculation day number \( d_1 \) since the first day of the year:
\begin{align} ω_1 \| = gs + g\dparen{\sum_{r_i \gt 0} r_i} − \dparen{\sum_i γ_ir_it_i} − 1 \notag \\ \| = 19s + 19×31 − (1×30×2 + 1×1×18) = 19 s + 511 \\ α_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} \\ j \| = α_1 + \dfloorratio{δ_2}{q + \sum_{r_i \gt 0} r_1} = α_1 + \dfloorratio{δ_1}{385} \notag \\ d_1 \| = s − 354j − 30 \dfloorratio{7j + 2}{19} − \dfloorratio{4j + 18}{19} \end{align}
For our example we find
\begin{align*} \\ ω_1 \| = 19s + 511 = 19×738676 + 511 = 14035355 \\ α_1 \| = \dfloorratio{ω_1}{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 \\ j \| = α_1 + \dfloorratio{δ_1}{385} = 2022 + \dfloorratio{112}{385} = 2022 \\ d_1 \| = s − 354j − 30 \dfloorratio{7j + 2}{19} − \dfloorratio{4j + 18}{19} = 112 \end{align*}
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(gd_1 + g − t − 1, f) = \Div(13d_1 + 13 − 7 − 1, 384) \notag \\ \| = \Div(13d_1 + 5, 384) \\ d_0 \| = \dfloorratio{ω_2}{g} = \dfloorratio{ω_2}{13} \end{align}
For our example we find
\begin{align*} \{ m_0, ω_2 \} \| = \Div(13d_1 + 5, 384) = \Div(13×112 + 5, 384) \\ \| = \Div(1461, 384) = \{ 3, 309 \} \\ d_0 \| = \dfloorratio{ω_2}{13} = \dfloorratio{309}{13} = 23 \end{align*}
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} \\ j \| = α_1 + \dfloorratio{δ_1}{385} \notag \\ d_1 \| = s − 354j − 30 \dfloorratio{7j + 2}{19} − \dfloorratio{4j + 18}{19} \\ \{ m, ω_2 \} \| = \Div(13d_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 \\ j \| = α_1 + \dfloorratio{δ_1}{385} = 2022 + \dfloorratio{112}{385} = 2022 \\ d_1 \| = s − 354j − 30 \dfloorratio{7j + 2}{19} − \dfloorratio{4j + 18}{19} = 112 \\ \{ m, ω_2 \} \| = \Div(13d_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.
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:
\({j}\) | D | |
---|---|---|
2019 | 2018-12-08 | 8 |
2020 | 2019-12-27 | 27 |
2021 | 2020-12-15 | 15 |
2022 | 2022-01-03 | 34 |
2023 | 2022-12-23 | 23 |
2024 | 2023-12-13 | 13 |
2025 | 2024-12-31 | 31 |
2026 | 2025-12-20 | 20 |
2027 | 2026-12-09 | 9 |
2028 | 2027-12-28 | 28 |
2029 | 2028-12-17 | 17 |
2030 | 2030-01-05 | 5 |
2031 | 2030-12-25 | 25 |
2032 | 2031-12-14 | 14 |
2033 | 2033-01-01 | 32 |
2034 | 2033-12-22 | 22 |
2035 | 2034-12-11 | 11 |
2036 | 2035-12-30 | 30 |
2037 | 2036-12-18 | 18 |
2038 | 2037-12-08 | 8 |
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 \( r \) (as in equation \eqref{eq:r}).
Table 1: Leap Years in Islamic Calendar
Type | Leap Years | \({r}\) | 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 \( j \) is
\begin{equation} N = \dfloorratio{11j + r}{30} \end{equation}
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 Sha`ban 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 | \({r}\) | \({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 |
\begin{align} x_2 \| = j − 1 \\ x_1 \| = m − 1 \\ z_1 \| = d − 1 \\ c_1 \| = \dfloorratio{325x_1 + 5}{11} \\ y_1 \| = c_1 + z_1 \\ z_2 \| = y_1 \\ c_2 \| = \dfloorratio{10631x_2 + r}{30} \\ y_2 \| = c_2 + z_2 \\ J \| = y_2 + J_0 \end{align}
For example, which CJDN corresponds to the Islamic date of 29 Sha`ban 1432 according to calendar type IIc? Then
\begin{align*} j \| = 1432 \\ m \| = 8 \\ d \| = 29 \\ r \| = 14 \\ J_0 \| = 1\ 948 \440 \\ x_2 \| = 1432 − 1 = 1431 \\ x_1 \| = 8 − 1 = 7 \\ z_1 \| = 29 − 1 = 28 \\ c_1 \| = \dfloorratio{325×7 + 5}{11} = \dfloorratio{2280}{11} = 207 \\ y_1 \| = 207 + 28 = 235 \\ z_2 \| = 235 \\ c_2 \| = \dfloorratio{10631×1431 + 14}{30} = \dfloorratio{15\ 212\ 975}{30} = 507\ 099 \\ y_2 \| = 507\ 099 + 235 = 507\ 334 \\ J \| = 507\ 334 + 1\ 948\ 440 = 2\ 455\ 774 \end{align*}
This can be condensed to
\begin{equation} J = \dfloorratio{10631j − 10631 + r}{30} + \dfloorratio{325m − 320}{11} + d − 1 + J_0 \end{equation}
i.e.,
Ia | \({J = \dfloorratio{10631j − 10616}{30} + \dfloorratio{325m − 320}{11} + d + 1\ 948\ 438}\) |
Ic | \({J = \dfloorratio{10631j − 10616}{30} + \dfloorratio{325m − 320}{11} + d + 1\ 948\ 439}\) |
IIa | \({J = \dfloorratio{10631j − 10617}{30} + \dfloorratio{325m − 320}{11} + d + 1\ 948\ 438}\) |
IIc | \({J = \dfloorratio{10631j − 10617}{30} + \dfloorratio{325m − 320}{11} + d + 1\ 948\ 439}\) |
IIIa | \({J = \dfloorratio{10631j − 10620}{30} + \dfloorratio{325m − 320}{11} + d + 1\ 948\ 438}\) |
IIIc | \({J = \dfloorratio{10631j − 10620}{30} + \dfloorratio{325m − 320}{11} + d + 1\ 948\ 439}\) |
IVa | \({J = \dfloorratio{10631j − 10622}{30} + \dfloorratio{325m − 320}{11} + d + 1\ 948\ 438}\) |
IVc | \({J = \dfloorratio{10631j − 10622}{30} + \dfloorratio{325m − 320}{11} + d + 1\ 948\ 439}\) |
For the same Islamic date as before we now find
\begin{align*} J \| = \dfloorratio{10631×1432 − 10617}{30} + \dfloorratio{325×8 − 320}{11} + 29 + 1\ 948\ 439 \\ \| = \dfloorratio{15\ 212\ 975}{30} + \dfloorratio{2280}{11} + 29 + 1\ 948\ 439 \\ \| = 507\ 099 + 207 + 29 + 1\ 948\ 439 = 2\ 455\ 774 \end{align*}
which is the same answer as before.
In the opposite direction we find:
\begin{align} y_2 \| = J − J_0 \\ \{x_2, r_2\} \| = \Div(30y_2 + 29 − r, 10631) \\ z_2 \| = \dfloorratio{r_2}{30} \\ y_1 \| = z_2 \\ \{x_1, r_1\} \| = \Div(11y_1 + 5, 325) \\ z_1 \| = \dfloorratio{r_1}{11} \\ j \| = x_2 + 1 \\ m \| = x_1 + 1 \\ d \| = z_1 + 1 \end{align}
For example, which Islamic date (calendar type IIc) corresponds to CJDN 2 455 774? Then \( J = 2 455 774 \), \( r = 14 \), \( J_0 = 1 948 440 \), and then
\begin{align*} y_2 \| = 2\ 455\ 774 − 1\ 948\ 440 = 507\ 334 \\ \{x_2, r_2\} \| = \Div(30×507\ 334 + 15, 10631) = \Div(15\ 220\ 035, 10631) = \{1431, 7074\} \\ z_2 \| = \dfloorratio{7074}{30} = 235 \\ y_1 \| = 235 \\ \{x_1, r_1\} \| = \Div(11×235 + 5, 325) = \Div(2590, 325) = \{7, 315\} \\ z_1 \| = \dfloorratio{315}{11} = 28 \\ j \| = 1432 \\ m \| = 8 \\ d \| = 29 \end{align*}
which means 29 Sha`ban 1432.
This can be condensed to
\begin{align} \{x_2, r_2\} \| = \Div(30(J − J_0) + 29 − r, 10631) \\ \{x_1, r_1\} \| = \Div\left( 11\dfloorratio{r_2}{30} + 5, 325 \right) \\ j \| = x_2 + 1 \\ m \| = x_1 + 1 \\ d \| = \dfloorratio{r_1}{11} + 1 \end{align}
For example, which Islamic date (calendar type IIc) corresponds to CJDN 2 455 774? Then \( J = 2\ 455\ 774 \), \( r = 14 \), \( J_0 = 1\ 948\ 440 \), and then
\begin{align*} \{x_2, r_2\} \| = \Div(30×(2\ 455\ 774 − 1\ 948\ 440) + 29 − 14, 10631) \\ \| = \Div(15\ 220\ 035, 10631) = \{1431, 7074\} \\ \{x_1, r_1\} \| = \Div\left( 11×\dfloorratio{7074}{30} + 5, 325 \right) \\ \| = \Div(11×235 + 5, 325) = \Div(2590, 325) = \{7, 315\} \\ j \| = 1431 + 1 = 1432 \\ m \| = 7 + 1 = 8 \\ d \| = \dfloorratio{315}{11} + 1 = 29 \end{align*}
which means 29 Sha`ban 1432, which is the same as in the previous example.
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.
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).
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 \| = ⌊J + 65⌉_{365} \\ h_m \| = \dfloorratio{H}{20} + 1 \\ h_d \| = ⌊H⌉_{20} \end{align}
For example, which Haab date corresponds to 15 December 1965 = CJDN 2 439 110? Then \( J = 2\ 439\ 110 \) and
\begin{align*} H \| = ⌊J + 65⌉_{365} = ⌊2\ 439\ 175⌉_{365} = 245 \\ h_m \| = \dfloorratio{245}{20} + 1 = 13 \\ h_d \| = ⌊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\} \).
To translate a Haab date \( \{h_d,h_m\} \) to a CJDN we first calculate \( H \).
\begin{equation} H = h_d + 20×(h_m − 1) \end{equation}
We know that
\begin{equation} J ≡ H − 65 \pmod{365} \end{equation}
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 \):
\begin{equation} J = J_0 − ⌊J_0 − H + 65⌉_{365} \end{equation}
Which CJDN corresponds to Haab date \( \{5,13\} \)? Then \( h_d = 5 \), \( h_m = 13 \), so \( H = 5 + 20×(13 − 1) = 245 \) and then \( J ≡ 245 − 65 ≡ 180 \pmod{365} \). That fits the original \( J \) that we began with in the previous example (2 439 110), because \( 2\ 439\ 110 = 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 = 2\ 439\ 126 \) (which corresponds to 31 December 1965), using equation \eqref{eq:laatste}. We find
\begin{align*} J \| = J_0 − ⌊J_0 − 180⌉_{365} \\ \| = 2\ 439\ 126 − ⌊2\ 438\ 946⌉_{365} \\ \| = 2\ 439\ 126 − 16 = 2\ 439\ 110 \end{align*}
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.
We translate CJDN \( J \) to a Tzolkin date as follows:
\begin{align} t_t \| = ⌊J + 5⌉_{13} + 1 \label{eq:trecena2} \\ t_v \| = ⌊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 \| = ⌊2\ 439\ 110 + 5⌉_{13} + 1 = 3 + 1 = 4 \\ t_v \| = ⌊2\ 439\ 110 + 16⌉_{20} + 1 = 6 + 1 = 7 \end{align*}
so that date is \( \{4,7\} \).
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 12.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} \| \begin{split} C_2 \| = C_1 (1 − r_2Q_1) + (x_2 − a_2) r_2Q_1 \\ \| = (t_t − 6)×(1 − 17×13) + (t_v − 17)×17×13 \\ \| = 221 t_v − 220 t_t − 2437 \end{split} \\ P_2 \| = p_2Q_1 = 20×13 = 260 \end{align}
so the solution is
\begin{equation} J ≡ 221 t_v − 220 t_t − 2437 = −39 t_v + 40 t_t − 97 \pmod{260} \end{equation}
Which days correspond to Tzolkin date \( \{4,7\} \)? Those days have \( J ≡ −39×7 + 40×4 − 97 ≡ 50 \pmod{260} \). That fits with \( J = 2\ 439\ 110 \) because \( 2\ 439\ 110 = 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:
\begin{equation} J = J_0 − ((J_0 − 40 t_t + 39 t_v + 97) \bmod 260) \end{equation}
The last Tzolkin date \( \{4,7\} \) that occurs on or before 31 December 1965 (= CJDN 2 439 126) is \( J = 2\ 439\ 126 − ⌊2439126 − 50⌉_{260} = 2\ 439\ 126 − 16 = 2\ 439\ 110 \).
For the number of days \( T \) since the last \( \{1,1\} \) we have
\begin{equation} \begin{split} T \| ≡ 40 (t_t − 1) − 39 (t_v − 1) \\ \| ≡ 40 t_t − 39 t_v − 1 \\ \| ≡ 40 t_t + 221 t_v − 1 \pmod{260} \end{split} \end{equation}
so
\begin{equation} T ≡ ⌊40 t_t + 221 t_v − 1⌉_{260} \end{equation}
For CJDN 2 439 110 (with \( \{t_t,t_v\} = \{4,7\} \)) we find \( T = ⌊40×4 + 221×7 − 1⌉_{260} = ⌊1706⌉_{260} = 146 \), so the last day before then that had \( \{1,1\} \) was CJDN \( J = 2\ 439\ 110 − 146 = 2\ 438\ 964 \), and that fits, because \( t_t = ⌊J + 5⌉_{13} + 1 = ⌊2\ 438\ 969⌉_{13} + 1 = 1 \) and \( t_v = ⌊J + 16⌉_{20} + 1 = ⌊2\ 438\ 980⌉_{20} + 1 = 1 \).
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 12.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} \| \begin{split} C_2 \| = C_1 (1 − r_2Q_1) + (x_2 − a_2) r_2Q_1 \\ \| = (H − 65)×(1 − 5×73) + (T − 96)×5×73 \\ \| = 365 T − 364 H − 11380 \end{split} \\ P_2 \| = p_2Q_1 = 365×52 = 18980 \end{align}
so the solution is
\begin{equation} J ≡ 365 T − 364 H − 11380 ≡ 365 T − 364 H + 7600 \pmod{18980} \end{equation}
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 = 2\ 439\ 110 \) that we began with, because \( 2\ 439\ 110 = 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.
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 = 584\ 283 \) (6 September −3113 in the Julian calendar).
Translating CJDN \( J \) to Long Count \( L ≡ l_5.l_4.l_3.l_2.l_1 \) goes as follows:
\begin{align} y \| = J − J_0 \\ \{l_5, r_5\} \| = \Div(y, 144000) \\ \{l_4, r_4\} \| = \Div(r_5, 7200) \\ \{l_3, r_3\} \| = \Div(r_4, 360) \\ \{l_2, l_1\} \| = \Div(r_3, 20) \end{align}
and translating a Long Count to CJDN goes as follows:
\begin{equation} \begin{split} J \| = l_1 + 20×(l_2 + 18×(l_3 + 20×(l_4 + 20×l_5))) + J_0 \\ \| = l_1 + 20×l_2 + 360×l_3 + 7200×l_4 + 144000×l_5 \end{split} \end{equation}
Which Long Count \( L \) corresponds to CJDN \( J = 2\ 439\ 110 \)? Then
\begin{align*} y \| = J − J_0 = 2\ 439\ 110 − 584\ 283 = 1\ 854\ 827 \\ \{l_5, r_5\} \| = \Div(1\ 854\ 827, 144\ 000) = \{12, 126\ 827\} \\ \{l_4, r_4\} \| = \Div(126\ 827, 7200) = \{17, 4427\} \\ \{l_3, r_3\} \| = \Div(4427, 360) = \{12, 107\} \\ \{l_2, l_1\} \| = \Div(107, 20) = \{5, 7\} \end{align*}
The answer is \( L = 12.17.12.5.7 \).
And now in the opposite direction: \( J = 7 + 20×(5 + 18×(12 + 20×(17 + 20×12))) + 584\ 283 = 2\ 439\ 110 \).
We are not limited to using straight lines. The method that we derived above for using a straight line can be expanded to more complicated functions. If we have functions \( v(x) \) and \( w(y) \) such that
\begin{align*} v'(x) \| ≥ 1 \\ v(w(x)) \| = w(v(x)) = x \end{align*}
(so \( v \) and \( w \) are each other's inverse functions) then the calendar formulas become
\begin{align} y \| = ⌊v(x)⌋ + z \\ x \| = ⌈w(y + 1)⌉ − 1 = −⌊−w(y + 1)⌋ − 1 \end{align}
We get the case of the straight line if we set \( v(x) = px = fx/g \); to this corresponds \( w(y) = y/p = gy/f \).
The derivation goes similar to the case with the straight line.
With a curved line we can make a calendar in which the average length of the month or the year does not stay constant in the long run. In this way we can keep the calendar better in step with the Sun and the Moon than for a calendar that has fixed average lengths.
A practical problem for this is that not every function \( v(x) \) has a (reasonably simple to calculate) corresponding inverse function \( w(y) \). You cannot use just any \( v(x) \).
If you use a function \( v(x) \) that (for whole numbers \( x \)) does not always yield a whole number or a ratio, or if you do the calculations with floating-point numbers, then you should worry about round-off errors. If you calculator or program makes a round-off error and yields \( v(x) = 6.9999 \) instead of \( v(x) = 7.0000 \), then you get \( ⌊v(x)⌋ = 6 \) instead of \( ⌊v(x)⌋ = 7 \), and so a wrong day number. To prevent round-off errors, you should pick a function \( v(x) \) that allows calculating with ratios and that has an inverse function \( w(y) \) that also allows calculating with ratios, so that all of the calculations can be done with whole numbers only (separately in numerators and denominators).
The above-mentioned algorithms are in principle valid for all days, but computer programs usually work with numbers of a limited size, so in practice the algorithms won't work anymore for dates that are too far from the begin date of the calendar, or too far from CJDN 0. If the computer program works with whole numbers of \( n \) bits wide, then the greatest number that it can handle is equal to \( w = 2^{n − 1} \). If one or more of the intermediate results of the algorithms gets greater than \( w \) (in positive or negative direction), then they won't fit anymore and then the program yields wrong results.
For translating a calendar date into a running day number, that running day number is usually the greatest (intermediate) result, so algorithms that translate a calendar date into a running day number will give valid results in computer programs if the running day number remains clearly less (in absolute sense) than \( w \). The number of days since or before CJDN 0 must also remain less than \( w \). The value of \( w \) for oft-used number widths is shown in table 2.
\({n}\) | \({w}\) | \({w/365.25}\) |
---|---|---|
2 | 32 768 | 89 |
4 | 2 147 483 648 | 5.8 × 106 |
8 | 9 223 372 036 854 775 808 | 2.5 × 1016 |
For example, if the computer program uses numbers of 32 bits wide, then it can translate calendar dates into running day numbers for dates up to at least 5 million years from the beginning of the calendar (both to the future and to the past).
While translating a running day number into a calendar date, the running day number \( y \) (since the beginning of the calendar) is entered into a formula like equation \eqref{eq:ynaarxr}, i.e., multiplied by a factor \( g \) (a whole number greater than 1), then added to a fixed (usually small) whole number, and then divided by a divisor \( f \) (a whole number greater than \( g \)). We can indicate that calculation schematically like this:
\begin{equation} x = \dfloorratio{gy + t}{f} \end{equation}
If we do the calculations in the listed order, then we get an intermediate result \( gy + t \) which is much greater than \( y \) itself. Intermediate results greater than \( w \) give trouble, so to avoid trouble we'd need roughly \( |gy| \lt w \), so \( |y| \lt w/g \), which is much less than \( w \) itself.
For example, the "CJDN → Gregorian (3)" algorithm has \( g = 4800 \), so then we'd need \( |y| \lt w/4800 \). For numbers of 32 bits wide, this algorithm would be useful as long as approximately \( |y| \lt 447\ 392 \), i.e., for 447 392 days or 1224 years from the beginning of the calendar. This is far too small to cover the whole period since the end of prehistory.
Section 12.2 describes how we can rearrange the calculation to avoid this problem.
As an example we look at equation \eqref{eq:g3}, which we repeat here:
\begin{equation} x_2 = \dfloorratio{4800y_2 + 15793}{146\ 097} \end{equation}
Then \( g = 4800 \), \( t = 15793 \), \( f = 146\ 097 \). Suppose that \( y_2 = 730\ 000 \) (we calculate for a date that is 730 000 days, approximately 2000 years, after the beginning of the calendar) and \( n = 4 \) so \( w = 2^{31} = 2\ 147\ 483\ 648 \).
Then \( 4800y_2 + 15793 = 3\ 504\ 015\ 793 \), which is greater than \( w \), and \( 3504015793/146097 = 23984 + 25345/146097 \), so \( x_2 = 23984 \). If we calculate \( x_2 \) in this way then we get an intermediate result that is too great to fit into a number of 32 bits wide.
Now we use the alternative method. Then
\[ x_2 = 4800\dfloorratio{y_2}{146\ 097} + \dfloorratio{4800⌊y_2⌉_{146\ 097} + 15793}{146\ 097} \]
We find
\begin{align*} \dfloorratio{y_2}{146\ 097} \| = \dfloorratio{730\ 000}{146\ 097} = 4 \\ ⌊y_2⌉_{146097} \| = y_2 − 146\ 097\dfloorratio{y_2}{146\ 097} = 145\ 612 \\ x_2 \| = 4800×4 + \dfloorratio{4800×145\ 612 + 15793}{146\ 097} \\ \| = 19200 + \dfloorratio{698\ 953\ 393}{146\ 097} = 19200 + 4784 = 23984 \end{align*}
This gives the same end result as above, but now the greatest intermediate result was 698 953 393, which is less than \( w \).
With this alternative method, the greatest possible intermediate result for this calendar is equal to \( η = fg − f + t = f×(g − 1) + t = 4799×146\ 097 + 15793 = 701\ 135\ 296 \), which fits into a number of 32 bits wide.
With this alternative we can, by doing more calculations, translate running day numbers into calendar dates for about the same range of dates as the translation of calendar dates into running day numbers, if \( fg − f + t \lt w \).
Table 3 shows, for all algorithms described above, the relevant value of \( g \) and (approximately) the greatest allowed value of \( y \) (measured in days and years) for \( n \) equal to 16, 32, and 64 ― the width in bits of the most commonly used types of whole numbers in computer programs. This shows the limitations of the use of the algorithms if the alternative way of calculation that was discussed above is not used. The last columns shown \( t \), \( f \), the greatest possible intermediate result \( η \) (apart from \( y \)) if the alternative method is used, and the minimum width \( n_{min} \) in bits that is required for the alternative method to work well in the computer program.
Calendar | \({g}\) | \({y}\) | \({y/365.25}\) | \({t}\) | \({f}\) | \({η}\) | \({n_{min}}\) | ||||
---|---|---|---|---|---|---|---|---|---|---|---|
16 | 32 | 64 | 16 | 32 | 64 | ||||||
CJDN → Julian (1) | 4 | 8192 | 536 × 106 | 2305 × 1015 | 22 | 1 469 872 | 6313 × 1012 | 3 | 1 461 | 4 386 | 2 |
CJDN → Julian (2) | 48 | 682 | 44 × 106 | 192 × 1015 | 1 | 122 489 | 526 × 1012 | 109 | 1 461 | 68 776 | 3 |
CJDN → Gregorian (1) | 4 | 8192 | 536 × 106 | 2305 × 1015 | 22 | 1 469 872 | 6313 × 1012 | 3 | 146 097 | 438 294 | 2 |
CJDN → Gregorian (2) | 400 | 81 | 5 × 106 | 23 × 1015 | 0 | 14 698 | 63 × 1012 | 799 | 146 097 | 58 293 502 | 4 |
CJDN → Gregorian (3) | 4800 | 6 | 447392 | 1.9 × 1015 | 0 | 1 224 | 5 × 1012 | 15793 | 146 097 | 701 135 296 | 4 |
CJDN → Babylonian (1) | 235 | 139 | 9 × 106 | 39 × 1015 | 0 | 25 019 | 10 × 1012 | 234 | 6 940 | 1 624 194 | 3 |
CJDN → Babylonian (2) | 19 | 1724 | 113 × 106 | 485 × 1015 | 4 | 309 446 | 1329 × 1012 | 546 | 6 940 | 125 466 | 3 |
CJDN → Islamic | 30 | 1092 | 71 × 106 | 307 × 1015 | 3 | 195 983 | 841 × 1012 | 15 | 10 631 | 308 314 | 3 |
The "CJDN → Gregorian (3)" algorithm is, for whole numbers of 32 bits wide, valid for dates up to 1224 years from the beginning of the calendar. If you use that algorithm with that number width for dates near today, then you'll get wrong answers. How the answers are wrong depends on what your computer does with intermediate results that don't fit, and that can be different for each computer. If you want to use this algorithm in practice, then your computer program should either use whole numbers of 64 bits wide (then the algorithm is valid for about 5 000 000 000 000 years), or use whole numbers of 32 bits wide and also use the alternative method explained above (then the algorithm is valid for about 6 000 000 years).
Below is an algorithm (in pseudo-code) for calculating a running day number from a calendar date. The meaning of the various function arguments is:
date[i,j]
is a two-dimensional table, in which
i
selects the different calendar units (day, month, and
so on; there are n + 1
of them) and j
selects the different dates (there are t
of them).
q[i]
is the q
(base period) of calendar
level i
.
g[i]
is the g
(denominator) of calendar
level i
.
b[i]
indicates the calendar type (1 through 4) of
calendar level i
.
d[i][k]
is the d
(deviation from the
base period) of period k
(there are m
of
these) of calendar level i
.
h[i][k]
is the h
(numerator) of period
k
of calendar level i
.
s[i][k]
is the s
(pattern shift) of
period k
of calendar level i
.
y[j]
is the array of running day numbers.
The function DIV(x,y)
corresponds to
⌊x/y⌋
. The function MOD(x,y)
corresponds to x mod y = x − y*⌊x/y⌋
.
Here is the algorithm:
functionCAL2DAY
(date
,q
,g
,b
,d
,h
,s
) forj
from 0 throught − 1
: sety[j]
todate[0,j]
fori
from 0 throughn − 1
: ifMOD(b[i],2) = 1
then: setz[j]
toy[j]
setx[j]
todate[i+1,j]
else: setz[j]
todate[i+1,j]
setx[j]
toy[j]
setc[j]
toq[i]*x[j]
fork
from 0 throughm − 1
: setc[j]
toc[j] + MOD(h[i][k]*x[k,j] + s[i][k],g[i])*d[i][k]
sety[j]
toc[j] + z[j]
returny
end function
Here is a general algorithm (in pseudo-code) for calculating a calendar date from a running day number for all four calendar types, in similar fashion as above.
functionDAY2CAL
(day
,q
,g
,b
,d
,h
,s
) fori
from 0 throughn − 1
: setdp[i]
to0
sets2[i]
to0
setf[i]
toq[i]*g[i]
fork
from 0 throughm − 1
: setf[i]
tof[i] + d[i][k]*h[i][k]
ifd[i][k] gt 0
then: setdp[i]
todp[i] + d[i][k]
sets2[i]
tod[i][k]*s[i][k]
sets2[i]
tog[i]*dp[i] − s2[i] − 1
setzz[i]
toq[i] + dp[i]
forj
from 0 throught − 1
: sety[j]
today[j]
fori
fromn − 1
through 0: setx[j]
toDIV(g[i]*y[j] + s2[i],f[i])
setc[j]
toq[i]*x[j]
fork
from 0 throughm − 1
: setc[j]
toc[j] + DIV(h[i][k]*x[j] + s[i][k],g[i])*d[i,k]
setz[j]
toy[j] − c[j]
ifb[i] gt 2
then: whilez[j] lt 0
: setx[j]
tox[j] + DIV(z[j],zz[i])
setc[j]
toq[i]*x[j]
fork
from 0 throughm − 1
: setc[j]
toc[j] + DIV(h[i][k]*x[j] + s[i][k],g[i])*d[i,k]
setz[j]
toy[j] − c[j]
ifMOD(b[i],2) = 1
then: sety[j] = z[j]
setdate[i + 1,j] = x[j]
else: setdate[i + 1,j] = z[j]
sety[j] = x[j]
setdate[0,j] = y[j]
return date end function
The below table shows for each of the calendars which calendar units
in which order should be provided to CAL2DAY
as
date
, or that are returned by
DAY2CAL
. d, m, y, c
indicate day,
month, year, and century, respectively. A *
indicates
the use of calculation months/years/centuries where the calculation
year begins with the month of March.
Calendar | Order | |||
---|---|---|---|---|
Julian (1) | d | m* | y* | |
Julian (2) | y | m | d | |
Gregorian (1) | d | m* | y* | c* |
Gregorian (2) | d | m* | y* | |
Gregorian (3) | y | m | d | |
Babylonian (1) | y | m | d | |
Babylonian (2) | d | m | y | |
Islamic | d | m | y |
The parameters that are needed to use the above algorithms for the various calendars are shown in the following table.
Julian | Gregorian | Babylonian | Islamic | |||||
---|---|---|---|---|---|---|---|---|
(1) | (2) | (1) | (2) | (3) | (1) | (2) | ||
J₀ | 1721117.5 | 1721057.5 | 1721119.5 | 1721119.5 | 1721059.5 | 1607557.6 | 1607557.5 | 1948440 |
q₁, g₁, b₁ | 30, 5, 1 | 12, 1, 4 | 30, 5, 1 | 30, 5, 3 | 12, 1, 4 | 12, 19, 2 | 29, 13, 1 | 29, 11, 1 |
d, h, s | 1, 3, 2 | 1, 0, 0 | 1, 3, 2 | 1, 3, 2 | 1, 0, 0 | 1, 7, 13 | 1, 7, 3 | 1, 6, 5 |
q₂, g₂, b₂ | 365, 4, 1 | 30, 48, 4 | 365, 100, 1 | 365, 400, 3 | 30, 4800, 4 | 29, 235, 2 | 354, 19, 3 | 354, 30, 1 |
d, h, s | 1, 1, 0 | 1, 28, 20 | 1, 25, 0 | 1, 100, 0 | 1, 2800, 2000 | 1, 125, 0 | 30, 7, 1 | 1, 11, 14 |
−2, 4, 40 | −1, 4, 0 | −2, 400, 4000 | 1, 4, 12 | |||||
1, 1, 46 | 1, 1, 0 | 1, 100, 4600 | ||||||
−1, 4, 4792 | ||||||||
1, 1, 4798 | ||||||||
q₃, g₃, b₃ | 36524, 4, 1 | |||||||
d, h, s | 1, 1, 0 |
If you want to use this function for the Julian (1) calendar, then you should use the following function arguments:
q = [30, 365]
g = [5, 4]
b = [1, 1]
d = [1, 1]
h = [3, 1]
s = [2, 0]
q
should contain the following elements: [ [
1461, 4, 0 ], [ 153, 5, 4 ] ]
. x[0,j]
is then
the calculation year number, x[1,j]
is the month number
within the calculation year (March is month number 0!), and
x[2,j]
is the day number within the month (the first
day has day number 0!).
If you want to use the function for the Gregorian calendar, then
q
should contain: [ [ 146097, 4, 0 ], [ 36525,
100, 0 ], [ 153, 5, 4 ] ]
. Then x[0,j]
is the
calculation century number, x[1,j]
the calculation year
within the calculation century, x[2,j]
the month number
within the calculation year (March has month number 0!), and
x[3,j]
the day number within the month (the first day
has number 0!).
Here is pseudocode to calculate a CJDN from a Julian calendar date
x
:
function JUL2CJDN(x) setq
to[ [ 1461, 4, 0 ], [ 153, 5, 4 ] ]
fori
from 0 throughn−1
: setx[1,i]
tox[1,i] − 3
setx[2,i]
tox[2,i] − 1
ifx[1,i]
is less than 0: setx[1,i]
tox[1,i] + 12
setx[0,i]
tox[0,i] − 1
setd
toCAL2DAY(x,q)
forj
from 0 throught−1
: sety[j]
toy[j] + 1721118
returny
end function
Here is pseudocode to calculate a CJDN from a Gregorian calendar date
c
:
function GREG2CJDN(x) setq
to[ [ 146097, 4, 0 ], [ 36525, 100, 0 ], [ 153, 5, 4 ] ]
fori
from 0 throughn−1
: setx[1,i]
tox[1,i] − 3
ifx[1,i]
is less than 0: setx[1,i]
tox[1,i] + 12
setx[0,i]
tox[0,i] − 1
setb[0,i]
toDIV[x[0,i],100]
setb[1,i]
tox[0,i] − 100*b[0,i]
setb[2,i]
tox[1,i]
setb[3,i]
tox[2,i] − 1
setd
toCAL2DAY(b,q)
forj
from 0 throught−1
: sety[j]
toy[j] + 1721120
returny
end function
Here is pseudocode to calculate Julian calendar dates from CJDN
y
:
function CJDN2JUL(y) setq
to[ [ 1461, 4, 0 ], [ 153, 5, 4 ] ]
forj
from 0 throught−1
: sety[j]
toy[j] − 1721118
setc
toDAY2CAL(y,q)
fori
from 0 throughn−1
: setx[1,i]
tox[1,i] + 3
setx[2,i]
tox[2,i] + 1
ifx[1,i]
is greater than 12: setx[1,i]
tox[1,i] − 12
setx[0,i]
tox[0,i] + 1
returnx
end function
And here is pseudocode to calculate Gregorian calendar dates from CJDN
y
:
function CJDN2GREG(y) setq
to[ [ 146097, 4, 0 ], [ 36525, 100, 0 ], [ 153, 5, 4 ] ]
forj
from 0 throught−1
: sety[j]
toy[j] − 1721120
setb
toDAY2CAL(y,q)
fori
from 0 throughn−1
: setx[0,i]
to100*b[0,i] + b[1,i]
setx[1,i]
tob[2,i] + 3
setx[2,i]
tob[3,i] + 1
ifx[1,i]
is greater than 12: setx[1,i]
tox[1,i] − 12
setx[0,i]
tox[0,i] + 1
returnx
end function
If you want to know how many days there are between two dates, then you can calculate that exactly by subtracting the CJDNs of the two dates. If you are satisfied with a possible error of a few days, then you can also estimate it from the difference measured in calendar years, calendar months, and calendar days.
Such information (the number of calendar years, months, and days) is not sufficient to calculate the exact number of days for all calendars, because not every year contains the same number of days as every other year, and not every month contains the same number of days as every other month (in all calendars).
Let's assume that the second date is \( j \) calendar years and \( m \) calendar months and \( d \) calendar days later than the first date (both in the same calendar, the Gregorian Calendar or the Jewish Calendar or the administrative Islamic Calendar), where you just subtract the year number, month number, and day number of the second date from those of the first date (which must be later). The variable \( j \) may be positive or zero, but not negative. The variables \( m \) and \( d \) may be positive or zero or negative, but \( m \) must not correspond to more than one calendar year, and \( d \) must not correspond to more than one calendar month. For the Jewish calendar we define Tishri to be month number 1 and define Adar Ⅱ to belong to month number 6 together with Adar Ⅰ (so that month number 6 may contain up to 59 days). For the Egyptian calendar we count the last 5 days of the year as a 13th month. Then you can estimate the number \( n \) of days between those two dates using the formula
\begin{equation} n = ⌊a j + b m + c d⌋ \end{equation}
with \( a \), \( b \), and \( c \) from the following table:
\({a}\) | \({b}\) | \({c}\) | \({|Δ|_\text{max}}\) | \({σ}\) | \({p_0}\) | |
---|---|---|---|---|---|---|
Gregorian | 365.24 | 30.4 | 1 | 4 | 1.1 | 35 % |
Jewish | 365.25 | 31.0 | 0.9 | 37 | 12.9 | 3 % |
Islamic | 354.367 | 29.5 | 1 | 2 | 0.6 | 62 % |
Egyptian | 365 | 30 | 1 | 0 | 0 | 100 % |
The \( |Δ|_\text{max} \) from the table shows the greatest error (measured in days) that the formula for that calendar yields (based on 10,000 random test dates) for dates that are not more than 400 years apart. The \( σ \) shows the standard deviation (say, the average error, also measured in days). The \( p_0 \) shows the probability that the estimated number \( n \) of days between the two dates is exactly right.
It is clear that the Egyptian calendar is the most predictable one, because it yields the least mistakes (namely zero). Then comes the administrative Islamic calendar, then the Gregorian calendar (with more variation in the month lengths than the Islamic calendar has), en lastly the Jewish calendar (with variation in the number of months in the year).
An example: How many days are there between 2003-05-25 and 2017-01-17 in the three calendars? Those dates differ by 14 years, −4 months, and −8 days. In the Gregorian calendar this yields \( n = ⌊365.24×14 + 30.4×−4 − 8⌋ = ⌊4983.76⌋ = 4983 \) days. The real number of days between those two dates is 4986.
In the Jewish calendar this yields \( n = ⌊365.25×14 + 31.0×−4 + 0.9×−8⌋ = ⌊4982.3⌋ = 4983 \) days, which happens to be equal to the real number of days between those two dates in the Jewish calendar.
In the administrative Islamic calendar this yields \( n = ⌊354.367×14 + 29.5×−4 − 8⌋ = ⌊4835.138⌋ = 4835 \) days, which is equal to the real number of days between those two dates in the administrative Islamic calendar.
In the Egyptian calendar this yields \( n = ⌊365×14 + 30×−4 − 8⌋ = ⌊4982⌋ = 4982 \) days, which is equal to the real number of days between those two dates in the Egyptian calendar.
//aa.quae.nl/en/reken/juliaansedag.html;
Last updated: 2024-04-07