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.
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 < |x| and
(Eq. 1) q = ⌊y/x⌋
(Eq. 2) r = y mod x = y − x⌊y/x⌋
(Eq. 3) y = qx + r
The notation y mod x means: the non-negative remainder
from the division of y by x.
We find
(Eq. 4) y/x = ⌊y/x⌋ + ((y/x) mod 1) = ⌊y/x⌋ + (y mod x)/x
and if x = 1 then
(Eq. 5) y = ⌊y⌋ + (y mod 1)
The notation x ≡ y (mod 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 (mod 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 (mod n) and
p is a whole number, then also x + p×n ≡ y (mod
n), and p×x ≡ p×y (mod n), and also p×x
≡ p×y (mod p×n).
A well-known example of modular arithmetic is clock face arithmetic.
The face of a typical clock can show hours between 1 and 12. If you
see two pictures of a clock face and in the first picture it shows 3
o'clock and in the second picture it shows 7 o'clock, then the second
picture might have been made 4 hours after the first one, but also 4 +
12 = 16 hours later, or 4 + 10×12 hours = 5 days and 4 hours later, or
4 hours plus any desired multiple of 12 hours later (or earlier). If
t₁ is the time of the first picture and
t₂ is the time of the second picture (measured in hours
from a fixed moment), then all you know from the pictures is that
t₂ ≡ t₁ + 4 (mod 12). And if the clock shows
t hours now, then after y more hours it
will show (t + y) mod 12 hours.
Note the difference in notation: z = x mod y means
that z is equal to the remainder of dividing
x by y, and z ≡ x (mod
y) means that z is equal to x
except for an arbitrary multiple of y. If z = x
mod y then also z ≡ x (mod y), but the
opposite need not be true,
One algorithm to calculate a CJDN J from a Gregorian
date (calendar year j, calendar month m,
calendar day d) is:
(Eq. 6) c₀ = ⌊(m − 3)/12⌋
(Eq. 7) x₄ = j + c₀
(Eq. 8) x₃ = ⌊x₄/100⌋
(Eq. 9) x₂ = x₄ mod 100
(Eq. 10) x₁ = m − 12c₀ − 3
(Eq. 11) J = ⌊146097x₃/4⌋ + ⌊36525x₂/100⌋ + ⌊(153x₁ + 2)/5⌋ + d +
1721119
Here J₁ is the number of days from the beginning of
calculation year 0 until the beginning of the current
100-calculation-year-period, J₂ the number of days
since the beginning of the current 100-calculation-year-period, and
J₃ 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.
For example: what is the CJDN for 7 September 2010 on the Gregorian
calendar? Then j = 2010, m = 9, d = 7 so c₀ =
⌊(9 − 3)/12⌋ = 0, x₄ = 2010 + 0 = 2010, x₃ = ⌊2010⁄100⌋ = 20, x₂ =
2010 − 100×20 = 10, x₁ = 9 − 12×0 − 3 = 6 and then c₀ =
⌊(9 − 3)/12⌋ = 0, x₄ = 2010 + 0 = 2010, x₃ = ⌊2010⁄100⌋ = 20, x₂ =
2010 − 100×20 = 10, x₁ = 9 − 12×0 − 3 = 6 en daarmee J
= ⌊146097×20⁄4⌋ + ⌊36525×10⁄100⌋ + ⌊(153×6 + 2)/5⌋ + 7 + 1721119 =
730485 + 3652 + 184 + 7 + 1721119 = 2455447.
And here are the calculations for a few more dates:
| calendar date | c₀ | x₄ | x₃ | x₂ | x₁ | …x₃… | …x₂… | …x₁… | 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:
(Eq. 12) k₃ = 4×(J − 1721120) + 3
(Eq. 13) x₃ = ⌊k₃/146097⌋
(Eq. 14) k₂ = 100⌊(k₃ mod 146097)/4⌋ + 99
(Eq. 15) x₂ = ⌊k₂/36525⌋
(Eq. 16) x₁ = ⌊(5⌊(k₂ mod 36525)/100⌋ + 2)/153⌋
(Eq. 17) c₀ = ⌊(x₁ + 2)/12⌋
(Eq. 18) j = 100×x₃ + x₂ + c₀
(Eq. 19) m = x₁ − 12c₀ + 3
(Eq. 20) d = ⌊(k₁ mod 153)/5⌋ + 1
Here x₃ is the number of calculation centuries since
that time, x₂ the number of calculation years since
that time, and x₁ 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 k₃ =
4×(2452827 − 1721120) + 3 = 2926831, x₃ =
⌊2926831⁄146097⌋ = 20, k₂ = 100⌊(2926831 mod
146097)/4⌋ + 99 = 100⌊4891⁄4⌋ + 99 = 100×1222 + 99 = 122299,
x₂ = ⌊122299⁄36525⌋ = 3, x₁ = ⌊(5⌊(122299 mod
36525)/100⌋ + 2)/153⌋ = ⌊(5⌊12724⁄100⌋ + 2)/153⌋ = ⌊(5×127 + 2)/153⌋ =
⌊637⁄153⌋ = 4, and then c₀ = ⌊(4 + 2)/12⌋ = 0,
j = 100×20 + 3 + 0 = 2003, m = 4 − 12×0 + 3 =
7, d = 5 + 1 = 6. The date is July 6th, 2003.
And here are the calculations for the same dates as before.
J | x₃ | x₂ | x₁ | c₀ | 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 |
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:
(Eq. 21) c₀ = ⌊(m − 3)/12⌋
(Eq. 22) x₄ = j + c₀
(Eq. 23) x₃ = ⌊x₄/100⌋
(Eq. 24) x₂ = x₄ mod 100
(Eq. 25) x₁ = m − 12c₀ − 3
(Eq. 26) J = ⌊(328718x₃ + 6)/9⌋ + ⌊36525x₂/100⌋ + ⌊(153x₁ + 2)/5⌋ + d +
1721119
An algorithm to convert CJDN J to year
j, month m, day d in the
Milanković calendar is:
(Eq. 27) k₃ = 9×(J − 1721120) + 2
(Eq. 28) x₃ = ⌊k₃/328718⌋
(Eq. 29) k₂ = 100⌊(k₃ mod 328718)/9⌋ + 99
(Eq. 30) x₂ = ⌊k₂/36525⌋
(Eq. 31) x₁ = ⌊(5⌊(k₂ mod 36525)/100⌋ + 2)/153⌋
(Eq. 32) c₀ = ⌊(x₁ + 2)/12⌋
(Eq. 33) j = 100x₃ + x₂ + c₀
(Eq. 34) m = x₁ − 12c₀ + 3
(Eq. 35) d = ⌊(k₁ mod 153)/5⌋ + 1
The algorithm to calculate a CJDN J from a Julian date
(calendar year j, calendar month m,
calendar day d) is:
(Eq. 36) J₀ = 1721117
(Eq. 37) c₀ = ⌊(m − 3)/12⌋
(Eq. 38) J₁ = ⌊1461×(j + c₀)/4⌋
(Eq. 39) J₂ = ⌊(153m − 1836c₀ − 457)/5⌋
(Eq. 40) J = J₁ + J₂ + d + J₀ = ⌊1461×(j + c₀)/4⌋ + ⌊(153m − 1836c₀
− 457)/5⌋ + d + 1721117
Here J₁ is the number of days between the beginning of
calculation year 0 and the beginning of the current calculation year,
and J₂ the number of days between the beginning of the
current calculation year and the beginning of the current month.
For example: what is the CJDN for 7 September 2010 on the Julian
calendar? Then j = 2010, m = 9, d = 7 so c₀ =
⌊(9 − 3)/12⌋, J₁ = ⌊1461×(2010 + 0)/4⌋ =
734152, J₂ = ⌊(153×9 − 1836×0 − 457)/5⌋ = 184,
J = 734152 + 184 + 7 + 1721117 = 2455460.
And here are the calculations for a few more dates:
| calendar date | c₀ | J₁ | J₂ | 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:
(Eq. 41) y₂ = J − 1721118
(Eq. 42) k₂ = 4y₂ + 3
(Eq. 43) k₁ = 5⌊(k₂ mod 1461)/4⌋ + 2
(Eq. 44) x₁ = ⌊k₁/153⌋
(Eq. 45) c₀ = ⌊(x₁ + 2)/12⌋
(Eq. 46) j = ⌊k₂/1461⌋ + c₀
(Eq. 47) m = x₁ − 12c₀ + 3
(Eq. 48) d = ⌊(k₁ mod 153)/5⌋ + 1
Which Julian date corresponds to CJDN 2451893? Then J =
2451893 so y₂ = 2451893 − 1721118 = 730775,
k₂ = 4×730775 + 3 = 2923103, k₁ = 5⌊(2923103
mod 1461)/4⌋ + 2 = 5⌊1103⁄4⌋ + 2 = 5×275 + 2 = 1377,
x₁ = ⌊1377⁄153⌋ = 9, c₀ = ⌊(9 + 2)/12⌋ = ⌊11⁄12⌋
= 0, and j = ⌊2923103⁄1461⌋ + 0 = 2000 + 0 =
2000, m = 9 − 12×0 + 3 = 12, d = ⌊(1377
mod 153)/5⌋ + 1 = ⌊0⁄5⌋ + 1 = 1. The date is 1 December
2000.
And here are the calculations for the same dates as before.
J | y₂ | k₂ | k₁ | x₁ | c₀ | 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 |
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:
(Eq. 49) J = ⌊(10631j − 10617)/30⌋ + ⌊(325m − 320)/11⌋ + d +
1948439
For example, which CJDN J corresponds to the Islamic
date 29-08-1432? Then j = 1432, m = 8, d = 29, so
J = ⌊(10631×1432 − 10617)/30⌋ + ⌊(325×8 − 320)/11⌋ + 29 +
1948440 = ⌊15212975⁄30⌋ + ⌊2280⁄11⌋ + 29 + 1948440 = 507099 + 207 + 29
+ 1948439 = 2455774, so 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
J = ⌊(10631×1 − 10617)/30⌋ + ⌊(325×1 − 320)/11⌋ + 1 + 1948439 =
⌊14⁄30⌋ + ⌊5⁄11⌋ + 1 + 1948439 = 0 + 0 + 1 + 1948439 =
1948440, 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:
(Eq. 50) k₂ = 30×(J − 1948440) + 15
(Eq. 51) k₁ = 11⌊(k₂ mod 10631)/30⌋ + 5
(Eq. 52) j = ⌊k₂/10631⌋ + 1
(Eq. 53) m = ⌊k₁/325⌋ + 1
(Eq. 54) d = ⌊(k₁ mod 325)/11⌋ + 1
For example, which Islamic date corresponds to CJDN 2455774? Then
J = 2455774, and then k₂ = 30×(2455774 −
1948440) + 15 = 15220035, k₁ = 11×⌊(15220035 mod 10631)/30⌋ + 5 =
11×⌊7074⁄30⌋ + 5 = 11×235 + 5 = 2590, j = ⌊15220035⁄10631⌋ + 1 = 1431
+ 1 = 1432, m = ⌊2590⁄325⌋ + 1 = 7 + 1 = 8, d = ⌊(2590 mod 325)/11⌋ +
1 = ⌊315⁄11⌋ + 1 = 29, so j = 1432, m = 8, d =
29 which means 29 Sha`ban 1432.
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:
(Eq. 55) y₁ = ⌊(235j − 241)/19⌋ + m
(Eq. 56) J = ⌊6940y₁/235⌋ + d + 1607557
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 x₁ = 2, z₁ = 8, z₂ = 26 and then
c₁ = ⌊(235×2 + 13)/19⌋ = ⌊483⁄19⌋ = 25, x₂ = y₁
= 25 + 8 = 33, c₂ = ⌊6940×33⁄235⌋ = 974,
y₂ = 974 + 26 = 1000, J = 1000 + 1607558 =
1607658.
From CJDN J, we find the Babylonian year number
j, month number m, and day number
d as follows:
(Eq. 57) k₂ = 235×(J − 1607558) + 234
(Eq. 58) k₁ = 19⌊k₂/6940⌋ + 5
(Eq. 59) j = ⌊k₁/235⌋ + 1
(Eq. 60) m = ⌊(k₁ mod 235)/19⌋ + 1
(Eq. 61) d = ⌊(k₂ mod 6940)/235⌋ + 1
For example, which date in the Babylonian calendar corresponds to CJDN
1608558? Then J = 1608558, so k₂
= 235×(1608558 − 1607558) + 234 = 235234, k₁ = 19×⌊235234⁄6940⌋ + 5 =
19×33 + 5 = 632, so j = ⌊632⁄235⌋ + 1 = 3, m = ⌊(632
mod 235)/19⌋ + 1 = ⌊162⁄19⌋ + 1 = 9, d = ⌊(235234 mod 6940)/235⌋ + 1
= ⌊6214⁄235⌋ + 1 = 27, which means day 27 of month 9 of year
3.
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:
(Eq. 62) c₀ = ⌊(13 − m)/7⌋
(Eq. 63) x₁ = j − 1 + c₀
(Eq. 64) x₃ = m − 1
(Eq. 65) z₄ = d − 1
(Eq. 66) c₁(x₁) = ⌊(235x₁ + 1)/19⌋
(Eq. 67) q(x₁) = ⌊c₁(x₁)/1095⌋
(Eq. 68) r(x₁) = c₁(x₁) mod 1095
(Eq. 69) υ₁(x₁) = 32336q(x₁) + ⌊(15q(x₁) + 765433r(x₁) +
12084)/25920⌋
(Eq. 70) υ₂(x₁) = υ₁(x₁) + (⌊6×(υ₁(x₁) mod 7)/7⌋ mod 2)
Calculate in the same way also υ₂(x₁ + 1). Then
(Eq. 71) L₂(x₁) = υ₂(x₁ + 1) − υ₂(x₁)
(Eq. 72) L₂(x₁ − 1) = υ₂(x₁) − υ₂(x₁ − 1)
(Eq. 73) v₃ = 2(⌊(L₂(x₁) + 19)/15⌋ mod 2)
(Eq. 74) v₄ = ⌊(L₂(x₁ − 1) + 7)/15⌋ mod 2
(Eq. 75) c₂(x₁) = υ₂ + v₃ + v₄
Calculate in the same way also c₂(x₁ + 1) (which means
you need to calculate υ₂(x₁ + 2), too). Then
(Eq. 76) L = c₂(x₁ + 1) − c₂(x₁)
(Eq. 77) c₈ = ⌊(L + 7)/2⌋ mod 15
(Eq. 78) c₉ = −(⌊(385 − L)/2⌋ mod 15)
(Eq. 79) c₃ = ⌊(384×x₃ + 7)/13⌋ + c₈×⌊(x₃ + 4)/12⌋ + c₉×⌊(x₃ +
3)/12⌋
(Eq. 80) c₄(x₁,x₃) = c₂(x₁) + c₃(x₃)
(Eq. 81) J = J₀ − 177 + c₄(x₁,x₃) + z₄ = 347821 + c₂(x₁) + c₃ +
z₄
As an example, we'll calculate which CJDN corresponds to 18 Sivan
A.M. 4682. Then j = 4682, m = 3,
d = 18. And then
c₀ = ⌊(13 − m)/7⌋ = ⌊(13 − 3)/7⌋ = ⌊10⁄7⌋ = 1
x₁ = j − 1 + c₀ = 4682 − 1 + 1 = 4682
x₃ = m − 1 = 3 − 1 = 2
z₄ = d − 1 = 18 − 1 = 17
c₁(4681) = c₁(x₁ − 1) = ⌊(235×(x₁ − 1) + 1)/19⌋ = ⌊(235×4681 +
1)/19⌋ = ⌊1100036⁄19⌋ = 57896
c₁(4682) = c₁(x₁) = ⌊(235×x₁ + 1)/19⌋ = ⌊(235×4682 + 1)/19⌋ =
⌊(1100270 + 1)/19⌋ = ⌊1100271⁄19⌋ = 57909
c₁(4683) = c₁(x₁ + 1) = ⌊(235×(x₁ + 1) + 1)/19⌋ = ⌊(235×4683 +
1)/19⌋ = ⌊1100506⁄19⌋ = 57921
c₁(4684) = c₁(x₁ + 2) = ⌊(235×(x₁ + 2) + 1)/19⌋ = ⌊(235×4684 +
1)/19⌋ = ⌊1100741⁄19⌋ = 57933
q(4681) = q(x₁ − 1) = ⌊c₁(x₁ − 1)/1095⌋ = ⌊57896⁄1095⌋ =
52
r(4681) = r(x₁ − 1) = c₁(x₁ − 1) mod 1095 = 57896 mod 1095 =
956
υ₁(4681) = υ₁(x₁ − 1) = 32336×q(x₁ − 1) + ⌊(15×q(x₁ − 1) +
765433×r(x₁ − 1) + 12084)/25920⌋ = 32336×52 + ⌊(15×52 + 765433×956 +
12084)/25920⌋ = 1681472 + ⌊731766812⁄25920⌋ = 1681472 + 28231 =
1709703
υ₂(4681) = υ₂(x₁ − 1) = υ₁(x₁ − 1) + (⌊6×(υ₁(x₁ − 1) mod 7)/7⌋
mod 2) = 1709703 + (⌊6×(1709703 mod 7)/7⌋ mod 2) = 1709703 +
(⌊6×2⁄7⌋ mod 2) = 1709703 + (⌊12⁄7⌋ mod 2) = 1709703 + (1 mod 2) =
1709703 + 1 = 1709704
q(4682) = q(x₁) = ⌊c₁(x₁)/1095⌋ = ⌊57909⁄1095⌋ = 52
r(4682) = r(x₁) = c₁(x₁) mod 1095 = 57909 mod 1095 =
969
υ₁(4682) = υ₁(x₁) = 32336×q(x₁) + ⌊(15×q(x₁) + 765433×r(x₁) +
12084)/25920⌋ = 32336×52 + ⌊(15×52 + 765433×969 + 12084)/25920⌋ =
1681472 + ⌊741717441⁄25920⌋ = 1681472 + 28615 = 1710087
υ₂(4682) = υ₂(x₁) = υ₁(x₁) + (⌊6×(υ₁(x₁) mod 7)/7⌋ mod 2) =
1710087 + (⌊6×(1710087 mod 7)/7⌋ mod 2) = 1710087 + (⌊1⁄7⌋ mod 2) =
1710087 + (0 mod 2) = 1710087 + 0 = 1710087
q(4683) = q(x₁ + 1) = ⌊c₁(x₁ + 1)/1095⌋ = ⌊57921⁄1095⌋ =
52
r(4683) = r(x₁ + 1) = c₁(x₁ + 1) mod 1095 = 57921 mod 1095 =
981
υ₁(4683) = υ₁(x₁ + 1) = 32336×q(x₁ + 1) + ⌊(15×q(x₁ + 1) +
765433×r(x₁ + 1) + 12084))/25920⌋ = 332336×52 + ⌊(15×52 + 765433×981 +
12084)/25920⌋ = 17281472 + ⌊750902637⁄25920⌋ = 17281472 + 28970 =
17310442
υ₂(4683) = υ₂(x₁ + 1) = υ₁(x₁ + 1) + (⌊6×(υ₁(x₁ + 1) mod 7)/7⌋
mod 2) = 1710442 + (⌊6×(1710442 mod 7)/7⌋ mod 2) = 1710442 +
(⌊6×6⁄7⌋ mod 2) = 1710442 + (⌊36⁄7⌋ mod 2) = 1710442 + (5 mod 2) =
1710442 + 1 = 1710443
q(4684) = q(x₁ + 2) = ⌊c₁(x₁ + 2)/1095⌋ = ⌊57933⁄1095⌋ =
52
r(4684) = r(x₁ + 2) = c₁(x₁ + 2) mod 1095 = 57933 mod 1095 =
993
υ₁(4684) = υ₁(x₁ + 2) = 32336×q(x₁ + 2) + ⌊(15×q(x₁ + 2) +
765433×r(x₁ + 2) + 12084)/25920⌋ = 32336×52 + ⌊(15×52 + 765433×993 +
12084)/25920⌋ = 1681472 + ⌊760087833⁄25920⌋ = 1681472 + 29324 =
1710796
υ₂(4684) = υ₂(x₁ + 2) = υ₁(x₁ + 2) + (⌊6×(υ₁(x₁ + 2) mod 7)/7⌋
mod 2) = 1710796 + (⌊6×(1710796 mod 7)/7⌋ mod 2) = 1710796 +
(⌊6×3⁄7⌋ mod 2) = 1710796 + (⌊18⁄7⌋ mod 2) = 1710796 + (2 mod 2) =
1710796 + 0 = 1710796
L₂(4681) = L₂(x₁ − 1) = υ₂(x₁) − υ₂(x₁ − 1) = 1710087 − 1709704
= 383
L₂(4682) = L₂(x₁) = υ₂(x₁ + 1) − υ₂(x₁) = 1710443 − 1710087 =
356
L₂(4683) = L₂(x₁ + 1) = υ₂(x₁ + 2) − υ₂(x₁ + 1) = 1710796 −
1710443 = 353
v₃(4682) = v₃(x₁) = 2×(⌊(L₂(x₁) + 19)/15⌋ mod 2) = 2×(⌊(356 +
19)/15⌋ mod 2) = 2×(⌊375⁄15⌋ mod 2) = 2×(25 mod 2) = 2
v₄(4682) = v₄(x₁) = ⌊(L₂(x₁ − 1) + 7)/15⌋ mod 2 = ⌊(383 +
7)/15⌋ mod 2 = ⌊390⁄15⌋ mod 2 = 26 mod 2 = 0
c₂(4682) = c₂(x₁) = υ₂(x₁) + v₃(x₁) + v₄(x₁) = 1710087 + 2 + 0
= 1710089
v₃(4683) = v₃(x₁ + 1) = 2×(⌊(L₂(x₁ + 1) + 19)/15⌋ mod 2) =
2×(⌊(353 + 19)/15⌋ mod 2) = 2×(⌊372⁄15⌋ mod 2) = 2×(24 mod 2) =
0
v₄(4683) = v₄(x₁ + 1) = ⌊(L₂(x₁) + 7)/15⌋ mod 2 = ⌊(356 +
7)/15⌋ mod 2 = ⌊363⁄15⌋ mod 2 = 24 mod 2 = 0
c₂(4683) = c₂(x₁ + 1) = υ₂(x₁ + 1) + v₃(x₁ + 1) + v₄(x₁ + 1) =
1710443
L = y₂(x₁ + 1) − y₂(x₁) = 1710443 − 1710089 = 354
c₈ = ⌊(L + 7)/2⌋ mod 15 = ⌊(354 + 7)/2⌋ mod 15 = ⌊361⁄2⌋ mod
15 = 180 mod 15 = 0
c₉ = −(⌊(385 − L)/2⌋ mod 15) = −(⌊(385 − 354)/2⌋ mod 15) =
−(⌊31⁄2⌋ mod 15) = −(15 mod 15) = 0
c₃ = ⌊(384×x₃ + 7)/13⌋ + c₈×⌊(x₃ + 4)/12⌋ + c₉×⌊(x₃ + 3)/12⌋ =
⌊(384×2 + 7)/13⌋ + 0×⌊(2 + 4)/12⌋ + 0×⌊(2 + 3)/12⌋ = ⌊775⁄13⌋ + 0 + 0
= 59
c₄ = c₂ + c₃ = 1710089 + 59 = 1710148
J = J₀ − 177 + c₄ + z₄ = 347821 + 1710148 + 17 =
2057986
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:
(Eq. 82) y₄ = J − 347821
(Eq. 83) q = ⌊y₄/1447⌋
(Eq. 84) r = y₄ mod 1447
(Eq. 85) y₁′ = 49q + ⌊(23q + 25920r + 13835)/765433⌋
(Eq. 86) γ₁ = y₁′ + 1
(Eq. 87) ξ₁ = ⌊(19γ₁ + 17)/235⌋
(Eq. 88) μ₁ = γ₁ − ⌊(235ξ₁ + 1)/19⌋
Calculate c₄′ = c₄(ξ₁, μ₁) in the way described in the
previous section. Then
(Eq. 89) ζ₁ = y₄ − c₄′
(Eq. 90) γ₂ = γ₁ + ⌊ζ₁/33⌋
(Eq. 91) ξ₂ = ⌊(19γ₂ + 17)/235⌋
(Eq. 92) μ₂ = γ₂ − ⌊(235ξ₂ + 1)/19⌋
Calculate c₄′ = c₄(ξ₂, μ₂) in the way described in the
previous section. Then
(Eq. 93) ζ₂ = y₄ − c₄′
(Eq. 94) γ₃ = γ₂ + ⌊ζ₁/33⌋
(Eq. 95) x₁ = ξ₃ = ⌊(19γ₃ + 17)/235⌋
(Eq. 96) x₃ = μ₃ = γ₃ − ⌊(235ξ₃ + 1)/19⌋
Calculate c₄′ = c₄(ξ₃, μ₃) in the way described in the
previous section. Then
(Eq. 97) z₄ = ζ₃ = y₁ − c₄′
(Eq. 98) c = ⌊(12 − x₃)/7⌋
(Eq. 99) j = x₁ + 1 − c
(Eq. 100) m = x₃ + 1
(Eq. 101) d = z₄ + 1
For J = 2057986 we find
y₄ = J − 347821 = 2057986 − 347821 = 1710165
q = ⌊y₄/1447⌋ = ⌊1710165⁄1447⌋ = 1181
r = y₄ mod 1447 = 1710165 mod 1447 = 1258
y₁′ = 49q + ⌊(23q + 25920r + 13835)/765433⌋ = 49×1181 +
⌊(23×1181 + 25920×1258 + 13835)/765433⌋ = 57869 + ⌊32648358⁄765433⌋ =
57869 + 42 = 57911
γ₁ = y₁' + 1 = 57911 + 1 = 57912
ξ₁ = ⌊(19γ₁ + 17)/235⌋ = ⌊(19×57912 + 17)/235⌋ = ⌊1100345⁄235⌋
= 4682
μ₁ = γ₁ − ⌊(235ξ₁ + 1)/19⌋ = 57912 − ⌊(235×4682 + 1)/19⌋ =
57912 − ⌊1100271⁄19⌋ = 57912 − 57909 = 3
In the way described in the previous section we calculate that
c₄′ = c₄(ξ₁,μ₁) = c₄(4682,3) = 1710178
Then
ζ₁ = y₄ − c₄′ = 1710165 − 1710178 = −13
γ₂ = γ₁ + ⌊ζ₁/33⌋ = 57912 + ⌊−13⁄33⌋ = 57912 + −1 =
57911
ξ₂ = ⌊(19γ₂ + 17)/235⌋ = ⌊(19×57911 + 17)/235⌋ = ⌊1100326⁄235⌋
= 4682
μ₂ = γ₂ − ⌊(235ξ₂ + 1)/19⌋ = 57911 − ⌊(235×4682 + 1)/19⌋ =
57911 − ⌊1100271⁄19⌋ = 57911 − 57909 = 2
In the way described in the previous section we calculate that
c₄ = c₄(ξ₂,μ₂) = c₄(4682,2) = 1710148
Then
ζ₂ = y₄ − c₄′ = 1710165 − 1710148 = 17
γ₃ = γ₂ + ⌊ζ₂/33⌋ = 57911 + ⌊17⁄33⌋ = 57911 + 0 = 57911
Because in this example ζ₃ = ζ₂, also ξ₃ =
ξ₂, μ₃ = μ₂, c₄(ξ₃,μ₃) =
c₄(ξ₂,μ₂), and ζ₃ = ζ₂, so in this example you
need not calculate ξ₃, μ₃, c₄(ξ₃,μ₃), ζ₃ explicitly,
but you can still do so if that is more convenient.
x₁ = ξ₃ = ⌊(19γ₃ + 17)/235⌋ = ⌊(19×57911 + 17)/235⌋ =
⌊1100326⁄235⌋ = 4682
x₃ = μ₃ = γ₃ − ⌊(235ξ₃ + 1)/19⌋ = 57911 − ⌊(235×4682 + 1)/19⌋ =
57911 − ⌊1100271⁄19⌋ = 57911 − 57909 = 2
In the way described in the previous section we calculate that
c₄′ = c₄(ξ₃,μ₃) = c₄(4682,2) = 1710148
Then
z₄ = ζ₃ = y₄ − c₄′ = 1710165 − 1710148 = 17
c = ⌊(12 − x₃)/7⌋ = ⌊(12 − 2)/7⌋ = ⌊10⁄7⌋ = 1
j = x₁ + 1 − c = 4682 + 1 − 1 = 4682
m = x₃ + 1 = 2 + 1 = 3
d = z₄ + 1 = 17 + 1 = 18
so the desired date in the Jewish calendar is day 18 of month 3 (Sivan) of year 4682: 18 Sivan A.M. 4682.
We can derive many calendar formulas by finding straight lines that, with rounding, yield the correct results.
Many of the calendar calculations that are described below are of the type
(Eq. 102) y = ⌊(fx + t)/d⌋
(Eq. 103) e = (fx + t) mod d
where f, t, d are fixed whole numbers with 1
< f, d and |t| < d, and y, x,
e 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
102ff to
(Eq. 104) y = ⌊(fx + ⌊t/d⌋d + (t mod d))/d⌋ = ⌊t/d⌋ + ⌊(fx + (t mod
d))/d⌋
(Eq. 105) e = (fx + t) mod d = (fx + (t mod d)) mod d
where the second term of both equations has the same form as equation
102, if you rename t mod d to a new
t. Below, we assume that that has been done, which
means that |t| < d.
If f > d, then we can rewrite equation
102ff to
(Eq. 106) y = ⌊((⌊f/d⌋d + (f mod d))x + t)/d⌋ = ⌊f/d⌋x + ⌊((f mod d)x +
t)/d⌋
(Eq. 107) e = ((⌊f/d⌋d + (f mod d))x + t) mod d = ((f mod d)x + t)
mod d
Then |x| may be nearly as great as w/(f mod
d) before we run into trouble.
Equations 106ff again have the form of equations
102ff, if you rename f mod d to a new
f. Below, we assume that this has been done, so that
f < 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⌊x/d⌋ which is roughly equal
to y, and then apply a correction to get the real
y.
We can rewrite equation 102ff to
(Eq. 108) y = ⌊(fx + t)/d⌋ = ⌊(f(⌊x/d⌋d + (x mod d)) + t)/d⌋ = f⌊x/d⌋ +
⌊(f(x mod d) + t)/d⌋
(Eq. 109) e = (fx + t) mod d = (f(⌊x/d⌋d + (x mod d)) + t) mod d =
(f(x mod d) + t) mod d
Now the greatest intermediate result is no longer fx +
t, which can get infinitely large, but f×(x mod d) +
t, which cannot exceed fd.
For example, let d = 12345, f = 8432,
t = 871, and w = 231 = 2,147,483,648,
and suppose we want to calculate y, e for x =
300,000.
We use the detour of equation 108. We find ⌊x/d⌋ =
⌊300000⁄12345⌋ = 24, x mod d = 300000 mod 12345 =
3720, y = f⌊x/d⌋ + ⌊(f(x mod d) + t)/d⌋ = 8432×24 +
⌊(8432×3720 + 871)/12345⌋ = 202368 + ⌊31367911⁄12345⌋ = 202368 + 2540
= 204908, and e = 31367911 mod 12345 = 11611.
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 y = ⌊(fx + t)/d⌋ = ⌊(8432×300000 + 871)/12345⌋
= ⌊2529600871⁄12345⌋ = 204908 and e = 2529600871 mod
12345 = 11611, 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 fd can be much greater than
w even if d and f are
each much less than w. If fd must
remain less than w, then d and
f cannot both be greater than √w, which
is a lot less than w itself. For example, for 32-bit
numbers, w = 231 = 2,147,483,648 and √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 P and then calculate once
(Eq. 110) Q = ⌊fP/d⌋
(Eq. 111) R = fP mod d
so
(Eq. 112) fP = dQ + R
Then, for each desired x, calculate
(Eq. 113) q = ⌊x/P⌋
(Eq. 114) r = x mod P
so
(Eq. 115) x = qP + r
and then
(Eq. 116) y = ⌊(fx + t)/d⌋ = ⌊(fqP + fr + t)/d⌋ = ⌊(qdQ + qR + fr + t)/d⌋
= qQ + ⌊(qR + fr + t)/d⌋
(Eq. 117) e = (fx + t) mod d = (fqP + fr + t) mod d = (qdQ + qR + fr +
t) mod d = (qR + fr + t) mod d
Now the greatest intermediate result is qR + fr + t.
We know that r < P, so fr < fP.
To stay out of trouble we need |qR + fr + t| ≤ |q|R + fP + |t|
< w, so |⌊x/P⌋|R + fP + |t| ≤ |x|R/P + fP + |t| <
w so
(Eq. 118) |x| < X ≡ (w − fP − |t|)×P/R
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 be small, and
P must certainly be less than w/f,
because otherwise X ≤ 0.
|x| cannot exceed w, so all P,
R for which X ≥ w give the same greatest
possible range for x. Within that group, we prefer
small P, Q, R, because that makes for easier
calculations.
The smallest possible positive value of R is equal to
the greatest common divisor of d and f,
and the corresponding P, Q > 0 can be found using
the Extended Algorithm of Euclid ― or by trying all d
possibilities for P.
If that P = P₁, Q = Q₁, R = R₁ fit together, then
(Eq. 119) fP₁ − dQ₁ = R₁
Then also P = R₁P₁, Q = R₁Q₁, R₁ belong together.
It is not useful to allow P ≥ d, because otherwise the
greatest intermediate result can be as great or greater than fP
= fd which can become greater than w, because
if it couldn't exceed w then we could have used
equation 108 and would not need the current more
complicated method at all. We seek P < d.
If we must have kP₁ = P < d, then k <
d/P₁ and that can be quite small, and then there are only few
corresponding combinations of P, Q, R. Fortunately, we
can find additional good combinations.
If P₂ = P + md, then Q₂ = ⌊fP₂/d⌋ = ⌊(fP +
fmd)/d⌋ = ⌊fP/d⌋ + mf = Q + mf and R₂ = fP₂ − dQ₂ = fP
+ fmd − (dQ + dmf) = fP − dQ = R, so if we add or subtract a
multiple of d from P, then
Q shifts by a corresponding multiple of
f, and R remains the same. In
particular, we can take
(Eq. 120) P = kP₁ mod d
(Eq. 121) Q = kQ₁ mod f
(Eq. 122) R = kR₁
for k < ⌊d/R₁⌋ because kR < d.
For example, let d = 765433, f = 25920,
t = 13835, w = 231 = 2147483648. Then
w/f = 231/25920 = 82850, so we seek a P <
82850, and an R as small as possible.
The Extended Algorithm of Euclid (or a search) for this
d and f yields that 99902f −
3383d = 1, so if P = P₁ ≡ 99902 then Q =
Q₁ ≡ 3383 and R = R₁ = 1. Then also RP₁
mod d, RQ₁ mod f, R fit together. The following table shows
a couple of combinations for small R.
R | RP₁ mod d | RQ₁ mod f |
|---|---|---|
| 1 | 99902 | 3383 |
| 2 | 199804 | 6766 |
| 7 | 699314 | 23681 |
| 8 | 33783 | 1144 |
| 9 | 133685 | 4527 |
The next table shows the combinations with the greatest
X.
R | P | Q | X |
|---|---|---|---|
| 8 | 33783 | 1144 | 5.4 × 1012 |
| 16 | 67566 | 2288 | 1.7 × 1012 |
| 31 | 35230 | 1193 | 1.4 × 1012 |
| 54 | 36677 | 1242 | 8.1 × 1011 |
| 39 | 69013 | 2337 | 6.3 × 1011 |
All of these X are comfortably greater than w ≈
2.15 × 109. X ≥ w for 1498 values of
R between 8 and 20312. Within that group, 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 for x = 1710321. We
find q = ⌊x/P⌋ = ⌊1710321⁄1447⌋ = 1181, r = x
mod P = 1710321 mod 1447 = 1414, and then y = qQ +
⌊(qR + fr + t)/d⌋ = 1181×49 + ⌊(1181×23 + 25920×1414 + 13835)/765433⌋
= 57869 + ⌊36691878⁄765433⌋ = 57869 + 47 = 57916, e =
36691878 mod 765433 = 716527. The greatest intermediate
result is 36,691,878, which is considerablye less than
w.
Had we been allowed arbitrarily large intermediate results, then we'd
have found y = ⌊(fx + t)/d⌋ = ⌊(25920×1710321 + 13835)/765433⌋
= ⌊44331534155⁄765433⌋ = 57916, e = 44331534155 mod
765433 = 716527, 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 = 231 =
2147483648. Then w/f = 231/4800 ≈ 447392, so
we seek a P < 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 P₁ = −15188 mod d = 130909, Q₁ = 499,
R₁ = 3. For small R we find the following
combinations:
k | R | P | Q |
|---|---|---|---|
| 1 | 3 | 100533 | 1497 |
| 2 | 6 | 54969 | 2994 |
| 3 | 9 | 9405 | 4491 |
| 4 | 12 | 109938 | 1188 |
There are 8445 combinations for whih X > w. The
combinations with the smallest PQR are:
R | P | Q | PQR | X |
|---|---|---|---|---|
| 375 | 761 | 25 | 7.13 × 106 | 4.33 × 109 |
| 144 | 1461 | 48 | 1.01 × 107 | 2.16 × 1010 |
| 57 | 3622 | 119 | 2.46 × 107 | 1.33 × 1011 |
| 750 | 1522 | 50 | 5.71 × 107 | 4.31 × 109 |
| 27 | 9405 | 309 | 7.85 × 107 | 7.01 × 1011 |
We choose P = 761, then Q = 25 and
R = 375. We calculate y, e for x
= 731767. Then q = ⌊731767⁄761⌋ = 961, r = 731767 mod
761 = 446, y = 961×25 + ⌊(961×375 + 4800×446 + 15793)/146097⌋ = 24025
+ ⌊2516968⁄146097⌋ = 24025 + 17 = 24042, e = 2516968 mod 146097 =
33319. The greatest intermediate result is 2,516,968, which
is comfortably smaller than w. With the original
formula we'd have found y = ⌊(4800×731767 + 15793)/146097⌋ =
⌊3512497393⁄146097⌋ = 24042, e = 3512497393 mod 146097 =
33319, 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.
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.
In the simplest case, the average length of the month is equal to
p days, all months are either ⌊p⌋ or
⌈p⌉ = ⌊p⌋ + 1 days long, and the running day number
y depends on the month number x and the
day number z within the current month as follows:
(Eq. 123) y = c + z = ⌊px⌋ + z
where x, y, c, z are whole numbers, and 1 ≤ p
< ∞. The first month has x = 0 and the
first day of the month has z = 0, for easier
calculation.
We define
(Eq. 124) ψ = p − ⌊p⌋ = p mod 1
(Eq. 125) p = q + ψ
The fraction of all months that are long (contain q + 1
days) is equal to ψ. Then the length L
of month x is equal to
(Eq. 126) L = ⌊p×(x + 1)⌋ − ⌊px⌋ = q + ⌊ψx + ψ⌋ − ⌊ψx⌋
and month x is a long month if
(Eq. 127) G = ⌊ψx + ψ⌋ − ⌊ψx⌋
is equal to 1, and is a short month (with length q
days) if G = 0. The number of long months between
month 0 and the beginning of month x is equal to
(Eq. 128) N = ⌊ψx⌋
There is another long month whenever ⌊ψx⌋ has grown by
one; that is on average after
(Eq. 129) Q = 1/ψ
months, but Q is not always a whole number, so in
practice the number of months between two long months is equal to
either ⌊Q⌋ or ⌈Q⌉.
If p = 30.6, then we find for the beginning (z =
0) of the first couple of months:
x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
px | 0 | 30.6 | 61.2 | 91.8 | 122.4 | 153 | 183.6 | 214.2 | 244.8 | 275.4 | 306 |
c | 0 | 30 | 61 | 91 | 122 | 153 | 183 | 214 | 244 | 275 | 306 |
ψx | 0 | 0.6 | 1.2 | 1.8 | 2.4 | 3 | 3.6 | 4.2 | 4.8 | 5.4 | 6 |
⌊ψx⌋ | 0 | 0 | 1 | 1 | 2 | 3 | 3 | 4 | 4 | 5 | 6 |
G | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | |
L | 30 | 31 | 30 | 31 | 31 | 30 | 31 | 30 | 31 | 31 |
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.
Using equation 123, we can calculate running day number
y from calendar date x, z, but we also
want to go in the other direction. We derive the reverse formula.
From equation 123 and
(Eq. 130) px − 1 < ⌊px⌋ ≤ px
follows
(Eq. 131) px + z − 1 < y ≤ px + z
(Eq. 132) px + z < y + 1 ≤ px + 1 + z
(Eq. 133) x + z/p < (y + 1)/p ≤ x + (z + 1)/p
If z = 0 then
(Eq. 134) x < (y + 1)/p ≤ x + (1/p)
x is a whole number, and p is greater
than 1 but finite, so
(Eq. 135) x < ⌈(y + 1)/p⌉ ≤ ⌈x + (1/p)⌉ = x + 1
(Eq. 136) x − 1 < x₀ ≝ ⌈(y + 1)/p⌉ − 1 ≤ x
The only value for x₀ that satisfies these inequalities
is x₀ = x, so the formulas to calculate x,
z from y are
(Eq. 137) x = ⌈(y + 1)/p⌉ − 1
(Eq. 138) z = y − c = y − ⌊px⌋
The first day of month x' (with z = 0)
has y = y' ≝ ⌊px'⌋. The day before that one has day
number y = y' − 1 = ⌊px'⌋ − 1. Equation 137
then yields
(Eq. 139) x = ⌈⌊px'⌋/p⌉ − 1 = ⌈(px' − δ)/p⌉ − 1 = ⌈x' − δ/p⌉ − 1 = x' −
1
with
(Eq. 140) δ = px' − ⌊px'⌋, 0 ≤ δ < 1
so equation 137 puts the day that precedes day z =
0 of month x = x' in month x = x' −
1 where it belongs. The transition from one month to the next
month lies just before z = 0, where it should be. This
shows that equation 137 is correct for all days.
With the same calendar as before we now go in the opposite direction.
Which calendar date x, z goes with running day number
y = 122? Then (from equation 137) x =
⌈(122 + 1)/30.6⌉ − 1 = ⌈123⁄30.6⌉ − 1 = ⌈4.0196...⌉ − 1 = 5 − 1 =
4 and z = 122 − ⌊30.6×4⌋ = 122 − ⌊122.8⌋ = 122 − 122 =
0, so running day number y = 122 corresponds to
month x = 4 and day number z = 0 within
that month.
And what about the preceding day? Then y = 121 so
x = ⌈(121 + 1)/30.6⌉ − 1 = ⌈122⁄30.6⌉ − 1 = ⌈3.9869...⌉ − 1 = 4
− 1 = 3 and z = 121 − ⌊30.6×3⌋ = 121 − ⌊91.8⌋ = 121 −
91 = 30, so running day number y = 121
corresponds to month x = 3 and day z =
30 within that month.
Calculating machines often work with a limited number of decimals
behind the decimal separator, so you can get into trouble with round-off
errors. If (y + 1)/p = 6.99999999998 but because of a
very small round-off error your calculating machine thinks that
(y + 1)/p = 7.00000000001, then your calculating
machine thinks that ⌈(y + 1)/p⌉ − 1 = 7 rather than 6,
and then you find the wrong month.
If the average length p is a ratio (of whole numbers),
then we can avoid such round-off errors by rewriting the formulas
based on ratios. We define
(Eq. 141) p ≝ f/g
(Eq. 142) ψ ≝ h/g
with f, g, h whole numbers (f, g greater
than zero, h greater or equal to zero). Then we find
(Eq. 143) y = c + z = ⌊px⌋ + z = ⌊fx/g⌋ + z
(Eq. 144) G = ⌊ψx + ψ⌋ − ⌊ψx⌋ = ⌊h×(x + 1)/g⌋ − ⌊hx/g⌋
(Eq. 145) x = ⌈(y + 1)/p⌉ − 1 = ⌈(y + 1)×g/f⌉ − 1 = ⌈(yg + g − f)/f⌉ =
⌊(yg + g − 1)/f⌋
(Eq. 146) z = y − c = y − ⌊px⌋ = y − ⌊fx/g⌋
because
(Eq. 147) ⌈n/m⌉ = ⌊(n + m − 1)/m⌋
for whole numbers n, m with m not equal
to 0. Now you can do all calculations with ratios, which have no
numbers after the decimal separator and hence no round-off errors.
We can simplify the calculation of z. Let
(Eq. 148) k = yg + g − 1
and divide k by f, yielding quotient
x and remainder r:
(Eq. 149) yg + g − 1 = k = fx + r
(Eq. 150) x = ⌊k/f⌋
(Eq. 151) r = k mod f
Then
(Eq. 152) z = y − ⌊fx/g⌋ = y − ⌊(yg + g − 1 − r)/g⌋ = y − ⌊y + 1 − (1 +
r)/g⌋ = y − (y + 1) − ⌊−(1 + r)/g⌋ = −1 − ⌊−(r + 1)/g⌋ = −1 + ⌈(r +
1)/g⌉ = −1 + ⌊(r + 1 + g − 1)/g⌋ = ⌊r/g⌋ = ⌊(k mod f)/g⌋
%ignore>
For the same calendar as before we have p = 30.6 =
153⁄5, so f = 153, g = 5. Which running day
number y goes with x = 4, z = 7? Then
y = ⌊fx/g⌋ + z = ⌊153×4⁄5⌋ + 7 = ⌊612⁄5⌋ + 7 = ⌊122 + 2⁄5⌋ + 7
= 122 + 7 = 129.
And in the other direction, what calendar date x, z
goes with running day number y = 129? Then k =
yg + g − 1 = 129×5 + 5 − 1 = 649, k = 649 = 4×153 + 37
= fx + r, so x = 4, r = 37,
z = ⌊r/g⌋ = ⌊37⁄5⌋ = 7.
We saw above that p = 30.6 yields a pattern of month
lengths like in the Gregorian calendar, but the pattern (from formula
123) does not begin at the right month number. We want to
shift the pattern so 31-30-31-30-31 begins at x = 0, y =
0 instead of at x = 4, y = 122. Then March is
the first month (x = 0) of the calculation year, and
March 1st (y = 0) is the first day of the calculation
year.
If we shift the pattern by a months (a
is a whole number), then we get
(Eq. 153) y = c + z = ⌊p×(x + a)⌋ − ⌊pa⌋ + z = ⌊px + pa⌋ − ⌊pa⌋ + z = ⌊px
+ pa − ⌊pa⌋⌋ + z = ⌊px + σ⌋ + z
(Eq. 154) σ ≝ pa − ⌊pa⌋ = pa mod 1
(Eq. 155) c = ⌊px + σ⌋
Equation 153 yields y = 0 for x = 0,
z = 0, just like we want.
The derivation of the reverse formula (to calculate x,
z from y) is analogous to that of equation
137. The results are
(Eq. 156) x = ⌈(y + 1 − σ)/p⌉ − 1
(Eq. 157) z = y − c = y − ⌊px + σ⌋
With p = 30.6 and a = 4 we find
σ = 30.6×4 − ⌊30.6×4⌋ = 0.4 so y = ⌊30.6×x +
0.4⌋ + z, and then for the beginning (z = 0) of
the first couple of months:
x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
px + σ | 0.4 | 31.0 | 61.6 | 92.2 | 122.8 | 153.4 | 184 | 214.6 | 245.2 | 275.8 | 306.4 | 337.0 | 367.6 |
⌊px + σ⌋ | 0 | 31 | 61 | 92 | 122 | 153 | 184 | 214 | 245 | 275 | 306 | 337 | 367 |
ψx + σ | 0.4 | 1 | 1.6 | 2.2 | 2.8 | 3.4 | 4 | 4.6 | 5.2 | 5.8 | 6.4 | 7 | 7.6 |
⌊ψx + σ⌋ | 0 | 1 | 1 | 2 | 2 | 3 | 4 | 4 | 5 | 5 | 6 | 7 | 7 |
G | 1 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 | |
L | 31 | 30 | 31 | 30 | 31 | 31 | 30 | 31 | 30 | 31 | 31 | 30 |
Now we have the correct month lengths for the months of March
(x = 0) through January (x = 10) of the
calculation year.
If p = f/g is a ratio of whole numbers, then we find
(Eq. 158) y = c + z = ⌊(fx + s)/g⌋ + z
(Eq. 159) s ≝ fa − g⌊fa/g⌋ = fa mod g
(Eq. 160) k = gy + g − 1 − s
(Eq. 161) x = ⌊k/f⌋
(Eq. 162) z = y − c = y − ⌊(fx + s)/g⌋ = ⌊(k mod f)/g⌋
For the same calendar as before we then have p = 153⁄5
(and still a = 4) so s = 153×4 mod 5 = 612 mod
5 = 2, hence y = ⌊(153×x + 2)/5⌋ + z, k
= 5y + 5 − 2 − 1 = 5y + 2, x = ⌊(5y + 2)/153⌋,
and z = ⌊((5y + 2) mod 153)/5⌋.
x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
153x + 2 | 2 | 155 | 308 | 461 | 614 | 767 | 920 | 1073 | 1226 | 1379 | 1532 | 1685 | 1838 |
(153x + 2)/5 | 0 + 2/5 | 31 | 61 + 3/5 | 92 + 1/5 | 122 + 4/5 | 153 + 2/5 | 184 | 214 + 3/5 | 245 + 1/5 | 275 + 4/5 | 306 + 2/5 | 337 | 367 + 3/5 |
y | 0 | 31 | 61 | 92 | 122 | 153 | 184 | 214 | 245 | 275 | 306 | 337 | 367 |
k = 5y + 2 | 2 | 157 | 307 | 462 | 612 | 767 | 922 | 1072 | 1227 | 1377 | 1532 | 1687 | 1837 |
k/153 | 2/153 | 1 + 4/153 | 2 + 1/153 | 3 + 3/153 | 4 | 5 + 2/153 | 6 + 4/153 | 7 + 1/153 | 8 + 3/153 | 9 | 10 + 2/153 | 11 + 4/153 | 12 + 1/153 |
(k mod 153) | 2 | 4 | 1 | 3 | 0 | 2 | 4 | 1 | 3 | 0 | 2 | 4 | 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 + d days long, with q, d 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
(Eq. 163) p = q + dψ
days. The formula to calculate the running day number
y from month number x and day number
z in the current month is then
(Eq. 164) y = c + z = qx + d⌊ψ×(x + a)⌋ − d⌊ψa⌋ + z = qx + d⌊ψx + ψa −
⌊ψa⌋⌋ + z = qx + d⌊ψx + σ⌋ + z
(Eq. 165) σ ≝ ψa − ⌊ψa⌋ = ψa mod 1
(Eq. 166) c = qx + d⌊ψx + σ⌋
How do we go in the opposite direction? To figure that out we compare
the running day number c that comes from equation
164 for the first day (z = 0) of month
x with the running day number (for convenience renamed
to cp) that comes from equation 123 for the
same x and the same average month length
p (but with d = 1 and a =
0).
(Eq. 167) cp ≝ ⌊px⌋ = ⌊qx + dψx⌋ = qx + ⌊dψx⌋
Then we find
(Eq. 168) c − cp = d⌊ψx + σ⌋ − ⌊dψx⌋ = d(ψx + σ − δ) − (dψx − ε) = dσ
− dδ + ε
for certain δ, ε satisfying
(Eq. 169) 0 ≤ {δ,ε} < 1
so
(Eq. 170) dσ − d < c − cp < dσ + 1
(Eq. 171) dσ − d + 1 ≤ c − cp ≤ dσ
so the beginning of month x in the target calendar is
between dσ + 1 − d and dσ days after the
beginning of month x in the simpler calendar. Because
0 ≤ σ < 1, we also have −d < c − cp <
d, so the difference between the beginning of a particular
month in the target calendar and the same month in the simpler
calendar is always less than d days (in either
direction).
For that simpler calendar we have formula 156 to calculate
the corresponding month number for any of the ⌊p⌋ or
⌈p⌉ days in that month, so if running day number
y corresponds to one of the first ⌊p⌋
days of month x in the target calendar, then we'll have
for that x
(Eq. 172) xlower ≤ x ≤ xupper
(Eq. 173) xlower ≝ ⌈(y − dσ + 1)/p⌉ − 1
(Eq. 174) xupper ≝ ⌈(y − dσ + d)/p⌉ − 1
In the target calendar, a month can be up to q + d days
long, while in the corresponding simpler calendar a month cannot be
longer than ⌈p⌉ days, which is less than q +
d. A number (less than d) days beyond day
⌊p⌋ of a month can still belong to that same month in
the target calendar, but already belong to a later month in the
simpler calendar. For such days, formula 174 can yield a
month number that is too great, but then formula 172 still
holds.
If d ≤ p then the difference between
xupper and xlower is at most 1. In that
case
(Eq. 175) cupper = qxupper + d⌊ψxupper + σ⌋
(Eq. 176) zupper = y − cupper
(Eq. 177) ζ = ⌊zupper/(q + d)⌋
(Eq. 178) x = xupper + ζ
(Eq. 179) z = y − c = y − qx − d⌊ψx + σ⌋
If f = 1001, g = 165, d = 2, q = 5, a = 77, then
p = f/g = 1001⁄165 = 6 11⁄165, ψ =
176⁄330, and σ = ψa mod 1 = 13552⁄330 mod 1 =
22⁄330. Then also d ≤ p, so equation 178
can be used.
The running day number y of the first day of month
number x = 37 is then (from equation 164)
y = qx + d⌊ψx⌋ = 5×37 + 2×⌊37×176⁄330 + 22⁄330⌋ = 185 +
2×⌊6534⁄330⌋ = 223.
Now we calculate the month that corresponds to running day number
y = 223. Then xlower = ⌈(y + 1)/p⌉ − 1 =
⌈224×165⁄1001⌉ − 1 = 36 and xupper = ⌈(y + d)/p⌉ − 1 =
⌈225×165⁄1001⌉ − 1 = 37, so the month number can be 36 or 37.
For xupper we find cupper = 5×37 + 2×⌊176×37⁄330 +
22⁄330⌋ = 223, so zupper = y − cupper = 223 − 223 =
0 and ζ = 0 and x = xupper = 37
and z = zupper = 0.
And here is another example. With f = 829, g = 235, d = 2, q =
3, ψ = 124⁄470, a = 0 we calculate which month corresponds to
running day number y = 1448. Then p = q + dψ =
3 + 2×124⁄470 ≥ 2 = d, so we can use equation 178. Then
xlower = ⌈(y + 1)/p⌉ − 1 = ⌈1449×235⁄829⌉ − 1 = 410 and
xupper = ⌈(y + d)/p⌉ − 1 = ⌈1450×235⁄829⌉ − 1 = 411, so
the month number can be 410 or 411. For xupper we find
cupper = 3×411 + 2×⌊411×124⁄470⌋ = 1449, so zupper
= y − cupper = 1448 − 1449 = −1 and ζ = −1 and
x = xupper + ζ = 410 and z = y − c = 1448 − 3×410
− 2×⌊411×124⁄470⌋ = 2.
If p = f/g = q + dh/g is a ratio of whole numbers
(f, g, q, d, h are whole numbers), then we find
%ignore>
(Eq. 180) y = c + z = qx + d⌊(hx + s)/g⌋ + z
(Eq. 181) s ≝ ha − g⌊ha/g⌋ = ha mod g
(Eq. 182) xupper = ⌊(gy + dg − ds − 1)/f⌋
(Eq. 183) cupper = qxupper + d⌊(hxupper + s)/g⌋
(Eq. 184) zupper = y − cupper
(Eq. 185) ζ = ⌊zupper/(q + d)⌋
(Eq. 186) x = xupper + ζ
(Eq. 187) z = y − c = y − qx − d⌊(hx + s)/g⌋
We now allow there to be more than two kinds of months with different
month lengths. In equation 164, ⌊ψ×(x + a)⌋
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 di (which may now also be negative),
relative frequency 0 < ψi < 1, and pattern shift
ai. Then we find
(Eq. 188) y = c + z = qx + ∑idi⌊ψi×(x + ai)⌋ − ∑idi⌊ψiai⌋ +
z = qx + ∑idi⌊ψix + ψiai − ⌊ψiai⌋⌋ + z = qx +
∑idi⌊ψix + σi⌋ + z
(Eq. 189) c = qx + ∑idi⌊ψix + σi⌋
(Eq. 190) σi ≝ ψiai − ⌊ψiai⌋ = ψiai mod 1
The derivation of the formulas for the opposite direction goes
analogous to that of equation 174, but now we have to take
into account possibly negative di. We find
(Eq. 191) p = q + ∑idiψi
(Eq. 192) cp = ⌊px⌋ = qx + ⌊∑idiψi⌋
(Eq. 193) c − cp = ∑idi⌊ψix + σi⌋ − ⌊∑idiψix⌋ =
∑idi×(ψix + σi − δi) − (∑idiψix − ε) = ∑idiσi
− ∑idiδi + ε
for
(Eq. 194) 0 ≤ δi, ε < 1
If there is at least one di > 0, then
(Eq. 195) c − cp > ∑idiσi − ∑(>0)di
(where ∑(>0)di is the sum of all
di that are greater than 0) and otherwise
(Eq. 196) c − cp ≥ ∑idiσi
Also
(Eq. 197) c − cp < ∑idiσi − ∑(<0)di + 1
Together this yields
(Eq. 198) ∑idiσi − ∑(>0)di + 1 ≤ y − yp ≤ ∑idiσi −
∑(<0)di
if there are positive di, and otherwise
(Eq. 199) ∑idiσi ≤ c − cp ≤ ∑idiσi − ∑idi
We can combine this to
(Eq. 200) ∑idiσi − ∑(>0)di ≤ c − cp ≤ ∑idiσi −
∑(<0)di
regardless of whether there are positive di. With
that,
(Eq. 201) c − ∑idiσi + ∑(<0)di ≤ cp ≤ c − ∑idiσi +
∑(>0)di
and so
(Eq. 202) xlower = ⌈(y − ∑idiσi + ∑(<0)di)/p⌉ − 1
(Eq. 203) xupper = ⌈(y − ∑idiσi + ∑(>0)di)/p⌉ −
1
If ∑(>0)di − ∑(<0)di < p then
xlower and xupper differ by at most 1.
Then
(Eq. 204) cupper = qxupper + ∑idi⌊ψixupper + σi⌋
(Eq. 205) zupper = y − cupper
(Eq. 206) ζ = ⌊zupper/(q + ∑(>0)di)⌋
(Eq. 207) x = xupper + ζ
(Eq. 208) z = y − c − y − qx − ∑idi⌊ψix + σi⌋
If all ψi = hi/g are ratios of whole numbers with a
common denominator g, then we find
(Eq. 209) f ≝ qg + ∑idihi
(Eq. 210) p = f/g
(Eq. 211) y = c + z = qx + ∑idi⌊(hix + si)/g⌋ +
z
(Eq. 212) si ≝ hiai − g⌊hiai/g⌋ = hiai mod g
(Eq. 213) xupper = ⌊(gy + g∑(>0)di − ∑idisi −
1)/f⌋
(Eq. 214) cupper = qxupper + ∑idi⌊(hixupper + si)/g⌋
(Eq. 215) zupper = y − cupper
(Eq. 216) ζ = ⌊zupper/(q + ∑(>0)di)⌋
(Eq. 217) x = xupper + ζ
(Eq. 218) z = y − c = y − qx − ∑idi⌊(hix + si)/g⌋
g is the least common multiple of the denominators of
all ψi, or is a multiple of that. You can take the
product of the denominators of all ψi for
g, but sometimes a smaller value can be used.
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
i | 1 | 2 |
di | 2 | 3 |
ψi | 1/3 = 5/15 | 1/5 = 3/15 |
ai | 0 | 0 |
hi | 5 | 3 |
si | 0 | 0 |
for g = 15 (the product of denominators 3 and 5). Then
p = (17×15 + 2×5 + 3×3)/15 = 268⁄15 = 17 + 13⁄15, so
f = 268 and y = 17x + 2⌊x/3⌋ + 3⌊x/5⌋
and xupper = ⌊(15y + 15×5 − 0 − 1)/268⌋ = ⌊(15y +
74)/268⌋.
The following table shows the results that you get when you calculate
for certain calendar dates x, z what the corresponding
running day number y is, and then calculate from that
y what the month number x = xupper + ζ
is.
x | 0 | 0 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 | 5 | 5 | 6 | 6 | 7 | 7 | 8 | 8 | 9 | 9 | 10 | 10 | 11 | 11 | 12 | 12 | 13 | 13 | 14 | 14 | 15 | 15 |
z | 0 | 16 | 0 | 16 | 0 | 18 | 0 | 16 | 0 | 19 | 0 | 18 | 0 | 16 | 0 | 16 | 0 | 18 | 0 | 19 | 0 | 16 | 0 | 18 | 0 | 16 | 0 | 16 | 0 | 21 | 0 | 16 |
y | 0 | 16 | 17 | 33 | 34 | 52 | 53 | 69 | 70 | 89 | 90 | 108 | 109 | 125 | 126 | 142 | 143 | 161 | 162 | 181 | 182 | 198 | 199 | 217 | 218 | 234 | 235 | 251 | 252 | 273 | 274 | 290 |
xupper | 0 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 | 5 | 5 | 6 | 6 | 7 | 7 | 8 | 8 | 9 | 9 | 10 | 10 | 11 | 11 | 12 | 12 | 13 | 13 | 14 | 14 | 15 | 15 | 16 |
yupper | 0 | 17 | 17 | 34 | 34 | 53 | 53 | 70 | 70 | 90 | 90 | 109 | 109 | 126 | 126 | 143 | 143 | 162 | 162 | 182 | 182 | 199 | 199 | 218 | 218 | 235 | 235 | 252 | 252 | 274 | 274 | 291 |
ζ | 0 | −1 | 0 | −1 | 0 | −1 | 0 | −1 | 0 | −1 | 0 | −1 | 0 | −1 | 0 | −1 | 0 | −1 | 0 | −1 | 0 | −1 | 0 | −1 | 0 | −1 | 0 | −1 | 0 | −1 | 0 | −1 |
xupper + ζ | 0 | 0 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 | 5 | 5 | 6 | 6 | 7 | 7 | 8 | 8 | 9 | 9 | 10 | 10 | 11 | 11 | 12 | 12 | 13 | 13 | 14 | 14 | 15 | 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 less than the average
month length: d ≤ p when there are two different month
lengths, or ∑(>0)di − ∑(<0)di < p if there
are more month lengths. 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 x = xupper and calculate the
corresponding z = y − c and ζ. Is that
ζ < 0? Then add ζ to x
and try again, until ζ = 0: then you have found the
correct x.
Let q = 3, d = 7, ψ = 1⁄3, then h = 1, g =
3, f = 16, p = q + dψ = 3 + 5⁄3 = 5 2⁄3 so the condition
d ≤ p 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
xupper = ⌊(3y + 20)/16⌋
xlower = ⌊(3y + 2)/16⌋
c = 3×x + 7⌊x/3⌋
We find
y | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
xupper | 1 | 1 | 1 | 1 | 2 | 2 | 2 | 2 | 2 | 2 | 3 | 3 | 3 | 3 | 4 | 4 | 4 |
cupper | 3 | 3 | 3 | 3 | 6 | 6 | 6 | 6 | 6 | 6 | 16 | 16 | 16 | 16 | 19 | 19 | 19 |
z₀ | -3 | -2 | -1 | 0 | -2 | -1 | 0 | 1 | 2 | 3 | -6 | -5 | -4 | -3 | -5 | -4 | -3 |
ζ₀ | -1 | -1 | -1 | 0 | -1 | -1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -1 | -1 | 0 |
c₁ | 0 | 0 | 0 | 3 | 3 | 6 | 6 | 6 | 6 | 16 | 16 | 16 | |||||
z₁ | 0 | 1 | 2 | 1 | 2 | 4 | 5 | 6 | 7 | -2 | -1 | 0 | |||||
ζ₁ | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -1 | -1 | 0 | |||||
c₂ | 6 | 6 | |||||||||||||||
z₂ | 8 | 9 | |||||||||||||||
ζ₂ | 0 | 0 | |||||||||||||||
x | 0 | 0 | 0 | 1 | 1 | 1 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 3 |
z | 0 | 1 | 2 | 0 | 1 | 2 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
For example: for y = 11 we find xupper = ⌊(3×11 +
20)/16⌋ = 3 and then cupper = 3×3 + 7⌊3⁄3⌋ = 16,
then z₀ = y − cupper = 11 − 16 = −5. That
z₀ is negative, so we decrement x by one
(x = 3 − 1 = 2) and try again. With the new
x we find c₁ = 3×2 + 7⌊2⁄3⌋ = 6 and then
z₁ = y − c₁ = 11 − 6 = 5, which is no longer negative,
so we're done. For y = 11 we find x = 2
and z = 5.
If you want to, then you can use this procedure also if d ≤
p.
The greatest number of months that you may have to try before you find
the right one is equal to the greatest value that xupper −
xlower can attain, plus 1. For calendars with two different
month lengths we have
(Eq. 219) xupper − xlower = ⌈(y − dσ + d)/p⌉ − ⌈(y − dσ + 1)/p⌉
The greatest value that this can attain is ⌈(d − 1)/p⌉,
so the number N of month that you have to try at most
is equal to
(Eq. 220) N = ⌈(d − 1)/p⌉ + 1
For calendars with more than two different month lengths we have
(Eq. 221) xupper − xlower = ⌈(y − ∑idiσi + ∑(>0)di)/p⌉ − ⌈(y −
∑idiσi + ∑(<0)di)/p⌉
which has for its greatest possible value ⌈(∑(>0)di −
∑(<0)di)/p⌉ so for such a calendar
(Eq. 222) N = ⌈(∑(>0)di − ∑(<0)di)/p⌉ + 1
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 y, running month number
x, and day number z in the current month
(all starting at 0) is then
y | 0 | 1 | … | 6 | 7 | … | 19 | 20 | … | 24 | 25 | … | 35 | 36 | … | 39 |
x | 0 | 0 | … | 0 | 1 | … | 1 | 2 | … | 2 | 3 | … | 3 | 4 | … | 4 |
z | 0 | 1 | … | 6 | 0 | … | 12 | 0 | … | 4 | 0 | … | 10 | 0 | … | 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 y and the
running month number x 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
⌊(y + f − a)/f⌋ = ⌊(y − a)/f⌋ + 1. The +
1 ensures that the value for y = 0 is
0: that makes for easier calculations.
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 x = 1 + ⌊(y −
7)/40⌋:
y | 0 | 1 | … | 6 | 7 | 8 | … | 46 | 47 | 48 |
y−7 | −7 | −6 | −1 | 0 | 1 | 39 | 40 | 41 | ||
x | 0 | 0 | 0 | 1 | 1 | 1 | 2 | 2 |
When there are g months, each with its own
ai (for i from 1 through
g), then their combined effect is
(Eq. 223)
x = g + ∑i⌊(y − ai)/f⌋
If the successive month lengths are mi, then the first
step is at a₁ = 0, the second one is at a₂ = a₁
+ m₁ = m₁, the third one is at a₃ = a₂ + m₂ = m₁ +
m₂, and in general
(Eq. 224)
ai = ∑(j<i)mj
Then
(Eq. 225)
x = g + ∑i⌊(y − ∑(j<i)mj)/f⌋
For the example calendar we have f = 40, g =
5, and
i | 1 | 2 | 3 | 4 | 5 |
mi | 7 | 13 | 5 | 11 | 4 |
ai | 0 | 7 | 20 | 25 | 36 |
and so x = ⌊(y + 40 − 0)/40⌋ + ⌊(y + 40 − 7)/40⌋ + ⌊(y + 40 −
20)/40⌋ + ⌊(y + 40 − 25)/40⌋ + ⌊(y + 40 − 36)/40⌋ = ⌊(y + 40)/40⌋ +
⌊(y + 33)/40⌋ + ⌊(y + 20)/40⌋ + ⌊(y + 15)/40⌋ + ⌊(y + 4)/40⌋.
For example, if y = 21 then x = ⌊61⁄40⌋ +
⌊54⁄40⌋ + ⌊41⁄40⌋ + ⌊36⁄40⌋ + ⌊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 c of
the first day of month x is:
(Eq. 226)
c = ∑imi⌊(x + g − i)/g⌋
With again the same calendar, we find c = 7⌊(x+4)/5⌋ +
13⌊(x+3)/5⌋ + 5⌊(x+2)/5⌋ + 11⌊(x+1)/5⌋ + 4⌊x/5⌋.
x | 0 | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|---|
7⌊(x+4)/5⌋ | 0 | 7 | 7 | 7 | 7 | 7 |
13⌊(x+3)/5⌋ | 0 | 0 | 13 | 13 | 13 | 13 |
5⌊(x+2)/5⌋ | 0 | 0 | 0 | 5 | 5 | 5 |
11⌊(x+1)/5⌋ | 0 | 0 | 0 | 0 | 11 | 11 |
4⌊x/5⌋ | 0 | 0 | 0 | 0 | 0 | 4 |
c | 0 | 7 | 20 | 25 | 36 | 40 |
The formula to go from running month number x and day
number z in the current month to running day number
y (all beginning at 0) is then (with i
running from 1 through g)
(Eq. 227)
y = c + z = ∑imi⌊(x + g − i)/g⌋ + z
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 5.2 has y = ⌊px +
σ⌋ + z. To have that calendar begin month x at
day y we need y = ⌊px + σ⌋, from which
follows y ≤ px + σ < y + 1, hence (for x >
0) (y − σ)/x ≤ p < (y + 1 − σ)/x. We know
that 0 ≤ σ < 1, so (y − 1)/x < (y − σ)/x
≤ p < (y + 1 − σ)/x < (y + 1)/x, so
(Eq. 228) (y − 1)/x < p < (y + 1)/x
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 5.2 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 228. The first day of month x = 1
has y = 7, so we must have 6 < p <
8. The first day of month x = 2 has y =
20 so we need 9½ = 19⁄2 < p < 21⁄2 = 10½,
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, so usually you have to combine several periods. Let's assume that we have two straight lines for two periods:
(Eq. 229) y₁ = c₁(x₁) + z₁
(Eq. 230) y₂ = c₂(x₂) + z₂
and in the other direction
(Eq. 231) x₁ = c₁'(y₁)
(Eq. 232) z₁ = y₁ − c₁(x₁)
(Eq. 233) x₂ = c₂'(y₂)
(Eq. 234) z₂ = y₂ − c₂(x₂)
where c'(y) is the inverse of c(x):
c'(c(x)) = x and c(c'(y)) = y.
We assume that the first line is for the smaller period and the second
line is for the larger period. There are two ways to combine these:
We can equate y₁ to z₂ or to
x₂. 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 (d > 1) or stepped (then usually
d = 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₁ = 7⁄3 = 2 + 2⁄3 and for the second calendar a simple
one with p₂ = 37⁄5 = 7 + 2⁄5. Then we have
y₁ = ⌊7x₁/3⌋ + z₁ = c₁ + z₁
y₂ = ⌊37x₂/5⌋ + z₂ = c₂ + z₂
x₁ = ⌊(3y₁ + 2)/7⌋
z₁ = ⌊((3y₁ + 2) mod 7)/3⌋
x₂ = ⌊(5y₂ + 4)/37⌋
z₂ = ⌊((5y₂ + 4) mod 37)/5⌋
In this case z₂ = y₁, so
(Eq. 235) y₂ = c₂(x₂) + c₁(x₁) + z₁
and in the other direction
(Eq. 236) x₂ = c₂'(y₂)
(Eq. 237) y₁ = z₂ = y₂ − c₂(x₂)
(Eq. 238) x₁ = c₁'(y₁)
(Eq. 239) z₁ = y₁ − c₁(x₁)
Here (for example) y₂ is the running day number,
x₂ is the year number, y₁ = z₂ is the
day number in the current year, x₁ is the month number
in the current year (with 0 for the first month), and
z₁ is the day number in the current month (with 0 for
the first day).
To calculate the calendar date from the running day number, we must
first calculate the larger period (x₂, z₂), and then
the smaller period (x₁, z₁).
The two example calendars then yield, for the first 20 days,
y₂ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
x₂ | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 2 | 2 | 2 | 2 | 2 |
z₂ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 0 | 1 | 2 | 3 | 4 | 5 |
y₁ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 0 | 1 | 2 | 3 | 4 | 5 |
x₁ | 0 | 0 | 1 | 1 | 2 | 2 | 2 | 0 | 0 | 1 | 1 | 2 | 2 | 2 | 0 | 0 | 1 | 1 | 2 | 2 |
z₁ | 0 | 1 | 0 | 1 | 0 | 1 | 2 | 0 | 1 | 0 | 1 | 0 | 1 | 2 | 0 | 1 | 0 | 1 | 0 | 1 |
Running day number y₂ = 16 corresponds to day z₁
= 0 of month x₁ = 1 of year x₂ =
2.
In this case x₂ = y₁, so
(Eq. 240) y₂ = c₂(c₁(x₁) + z₁) + z₂
and in the other direction
(Eq. 241) y₁ = c₂'(y₂)
(Eq. 242) z₂ = y₂ − c₂(y₁)
(Eq. 243) x₁ = c₁´(y₁)
(Eq. 244) z₁ = y₁ − c₁(x₁)
Here (for example) y₂ is the running day number,
x₁ is the year number, x₂ = y₁ is the
running month number, z₁ is the month number in the
current year (with 0 for the first month), and z₂ is
the day number in the current month (with 0 for the first day).
With our two example calendars we find
y₂ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
x₂ | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 2 | 2 | 2 | 2 | 2 |
z₂ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 0 | 1 | 2 | 3 | 4 | 5 |
y₁ | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 2 | 2 | 2 | 2 | 2 |
x₁ | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
z₁ | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
Running day number y₂ = 16 corresponds to day z₂
= 2 of month z₁ = 0 of year x₁ =
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 pi
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₁,x₂,…,xn}, where xi is the
day number from period i. If xi is
equal to pi − 1, then the next day has xi =
0 again.
For example, in a calendar with p₁ = 13 and p₂ =
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 J into
{x} we can use the following formula:
(Eq. 245) xi = (J + ai) mod pi
Here ai is the value of xi when
J = 0. That value depends on the calendar.
Suppose that in the calendar from the previous example J =
0 corresponds to {11,8}. Then a₁ =
11 and a₂ = 8, and then
x₁ = (J + 11) mod 13
x₂ = (J + 8) mod 20
Day J = 11 then corresponds to x₁ = (11 + 11)
mod 13 = 22 mod 13 = 9 and x₂ = (11 + 8) mod 20 = 19
mod 20 = 19, so {9,19}.
It is a lot more difficult to go in the other direction. Then we have
to find a J for which equation 245 is
satisfied for all i, i.e.,
(Eq. 246) J ≡ xi − ai (mod pi)
We define
(Eq. 247) ci = xi − ai
We first look at the case n = 2. Then we need to solve
J from
(Eq. 248) J ≡ c₁ (mod p₁)
(Eq. 249) J ≡ c₂ (mod p₂)
All solutions to equation 248 are of the kind
(Eq. 250) J = c₁ + kp₁
when k runs through all whole numbers. Substituting
into formula 249 yields
(Eq. 251) kp₁ ≡ c₂ − c₁ (mod p₂)
If we could find a number r₂ such that r₂p₁ ≡ 1
(mod p₂), then we could solve the preceding formula for
k. Such a number r₂ only exists if
p₁ and p₂ are relative prime, which
means that they have no common divisors (greater than 1).
If the greatest common divisor of p₁ and
p₂ is equal to g (greater or equal to
1), and
(Eq. 252) qi = pi/g
then we can rewrite formula 251 to
(Eq. 253) kgq₁ ≡ c₂ − c₁ (mod gq₂)
If c₂ − c₁ is evenly divisible by g,
then we can divide by g throughout and then we find
(Eq. 254) kq₁ = (c₂ − c₁)/g mod q₂
For dates from calendars based on formula 245 c₂ −
c₁ is evenly divisible by g, so we make that
assumption.
Because q₁ and q₂ are relative prime,
there is a number r₂ such that r₂q₁ ≡ 1 (mod
q₂). With that we find from equation 254
(Eq. 255) k ≡ kq₁r₂ ≡ ((c₂ − c₁)/g) r₂ (mod q₂)
and then
(Eq. 256) kp₁ ≡ q₁r₂(c₂ − c₁)/g (mod q₂p₁)
(Eq. 257) J = c₁ + kp₁ ≡ c₁ + q₁r₂(c₂ − c₁) ≡ c₁ (1 − r₂q₁) + c₂r₂q₁
(mod q₂p₁)
thus
(Eq. 258) J ≡ (x₁ − a₁) (1 − r₂q₁) + (x₂ − a₂)r₂q₁ (mod
p₂q₁)
How can you find a r₂ such that r₂q₁ ≡ 1 (mod
q₂)? Because you only need to find that r₂
once for a given calendar, it is usually the least amount of work to
just try successive values starting at 1 until you find the correct
one. You need to check at most q₂ successive values.
If you need to calculate such r₂ often, then you can
use the Extended Euclidean Algorithm.
You can find the greatest common divisor of p₁ and
p₂ by using the regular Euclidean Algorithm.
We again use the calendar from the previous example, with p₁ =
13, p₂ = 20, a₁ = 11 and
a₂ = 8. The greatest common divisor of 13 and 20 is 1,
so g = 1 and q₁ = p₁ = 13 and q₂
= p₂ = 20. Now we seek r₂.
y | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
yq₁ = 13y | 0 | 13 | 26 | 39 | 52 | 65 | 78 | 91 | 104 | 117 | 130 | 143 | 156 | 169 | 182 | 195 | 208 | 221 | 234 | 247 | 260 |
yq₁ mod q₂ = 13y mod 20 | 0 | 13 | 6 | 19 | 12 | 5 | 18 | 11 | 4 | 17 | 10 | 3 | 16 | 9 | 2 | 15 | 8 | 1 | 14 | 7 | 0 |
We find r₂ = 17, because 17×13 = 221 ≡ 1 (mod
20).
Then J ≡ (x₁ − 11)×(1 − 17×13) + (x₂ − 8)×17×13 ≡ (x₁ −
11)×−220 + (x₂ − 8)×221 ≡ 40×(x₁ − 11) + 221×(x₂ − 8) ≡ 40x₁ − 11×40 +
221x₂ − 8×221 ≡ 40x₁ + 221x₂ − 2208 ≡ 40x₁ + 221x₂ + 132 (mod 13×20 =
260).
For date {9,19} we then find J ≡ 40×9 + 221×19 +
132 ≡ 360 + 4199 + 132 ≡ 100 + 39 + 132 ≡ 271 ≡ 11 (mod 260),
so day J = 11 and every 260 days earlier or later
correspond to date {9,19}.
Warning! Formula 258 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 periods are not relatively
prime, with p₁ = 10, p₂ = 15, a₁
= a₂ = 0. Then
x₁ = J mod 10
x₂ = J mod 15
The greatest common divisor of p₁ and p₂
is g = 5, so q₁ = p₁/g = 2 and q₂
= p₂/g = 3. To this belongs r₂ = 2, because
2×3 = 6 ≡ 1 (mod 5). Then c₁ = x₁ and
c₂ = x₂, and
J ≡ x₁ (1 − 2×2) + x₂×2×2 ≡ −3x₁ + 4x₂ = 27x₁ + 4x₂ (mod 15×2
= 30)
For J from 8 to 17 we then find for {x}:
{8,8}, {9,9}, {0,10}, {1,11}, {2,12}, {3,13}, {4,14}, {5,0},
{6,1}, {7,2}.
For that {x} formula 5.9.2 yields:
x₁ | 8 | 9 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
x₂ | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 0 | 1 | 2 |
27x₁ + 4x₂ | 248 | 279 | 40 | 71 | 102 | 133 | 164 | 135 | 166 | 197 |
J mod 30 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
Because g is not equal to 1, many combinations of
x₁ and x₂ do not occur in this calendar.
Only combinations for which x₁ − x₂ is evenly divisible
by 5 occur in this calendar. For example, {3,7} does
not occur. If we apply equation 5.9.2 to that date, then we find
J ≡ 27×3 + 4×7 ≡ 19 (mod 30), but for J =
19 we find x₁ = 9 and x₂ = 4, so
{9,4} and not {3,7}. For impossible
{x} we still get nice-looking J out of
formula 5.9.2.
Using equation 258, J ≡ x₁ − a₁ mod p₁ and
J ≡ x₂ − a₂ (mod p₂) lead to another equation J
≡ C₂ (mod P₂) with
(Eq. 259) C₂ ≝ (x₁ − a₁) (1 − r₂q₁) + (x₂ − a₂) r₂q₁
(Eq. 260) P₂ ≝ p₂q₁
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 J
≡ x₃ − a₃ (mod p₃), and so on until we've handled all
pi. We end up with a formula that again has the same
form J ≡ Cn (mod Pn), and that is the solution of
the n equations.
The procedure is then as follows. Given xi,
pi, ai for i from 1
through n,
C₁ = x₁ − a₁ and P₁ =
p₁.i from 2 through n:gi, the greatest common divisor of
P(i−1) and pi.Q(i−1) = P(i−1)/gi and qi =
pi/gi.ri that satisfies riQ(i−1) ≡ 1
(mod qi).Ci = C(i−1) (1 − riQ(i−1)) + (xi − ai)
riQ(i−1) and Pi = piQ(i−1).(Eq. 261) J ≡ Cn (mod
Pn)
Let's look at a calendar with the following characteristics:
i | 1 | 2 | 3 |
pi | 4 | 5 | 6 |
ai | 3 | 1 | 2 |
You translate running day number J to calendar date
{x} as follows:
x₁ = (J + 3) mod 4
x₂ = (J + 1) mod 5
x₃ = (J + 2) mod 6
In the opposite direction we find:
C₁ = x₁ − 3
P₁ = 4
g₂ = 1
Q₁ = 4⁄1 = 4
q₂ = 5⁄1 = 5
r₂ = 4
C₂ = C₁×(1 − 4×4) + (x₂ − 1)×4×4 = −15×(x₁ − 3) + 16×(x₂ − 1) =
−15x₁ + 16x₂ + 29
P₂ = 5×4 = 20
g₃ = 2
Q₂ = 20⁄2 = 10
q₃ = 6⁄2 = 3
r₃ = 1
C₃ = C₂×(1 − 1×10) + (x₃ − 2)×1×10 = −9×(−15x₁ + 16x₂ + 29) +
10×(x₃ − 2) = 135x₁ − 144x₂ + 10x₃ − 281
P₃ = 60
The solution is J ≡ C₃ ≡ 15x₁ + 36x₂ + 10x₃ + 19 (mod Pn =
60).
Let's check: if J = 654, then x₁ = (654 + 3)
mod 4 = 1, x₂ = (654 + 1) mod 5 = 0, x₃ = (654 + 2) mod 6 =
2. And from {x} to J we find
J ≡ 15×1 + 36×0 + 10×2 + 19 ≡ 54 (mod 60), which is
correct, because 54 ≡ 654 (mod 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 J that
corresponds to date {x} we find formula 261,
which gives a solution mod Pn. If you have found a
running day number J that fits date {x},
then you can add or subtract arbitrary multiples of Pn
and then you find another J 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
choose the last solution on or before a specified date, for example
the last day on or before J = 700 that corresponds to
date {1,0,2}.
If that limiting day is J₀, and J ≡ Cn (mod
Pn), then
(Eq. 262) J₀ − Pn < J ≤ J₀
(Eq. 263) J₀ − Pn < Cn + kPn ≤ J₀
(Eq. 264) J₀ − Cn − Pn < kPn ≤ J₀ − Cn
(Eq. 265) (J₀ − Cn)/Pn − 1 < k ≤ (J₀ − Cn)/Pn
(Eq. 266) ⌊(J₀ − Cn)/Pn⌋ − 1 < k ≤ ⌊(J₀ − Cn)/Pn⌋
There is only a single value of k that satisfies these
inequalities, which is
(Eq. 267) k = ⌊(J₀ − Cn)/Pn⌋
Now ⌊x/y⌋ = x/y − (x mod y)/y so y⌊x/y⌋ = x −
(x mod y), so
(Eq. 268) kPn = Pn⌊(J₀ − Cn)/Pn⌋ = J₀ − Cn − ((J₀ − Cn) mod
Pn)
and
(Eq. 269) J = Cn + kPn = J₀ − ((J₀ − Cn) mod
Pn)
For example, what is the last day on or before J₀ = 700
that corresponds to date {1,0,2} in the calendar from
the previous example?
There we found Cn = 15x₁ + 36x₂ + 10x₃ + 19 and
Pn = 60, so Cn = 15×1 + 36×0 + 10×2 + 19 =
54. With formula 269 we then find J = 700 −
((700 − 54) mod 60) = 700 − (646 mod 60) = 700 − 46 = 654
which is correct: 654 + 60 = 714 is greater than 700, so 654 is the
last J that is less than or equal to J₀
and that fits date {1,0,2}.
We should find J = 654 for all J₀ from
654 through 654 + 60 − 1 = 713, and we do:
J₀ | J₀ − Cn | (J₀ − Cn) mod Pn | J |
| 653 | 599 | 59 | 594 |
| 654 | 600 | 0 | 654 |
| 712 | 658 | 58 | 654 |
| 713 | 659 | 59 | 654 |
| 714 | 660 | 0 | 714 |
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.
g − 1 (the last month before everything repeats
itself) is always a long month.The following table summarizes the calendar formulas, and uses the following definitions:
q is the basic number of days in each month. For
calendar types 1 through 3, q is the number of days in
short months. 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.ψ, ψi is the fraction of the infinite number of
months that has the non-basic month length (unequal to
q).d, di is the difference between a month length and
the basic month length q. They are whole numbers. For
calendar type 3, d must be greater than zero. For
calendar type 4 di may be greater or less than
zero.h, hi are the numerator and denominator from
ψ = h/g or ψi = hi/g. They are whole
numbers greater than zero.a, ai 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 a + g has the same
effect as value a.
x is the running month number. It is a whole
number, and can be negative, zero, or positive.c is the running day number of the beginning of
month c. It is a whole number, and can be negative,
zero, or positive.ζ is a correction to be added to month number
x to get a better estimate for the month number. This
is only relevant for calendar types 3 and 4.z is the number of days since the beginning of the
current month, z = y − c.# | p | f | c | c' | s | ζ |
|---|---|---|---|---|---|---|
| 1 | q + ψ | qg + h | ⌊fx/g⌋ | ⌊(gy + g − 1)/f⌋ | 0 | 0 |
| 2 | q + ψ | qg + h | ⌊(fx + s)/g⌋ | ⌊(gy + g − s − 1)/g⌋ | fa mod g | 0 |
| 3 | q + dψ | qg + dh | qx + d⌊(hx + s)/g⌋ | ⌊(gy + dg − ds − 1)/g⌋ | ha mod g | ⌊z/(q + d)⌋ |
| 4 | q + ∑diψi | qg + ∑dihi | qx + ∑di⌊(hix + si)/g⌋ | ⌊(gy + g∑(>0)di − ∑disi − 1)/f⌋ | hiai mod g | ⌊z/(q + ∑(>0)di)⌋ |
For calendar types 3 and 4, the formula for x yields an
upper boundary for the month number. The general procedure for
finding the right month number is then:
Try the x from the formula in the table. Calculate the
corresponding c and then z = y − c and
ζ. If ζ is equal to 0, then you're
done. Otherwise, add ζ (which is negative) to
x and try again.
If d ≤ p (for calendar type 3) or ∑(>0)di −
∑(<0)di < p (for calendar type 4), then you need to
calculate ζ at most once. Otherwise you may need to do
it more often, up to ⌈(d − 1)/p⌉ + 1 (for calendar type
3) or ⌈(∑(>0)di − ∑(<0)di)/p⌉ + 1 (for
calendar type 4) times.
If there are more that two relevant units of time, then different calendar levels must be combined. From calendar date in the direction of running day number we have
(Eq. 270) yi = ci(xi) + zi
and from running day number in the direction of calendar date
(Eq. 271) xi = c'i(yi)
(Eq. 272) zi = yi − ci(xi)
If the smallest unit of time in two calendars is the same (for
example, days), then those calendars should be combined in a flat
manner, then z(i+1) = yi. If the smallest unit of
time from calendar i + 1 is equal to the largest unit
of time from calendar i, then those calendars should be
combined in a stepped manner, then x(i+1) = yi.
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 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 can work around the problem by regarding February as the last month of the calculation year. Then March is month 0 of the calculation year, and February is month 11 of the same calculation year.
For month m of year j we then find
calculation month m₂ and calculation year
j₂:
(Eq. 273) c = ⌊(m − 3)/12⌋
(Eq. 274) j₂ = j + c
(Eq. 275) m₂ = m − 12c − 3
m | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
c | −1 | −1 | −1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |
m₂ | 9 | 10 | 11 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 0 | 1 | 2 |
j₂ | j−1 | j−1 | j−1 | j | j | j | j | j | j | j | j | j | j | j | j | j+1 | j+1 | j+1 |
and in the opposite direction
(Eq. 276) c = ⌊(m₂ + 2)/12⌋
(Eq. 277) m = m₂ − 12c + 3
(Eq. 278) j = j₂ + c
m₂ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
c | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
m | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 1 | 2 |
j | j₂ | j₂ | j₂ | j₂ | j₂ | j₂ | j₂ | j₂ | j₂ | j₂ | j₂+1 | j₂+1 |
If we use a flat combination of the calendar levels, then the lower calendar (days-months) starts over for every year in the upper calendar (days-years). The last month of the calculation year is then cut short by the upper calendar, so then it does not matter if that last month would contain too many days if it weren't cut short. Then we can give all calendar months 30 or 31 days, which makes the calculations a lot simpler.
The month lengths from March through January are 31 - 30 - 31 - 30 -
31 - 31 - 30 - 31 - 30 - 31 - 31. We get this sequence of month
lengths if we use calendar type 2 from section 5.10 with
f = 153, g = 5, a = 4 so s = fa mod g = 153×4
mod 5 = 2. In that calendar, February gets 30 days, but that
is cut short to 28 or 29 days by the upper calendar.
That upper calendar should yield 365 - 365 - 365 - 366 days and repeat
that every 4 years. We get that sequence of year lengths if we use
calendar type 1 with f = 1461, g = 4.
The first day of calculation year 0, i.e. 1 March of the year 0 in the
Julian calendar, has CJDN J₀ = 1721118.
The steps to get from the Julian calendar to the CJDN are now:
Calculate calculation year number x₂, calculation month
number x₁, and calculation day number z₁
from the year number j, month number m,
and day number d. The first time period for each unit
of time (calculation year, calculation month, calculation day) must
have number 0, otherwise the calculations don't give the right
results.
(Eq. 279) c₀ = ⌊(m − 3)/12⌋
(Eq. 280) x₂ = j + c₀
(Eq. 281) x₁ = m − 12c₀ − 3
(Eq. 282) z₁ = d − 1
We combine the two calendar levels in the flat manner, so z₂ =
y₁:
(Eq. 283) c₁ = ⌊(153x₁ + 2)/5⌋
(Eq. 284) y₁ = c₁ + z₁
(Eq. 285) z₂ = y₁
(Eq. 286) c₂ = ⌊1461x₂/4⌋
(Eq. 287) y₂ = c₂ + z₂
Add the CJDN of running day number 0:
(Eq. 288) J = y₂ + J₀ = y₂ + 1721118
For example, what CJDN corresponds to Julian date 6 July 2003? Then
j = 2003, m = 7, d = 6, and thus c₀ = ⌊(7 −
3)/12⌋ = 0, x₁ = 7 − 12×0 − 3 = 4, x₂ = 2003 + 0 = 2003, z₁ = 6 − 1 =
5. Then we find c₁ = ⌊(153×4 + 2)/5⌋ = ⌊614⁄5⌋ =
122, y₁ = 122 + 5 = 127, z₂ =
127, c₂ = ⌊1461×2003⁄4⌋ = ⌊2926383⁄4⌋ = 731595,
y₂ = 731595 + 127 = 731722, and finally J =
731722 + 1721118 = 2452840.
Another example. What CJDN corresponds to Julian date 1 December
2000? Then j = 2000, m = 12, d = 1, so c₀ =
⌊(12 − 3)/12⌋ = 0, x₁ = 12 − 12×0 − 3 = 9, x₂ = 2000 + 0 = 2000, z₁ =
1 − 1 = 0. Then we find c₁ = ⌊(153×9 + 2)/5⌋ =
⌊1379⁄5⌋ = 275, y₁ = 275 + 0 = 275, z₂ =
275, c₂ = ⌊1461×2000⁄4⌋ = ⌊2922000⁄4⌋ = 730500,
y₂ = 730500 + 275 = 730775, so J = 730775 +
1721118 = 2451893.
We can combine and squeeze these steps into:
(Eq. 289) c₀ = ⌊(m − 3)/12⌋
(Eq. 290) J = ⌊1461×(j + c₀)/4⌋ + ⌊(153m − 1836c₀ − 457)/5⌋ + d + 1721117
For the
same example as above we find j = 2003, m = 7, d =
6 so c₀ = ⌊(7 − 3)/12⌋ =
0, J = ⌊1461×(2003 + 0)/4⌋ + ⌊(153×7 − 1836×0 − 457)/5⌋
+ 6 + 1721117 = ⌊2926383⁄4⌋ + ⌊614⁄5⌋ + 6 + 1721117 = 731595 + 122 + 6
+ 1721117 = 2452840, the same answer as before.
We run through the opposite procedure from the one described above,
with the same calendar levels as above. Calendar level 1 is of
calendar type 2 with f = 153, g = 5, a = 4 (so s
= fa mod g = 153×4 mod 5 = 2), and calendar level 2 is of
calendar type 1 with f = 1461, g = 4.
First we calculate the running day number from the Julian Day Number, by subtracting the Julian Day Number of running day number 0:
(Eq. 291) y₂ = J − J₀ = J − 1721118
Then we calculate the calculation year, calculation month, and calculation day from the running day number, in the flat manner:
%ignore>
(Eq. 292) k₂ = 4y₂ + 3
(Eq. 293) x₂ = ⌊k₂/1461⌋
(Eq. 294) z₂ = ⌊(k₂ mod 1461)/4⌋
(Eq. 295) y₁ = z₂
(Eq. 296) k₁ = 5y₁ + 2
(Eq. 297) x₁ = ⌊k₁/153⌋
(Eq. 298) z₁ = ⌊(k₁ mod 153)/5⌋
And lastly we translate these calculation values to calendar values:
(Eq. 299) c₀ = ⌊(x₁ + 2)/12⌋
(Eq. 300) j = x₂ + c₀
(Eq. 301) m = x₁ − 12c₀ + 3
(Eq. 302) d = z₁ + 1
For example, which Julian Date corresponds to Julian Day number
2452840? Then J = 2452840 so y₂ = 2452840 −
1721118 = 731722, k₂ = 4×731722 + 3 = 2926891,
x₂ = ⌊k₂/1461⌋ = ⌊2926891⁄1461⌋ = 2003, z₂ =
⌊(k₂ mod 1461)/4⌋ = ⌊(2926891 mod 1461)/4⌋ = ⌊508⁄4⌋ = 127,
y₁ = 127, k₁ = 5×127 + 2 = 637,
x₁ = ⌊k₁/153⌋ = ⌊637⁄153⌋ = 4, z₁ = ⌊(k₁ mod
153)/5⌋ = ⌊(637 mod 153)/5⌋ = ⌊25⁄5⌋ = 5, c₀ = ⌊(4 +
2)/12⌋ = 0, and so j = 2003 + 0 = 2003,
m = 4 − 12×0 + 3 = 7, d = 5 + 1 = 6.
The date is July 6th, 2003.
Which Julian date corresponds to CJDN 2451893? Then J =
2451893 so y₂ = 2451893 − 1721118 = 730775,
k₂ = 4×730775 + 3 = 2923103, x₂ = ⌊k₂/1461⌋ =
⌊2923103⁄1461⌋ = 2000, z₂ = ⌊(k₂ mod 1461)/4⌋ =
⌊(2923103 mod 1461)/4⌋ = ⌊1103⁄4⌋ = 275, y₁ =
275, k₁ = 5×275 + 2 = 1377, x₁ =
⌊k₁/153⌋ = ⌊1377⁄153⌋ = 9, z₁ = ⌊(k₁ mod 153)/4⌋ =
⌊(1377 mod 153)/4⌋ = 0, c₀ = ⌊(9 + 2)/12⌋ = ⌊11⁄12⌋ =
0, en j = 2000 + 0 = 2000, m = 9 − 12×0
+ 3 = 12, d = 0 + 1 = 1. The date is 1
December 2000.
And which Julian date corresponds to CJDN 173? Then J =
173 and y₂ = 173 − 1721118 = −1720945,
k₂ = 4×−1720945 + 3 = −6883777, x₂ = ⌊k₂/1461⌋ =
⌊−6883777⁄1461⌋ = −4712, z₂ = ⌊(k₂ mod 1461)/4⌋ =
⌊(−6883777 mod 1461)/4⌋ = ⌊455⁄4⌋ = 113, y₁ =
113, k₁ = 5×113 + 2 = 567, x₁ = ⌊k₁/153⌋
= ⌊567⁄153⌋ = 3, z₁ = ⌊(k₁ mod 153)/5⌋ = ⌊(567 mod
153)/5⌋ = ⌊108⁄5⌋ = 21, c₁ = ⌊(153×3 + 2)/5⌋ = ⌊461⁄5⌋
= 92, z₁ = 113 − 92 = 21, c₀ = ⌊(3 +
2)/12⌋ = 0, so j = −4712 + 0 = −4712, m = 3 − 12×0 + 3
= 6, d = 21 + 1 = 22. The date is 22 June −4712.
We can combine and compress these a bit, to
(Eq. 303) y₂ = J − 1721118
(Eq. 304) k₂ = 4y₂ + 3
(Eq. 305) k₁ = 5⌊(k₂ mod 1461)/4⌋ + 2
(Eq. 306) x₁ = ⌊k₁/153⌋
(Eq. 307) c₀ = ⌊(x₁ + 2)/12⌋
(Eq. 308) j = ⌊k₂/1461⌋ + c₀
(Eq. 309) m = x₁ − 12c₀ + 3
(Eq. 310) d = ⌊(k₁ mod 153)/5⌋ + 1
Which Julian date corresponds to CJDN 2451893? Then J =
2451893 so y₂ = 2451893 − 1721118 = 730775,
k₂ = 4×730775 + 3 = 2923103, k₁ = 5⌊(2923103
mod 1461)/4⌋ + 2 = 5⌊1103⁄4⌋ + 2 = 5×275 + 2 = 1377,
x₁ = ⌊1377⁄153⌋ = 9, c₀ = ⌊(9 + 2)/12⌋ = ⌊11⁄12⌋
= 0, and j = ⌊2923103⁄1461⌋ + 0 = 2000 + 0 =
2000, m = 9 − 12×0 + 3 = 12, d = ⌊(1377
mod 153)/5⌋ + 1 = ⌊0⁄5⌋ + 1 = 1. The date is 1 December
2000.
We can also use a stepped combination of calendars; then we need a
calendar level between a running month number x and a
running day number y, 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.
First we calculate the running month number y₁ from the
year x₁ and the month number z₁ within
the year. The formula is very simple:
(Eq. 311) y₁ = 12x₁ + z₁
At the second calendar level, we must calculate a running day number
from the running month number. Of the 12 months of a year, 7 are
long, with 31 days each, so we need a formula ⌊7×(x₂ +
a)/12⌋ (which repeats itself every 12 months), but what should
be the value of a?
If a = 0, then ⌊7x₂/12⌋ yields the values
(for x₂ from 0 through 12): 0 0 1 1 2 2 3 4 4 5 5 6 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. We get that if we shift the pattern by −1 month
(one to the left), so a = −1. Then s = fa mod
g = −7 mod 12 = 5, so we find ⌊(7x₂ + 5)/12⌋.
Then all months are good, except for February (x₂ = 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⌊(x₂ + 10)/12⌋. We add 1
day back in for the first of every four years by using ⌊(x₂ +
46)/48⌋. All in all we find
(Eq. 312) c₂ = 30x₂ + ⌊(7x₂ + 5)/12⌋ − 2⌊(x₂ + 10)/12⌋ + ⌊(x₂ +
46)/48⌋
This is calendar type 4, but for calculating in the opposite direction
it is better if all fractions use the same numerator. The least
common multiple of the numerators 12, 12, and 48 is 48, so we use
g = 48. Then
(Eq. 313) c₂ = 30x₂ + ⌊(28x₂ + 20)/48⌋ − 2⌊(4x₂ + 40)/48⌋ + ⌊(x₂ +
46)/48⌋
which means calendar type 4 with q = 30, g = 48, {d₁,h₁,s₁} =
{1,28,20}, {d₂,h₂,s₂} = {−2,4,40}, {d₃,h₃,s₃} = {1,1,46}.
Then the procedure is
Translate the year j, month m, day
d to calculation year x₁, calculation
month z₁, and calculation day z₂. The
number of the first calculation year/month/day must be 0, otherwise
the calculations don't give the right results.
(Eq. 314) x₁ = j
(Eq. 315) z₁ = m − 1
(Eq. 316) z₂ = d − 1
The CJDN J₀ that corresponds to {x₁,z₁,z₂} =
{0,0,0}, i.e., 1 January of the year 0 (in the Julian
calendar) is 1721058.
Combine the calendar levels in the stepped fashion, i.e., x₂ =
y₁:
(Eq. 317) c₁ = 12x₁
(Eq. 318) y₁ = c₁ + z₁
(Eq. 319) x₂ = y₁
(Eq. 320) c₂ = 30x₂ + ⌊(28x₂ + 20)/48⌋ − 2⌊(4x₂ + 40)/48⌋ + ⌊(x₂ +
46)/48⌋
(Eq. 321) y₂ = c₂ + z₂
Add the CJDN of running day number 0:
(Eq. 322) J = y₂ + J₀ = y₂ + 1721058
For example, what CJDN corresponds to Julian date July 6th, 2003?
Then j = 2003, m = 7, d = 6, so x₁ = 2003, z₁ =
6, z₂ = 5. Then we find c₁ = 12×2003 = 24036,
y₁ = 24036 + 6 = 24042, x₂ = 24042,
c₂ = 30×24042 + ⌊(28×24042 + 20)/48⌋ − 2×⌊(4×24042 + 40)/48⌋ +
⌊(24042 + 46)/48⌋ = 721260 + ⌊673196⁄48⌋ − 2×⌊96208⁄48⌋ + ⌊24088⁄48⌋ =
721260 + 14024 − 2×2004 + 501 = 731777, y₂ = 731777 + 5
= 731782, and finally J = 731782 + 1721058 =
2452840.
We can combine the above formulas to
(Eq. 323) c = 12j + m
(Eq. 324) J = 30c + ⌊(7c − 2)/12⌋ − 2⌊(c + 9)/12⌋ + ⌊(c + 45)/48⌋ + d +
1721027
For example, what CJDN corresponds to Julian date July 6th, 2003?
Then j = 2003, m = 7, d = 6, so c =
12×2003 + 7 = 24043, J = 30×24043 + ⌊(7×24043 − 2)/12⌋ − 2⌊(24043 +
9)/12⌋ + ⌊(24043 + 45)/48⌋ + 6 + 1721027 = 721290 + ⌊168299⁄12⌋ −
2⌊24052⁄12⌋ + ⌊24088⁄48⌋ + 6 + 1721027 = 721290 + 14024 − 2×2004 + 501
+ 6 + 1721027 = 2452840.
We run through the above procedure in the opposite direction.
Calculate the running day number y₂ by subtracting the
CJDN of running day number 0 from the Julian Day number
J:
(Eq. 325) y₂ = J − J₀ = J − 1721058
With q = 30, g = 48, {d₁,h₁,s₁} = {1,28,20}, {d₂,h₂,s₂} =
{−2,4,40}, {d₃,h₃,s₃} = {1,1,46} we have f = qg +
∑dihi = 30×48 + 1×28 − 2×4 + 1×1 = 1461, so the average
month length is f/g = 1461⁄48 = 487⁄16 = 30 + 7⁄16
days. Also ∑disi = 1×20 − 2×40 + 1×46 = −14 and
∑(>0)di = 2 and so
(Eq. 326) g∑(>0)di − ∑i di si − 1 = 48×2 − (−14) − 1 =
109
Translate to calculation year x₁, calculation month
z₁, and calculation day z₂:
(Eq. 327) x₂ = c'₂(y₂) = ⌊(48y₂ + 109)/1461⌋
(Eq. 328) c₂ = 30x₂ + ⌊(28x₂ + 20)/48⌋ − 2⌊(4x₂ + 40)/48⌋ + ⌊(x₂ +
46)/48⌋ = 30x₂ + ⌊(7x₂ + 5)/12⌋ − 2⌊(x₂ + 10)/12⌋ + ⌊(x₂ +
46)/48⌋
(Eq. 329) z₂ = y₂ − c₂
(Eq. 330) ζ = ⌊z₂/32⌋
(Eq. 331) x₂ → x₂ + ζ
(Eq. 332) c₂ → 30x₂ + ⌊(28x₂ + 20)/48⌋ − 2⌊(4x₂ + 40)/48⌋ + ⌊(x₂ +
46)/48⌋ = 30x₂ + ⌊(7x₂ + 5)/12⌋ − 2⌊(x₂ + 10)/12⌋ + ⌊(x₂ +
46)/48⌋
(Eq. 333) z₂ → y₂ − c₂
(Eq. 334) y₁ = x₂
(Eq. 335) x₁ = c'₁(y₁) = ⌊y₁/12⌋
(Eq. 336) c₁ = 12x₁
(Eq. 337) z₁ = y₁ − c₁
Then translate to calendar year j, calendar month
m, and calendar day d:
(Eq. 338) j = x₁
(Eq. 339) m = z₁ + 1
(Eq. 340) d = z₂ + 1
For example, what Julian Date corresponds to CJDN 2452840? Then
J = 2452840, so y₂ = 2452840 − 1721058 =
731782, x₂ = ⌊(48×731782 + 81)/1461⌋ = ⌊35125617⁄1461⌋
= 24042, c₂ = 30×24042 + ⌊(28×24042 + 20)/48⌋ −
2×⌊(4×24042 + 40)/48⌋ + ⌊(24042 + 46)/48⌋ = 721260 + ⌊673196⁄48⌋ −
2×⌊96208⁄48⌋ + ⌊24088⁄48⌋ = 721260 + 14024 − 4008 + 501 =
731777, z₂ = 731782 − 731777 = 5, ζ =
⌊5⁄32⌋ = 0. Because ζ = 0, the x₂, c₂,
z₂ remain unchanged. Then y₁ = 24042,
x₁ = ⌊24042⁄12⌋ = 2003, c₁ = 12×2003 =
24036, and z₁ = 24042 − 24036 = 6. Finally
j = 2003, m = 6 + 1 = 7, and d =
5 + 1 = 6, so the date is July 6th, 2003.
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 129). 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:
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.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.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.p = f/g =
146097⁄4. This yields 3 sequences of 36524 days and 1
sequence of 36525 days, and that fits the Gregorian Calendar.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₀ = 1721120. We
then use three calendar levels, with the following values:
i | fi | gi | ai | si |
|---|---|---|---|---|
| 1 | 153 | 5 | 4 | 2 |
| 2 | 36525 | 100 | 0 | 0 |
| 3 | 146097 | 4 | 0 | 0 |
The steps to get from the Gregorian calendar to the CJDN are now:
Calculate calculation century number x₃, calculation
year number x₂, calculation month number
x₁, and calculation day number z₁ from
the year number j, month number m, and
day number d
(Eq. 341) c₀ = ⌊(m − 3)/12⌋
(Eq. 342) x₄ = j + c₀
(Eq. 343) x₃ = ⌊x₄/100⌋
(Eq. 344) x₂ = x₄ mod 100 = x₄ − 100x₃
(Eq. 345) x₁ = m − 12c₀ − 3
(Eq. 346) z₁ = d − 1
We combine the two calendar levels in the flat manner, so z₂ =
y₁ and z₃ = y₂:
(Eq. 347) c₁ = ⌊(153x₁ + 2)/5⌋
(Eq. 348) y₁ = c₁ + z₁
(Eq. 349) z₂ = y₁
(Eq. 350) c₂ = ⌊36525x₂/100⌋
(Eq. 351) y₂ = c₂ + z₂
(Eq. 352) z₃ = y₂
(Eq. 353) c₃ = ⌊146097x₃/4⌋
(Eq. 354) y₃ = c₃ + z₃
Add the CJDN of running day number 0:
(Eq. 355) J = y₃ + J₀ = y₃ + 1721120
Combined and condensed, this yields:
(Eq. 356) c₀ = ⌊(m − 3)/12⌋
(Eq. 357) x₄ = j + c₀
(Eq. 358) x₃ = ⌊x₄/100⌋
(Eq. 359) x₂ = x₄ mod 100
(Eq. 360) x₁ = m − 12c₀ − 3
(Eq. 361) J = ⌊146097x₃/4⌋ + ⌊36525x₂/100⌋ + ⌊(153x₁ + 2)/5⌋ + d +
1721119
For example, which Julian Day number corresponds to Gregorian date
July 6th, 2003? Then j = 2003, m = 7, d = 6 and then
c₀ = ⌊(7 − 3)/12⌋ = 0, x₄ = 2003 + 0 = 2003, x₃ = ⌊2003⁄100⌋ =
20, x₂ = 2003 mod 100 = 3, x₁ = 7 − 12×0 − 3 = 4, J = ⌊146097×20⁄4⌋ +
⌊36525×3⁄100⌋ + ⌊(153×4 + 2)/5⌋ + 6 + 1721119 = 730485 + 1095 + 122 +
6 + 1721119 = 2452827.
Now we go in the opposite direction again, with the same three calendar levels as before.
First we subtract the CJDN of running day number 0 from the CJDN to get the running day number:
(Eq. 362) y₃ = J − J₀ = J − 1721120
Then we translate the running day number in the flat manner into a calculation century, calculation year, calculation month, and calculation day:
%ignore>
(Eq. 363) k₃ = 4y₃ + 3
(Eq. 364) x₃ = ⌊k₃/146097⌋
(Eq. 365) z₃ = ⌊(k₃ mod 146097)/4⌋
(Eq. 366) y₂ = z₃
(Eq. 367) k₂ = 100y₂ + 99
(Eq. 368) x₂ = ⌊k₂/36525⌋
(Eq. 369) z₂ = ⌊(k₂ mod 36525)/100⌋
(Eq. 370) y₁ = z₂
(Eq. 371) k₁ = 5y₁ + 2
(Eq. 372) x₁ = ⌊k₁/153⌋
(Eq. 373) z₁ = ⌊(k₁ mod 153)/5⌋
And lastly we translate to day-month-year:
(Eq. 374) c₀ = ⌊(x₁ + 2)/12⌋
(Eq. 375) j = 100×x₃ + x₂ + c₀
(Eq. 376) m = x₁ − 12c₀ + 3
(Eq. 377) d = z₁ + 1
For example, which date in the Gregorian calendar corresponds to CJDN
2452827? Then J = 2452827 and then y₃ = J −
1721120 = 731707, k₃ = 4×731707 + 3 = 2926831,
x₃ = ⌊2926831⁄146097⌋ = 20, z₃ = ⌊(2926831 mod
146097)/4⌋ = ⌊4891⁄4⌋ = 1222, y₂ = 1222,
k₂ = 100×1222 + 99 = 122299, x₂ = ⌊122299⁄36525⌋
= 3, z₂ = ⌊(122299 mod 36525)/100⌋ = ⌊12724⁄100⌋ =
127, y₁ = 127, k₁ = 5×127 + 2 =
637, x₁ = ⌊637⁄153⌋ = 4, z₁ = ⌊(637 mod
153)/5⌋ = ⌊25⁄5⌋ = 5, and then c₀ = ⌊(4 + 2)/12⌋ =
0, j = 100×20 + 3 + 0 = 2003, m = 4 −
12×0 + 3 = 7, d = 5 + 1 = 6. The date is July
6th, 2003.
This condenses a little bit, to:
%ignore>
(Eq. 378) k₃ = 4×(J − 1721120) + 3
(Eq. 379) x₃ = ⌊k₃/146097⌋
(Eq. 380) k₂ = 100⌊(k₃ mod 146097)/4⌋ + 99
(Eq. 381) x₂ = ⌊k₂/36525⌋
(Eq. 382) x₁ = ⌊(5⌊(k₂ mod 36525)/100⌋ + 2)/153⌋
(Eq. 383) c₀ = ⌊(x₁ + 2)/12⌋
(Eq. 384) j = 100×x₃ + x₂ + c₀
(Eq. 385) m = x₁ − 12c₀ + 3
(Eq. 386) d = ⌊(k₁ mod 153)/5⌋ + 1
For example, which date in the Gregorian calendar corresponds to CJDN
2452827? Then J = 2452827 and then k₃ =
4×(2452827 − 1721120) + 3 = 2926831, x₃ =
⌊2926831⁄146097⌋ = 20, k₂ = 100⌊(2926831 mod
146097)/4⌋ + 99 = 100⌊4891⁄4⌋ + 99 = 100×1222 + 99 = 122299,
x₂ = ⌊122299⁄36525⌋ = 3, x₁ = ⌊(5⌊(122299 mod
36525)/100⌋ + 2)/153⌋ = ⌊(5⌊12724⁄100⌋ + 2)/153⌋ = ⌊(5×127 + 2)/153⌋ =
⌊637⁄153⌋ = 4, and then c₀ = ⌊(4 + 2)/12⌋ = 0,
j = 100×20 + 3 + 0 = 2003, m = 4 − 12×0 + 3 =
7, d = 5 + 1 = 6. The date is July 6th, 2003.
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,
(Eq. 387) q = 365, g = 400, {d₁,h₁,s₁} = {1,100,0}, {d₂,h₂,s₂} =
{−1,4,0}, {d₃,h₃,s₃} = {1,1,0}
The lower calendar level is the same as before, so
(Eq. 388) c₃ = ⌊(m − 3)/12⌋
(Eq. 389) x₂ = j + c₃
(Eq. 390) x₁ = m − 12c₃ − 3
(Eq. 391) z₁ = d − 1
(Eq. 392) c₁ = ⌊(153x₁ + 2)/5⌋
(Eq. 393) y₁ = c₁ + z₁
(Eq. 394) z₂ = y₁
(Eq. 395) c₂ = 365x₂ + ⌊100x₂/400⌋ − ⌊4x₂/400⌋ + ⌊x₂/400⌋ = 365x₂ +
⌊x₂/4⌋ − ⌊x₂/100⌋ + ⌊x₂/400⌋
(Eq. 396) y₂ = c₂ + z₂
(Eq. 397) J = y₂ + J₀ = y₂ + 1721120
For example, which CJDN corresponds to Gregorian date July 6th, 2003?
Then j = 2003, m = 7, d = 6, so c₃ = ⌊(7 −
3)/12⌋ = 0, x₁ = 7 − 12×0 − 3 = 4, x₂ = 2003 + 0 = 2003, z₁ = 6 − 1 =
5, and then c₁ = ⌊(153×4 + 2)/5⌋ = ⌊614⁄5⌋ =
122, y₁ = 122 + 5 = 127, z₂ =
127, c₂ = 365×2003 + ⌊100×2003⁄400⌋ − ⌊4×2003⁄400⌋ +
⌊2003⁄400⌋ = 731095 + ⌊200300⁄400⌋ − ⌊8012⁄400⌋ + 5 = 731095 + 500 −
20 + 5 = 731580, y₂ = 731580 + 127 = 731707,
and finally J = 731707 + 1721120 = 2452827.
This condenses to:
(Eq. 398) c₃ = ⌊(m − 3)/12⌋
(Eq. 399) x₂ = j + c₃
(Eq. 400) x₁ = m − 12c₃ − 3
(Eq. 401) J = 365x₂ + ⌊x₂/4⌋ − ⌊x₂/100⌋ + ⌊x₂/400⌋ + ⌊(153x₁ + 2)/5⌋ + d
+ 1721119
With the upper calendar of type 4, we go in the opposite direction, again with
q = 365, g = 400, {d₁,h₁,s₁} = {1,100,0}, {d₂,h₂,s₂} =
{−1,4,0}, {d₃,h₃,s₃} = {1,1,0}
Then
(Eq. 402) f = qg + ∑dihi = 365×400 + 1×100 − 1×4 + 1×1 =
146097
so the average length of the year is f/g = 146097⁄400 = 365 +
97⁄400 days.
First we calculate the running day number from the CJDN, by subtracting the CJDN of running day number 0:
(Eq. 403) y₂ = J − J₀ = J − 1721120
Then we calculate the calculation year, calculation month, and calculation day from the running day number, in the flat manner:
(Eq. 404) x₂ = c'₂(y₂) = ⌊(400y₂ + 799)/146097⌋
(Eq. 405) c₂ = 365x₂ + ⌊100x₂/400⌋ − ⌊4x₂/400⌋ + ⌊x₂/400⌋ = 365x₂ +
⌊x₂/4⌋ − ⌊x₂/100⌋ + ⌊x₂/400⌋
(Eq. 406) z₂ = y₂ − c₂
(Eq. 407) ζ = ⌊z₂/367⌋
(Eq. 408) x₂ → x₂ + ζ
(Eq. 409) c₂ → 365x₂ + ⌊100x₂/400⌋ − ⌊4x₂/400⌋ + ⌊x₂/400⌋ = 365x₂ +
⌊x₂/4⌋ − ⌊x₂/100⌋ + ⌊x₂/400⌋
(Eq. 410) z₂ → y₂ − c₂
(Eq. 411) y₁ = z₂
(Eq. 412) x₁ = c'₁(y₁) = ⌊(5y₁ + 2)/153⌋
(Eq. 413) c₁ = ⌊(153x₁ + 2)/5⌋
(Eq. 414) z₁ = y₁ − c₁
And lastly we translate these calculation values to calendar values:
(Eq. 415) c₀ = ⌊(x₁ + 2)/12⌋
(Eq. 416) j = x₂ + c₄
(Eq. 417) m = x₁ − 12c₀ + 3
(Eq. 418) d = z₁ + 1
For example, which date in the Gregorian calendar corresponds to CJDN
2452827? Then J = 2452827 and then y₂ = J −
1721120 = 731707, x₂ = ⌊(400×731707 + 799)/146097⌋ =
⌊292683599⁄146097⌋ = 2003, c₂ = 365×2003 +
⌊100×2003⁄400⌋ − ⌊4×2003⁄400⌋ + ⌊2003⁄400⌋ = 731095 + ⌊200300⁄400⌋ −
⌊8012⁄400⌋ + 5 = 731095 + 500 − 20 + 5 = 731580, z₂ =
731707 − 731580 = 127, ζ = ⌊127⁄367⌋ = 0.
ζ = 0, so x₂, c₂, z₂ remain the same.
Then y₁ = 127, x₁ = ⌊(5×127 + 2)/153⌋ =
⌊637⁄153⌋ = 4, c₁ = ⌊(153×4 + 2)/5⌋ = ⌊614⁄5⌋ =
122, z₁ = 127 − 122 = 5. Then c₀ = ⌊(4
+ 2)/12⌋ = 0, j = 2003 + 0 = 2003, m = 4
− 12×0 + 3 = 7, d = 5 + 1 = 6. The date is
July 6th, 2003.
The numerator of x₂ can get very large in this
algorithm: In the example it was equal to 292,683,599 for a date in
the year 2003. If you use this algorithm in a computer program that
uses values of 4 bytes large, then x₂ will get too
large for dates more than 14,698 years from Julian Day number 0, i.e.,
from the year 9986. Section 5.1 explains how to find a
solution for this. Such a solution is to replace formula
with
(Eq. 419) q = ⌊y₂/1461⌋
(Eq. 420) r = y₂ mod 1461
(Eq. 421) x₂ = 4q + ⌊(12q + 400r + 799)/146097⌋
For example, when y₂ = 9,000,000, then x₂ =
⌊(400×9000000 + 799)/146097⌋ = ⌊3600000799⁄146097⌋ = 24641.
The greatest intermediate result is 3,600,000,799, which exceeds the
greatest value (2,147,483,648) that fits a 4-byte value. With the
alternative,w e find q = ⌊9000000⁄1461⌋ = 6160, r = 9000000
mod 1461 = 240, x₂ = 4×6160 + ⌊(12×6160 + 400×240 + 799)/146097⌋ =
24640 + ⌊170719⁄146097⌋ = 24640 + 1 = 24641. Now the greatest
intermediate result was 170719, which comfortably fits a 4-byte value.
Net als voor de Juliaanse kalender kunnen we een getrapte combinatie van kalenderniveaus gebruiken. Vergeleken met de Juliaanse kalender moeten we de schrikkelregels voor elke 100 jaar en elke 400 jaar er nog bij stoppen:
Just like for the Julian calendar we can use a stepped combination of calendar levels. Compared to the Julian calendar we have to add the leap year rules for each 100 years and for each 400 years:
(Eq. 422) c₂ = 30x₂ + ⌊(7x₂ + 5)/12⌋ − 2⌊(x₂ + 10)/12⌋ + ⌊(x₂ +
46)/48⌋ − ⌊(x₂ + 1198)/1200⌋ + ⌊(x₂ + 4798)/4800⌋
Here, too, we want to have all denominators be equal; then we get
(Eq. 423) c₂ = 30x₂ + ⌊(2800x₂ + 2000)/4800⌋ − 2⌊(400x₂ + 4000)/12⌋ + ⌊(100x₂ +
4600)/4800⌋ − ⌊(4x₂ + 4792)/4800⌋ + ⌊(x₂ + 4798)/4800⌋
which means calendar type 4 with q = 30, g = 4800, {d₁,h₁,s₁} =
{1,2800,2000}, {d₂,h₂,s₂} = {−2,400,4000}, {d₃,h₃,s₃} = {1,100,4600},
{d₄,h₄,s₄} = {−1,4,4792}, {d₅,h₅,s₅} = {1,1,4798}.
The CJDN J₀ that corresponds to {x₁,z₁,z₂} =
{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
(Eq. 424) x₁ = j₀
(Eq. 425) z₁ = m − 1
(Eq. 426) z₂ = d − 1
(Eq. 427) c₁ = 12x₁
(Eq. 428) y₁ = c₁ + z₁
(Eq. 429) x₂ = y₁
(Eq. 430) c₂ = 30x₂ + ⌊(2800x₂ + 2000)/4800⌋ − 2⌊(400x₂ + 4000)/4800⌋ +
⌊(100x₂ + 4600)/4800⌋ − ⌊(4x₂ + 4792)/4800⌋ + ⌊(x₂ +
4798)/4800⌋ = 30x₂ + ⌊(7x₂ + 5)/12⌋ − 2⌊(x₂ + 10)/12⌋ + ⌊(x₂ +
46)/48⌋ − ⌊(x₂ + 1198)/1200⌋ + ⌊(x₂ + 4798)/4800⌋
(Eq. 431) y₂ = c₂ + z₂
(Eq. 432) J = y₂ + J₀ = y₂ + 1721060
For example, which CJDN corresponds to Gregorian date July 6th, 2003?
Then j = 2003, m = 7, d = 6, so x₁ = 2003, z₁ =
7 − 1 = 6, z₂ = 6 − 1 = 5, and then c₁ = 12×2003 =
24036, y₁ = 24036 + 6 = 24042, x₂ =
24042, c₂ = 30×24042 + ⌊(2800×24042 + 2000)/4800⌋ −
2×⌊(400×24042 + 4000)/4800⌋ + ⌊(100×24042 + 4600)/4800⌋ − ⌊(4×24042 +
4792)/4800⌋ + ⌊(24042 + 4798)/4800⌋ = 721260 + ⌊67319600⁄4800⌋ −
2×⌊9620800⁄4800⌋ + ⌊2408800⁄4800⌋ − ⌊100960⁄4800⌋ + ⌊28840⁄4800⌋ =
721260 + 14024 − 4008 + 501 − 21 + 6 = 731762, y₂ =
731762 + 5 = 731767, and finally J = 731767 + 1721060 =
2452827.
We can combine the above formulas into
(Eq. 433) c = 12×j + m
(Eq. 434) J = 30c + ⌊(7c − 2)/12⌋ − 2⌊(c +
9)/12⌋ + ⌊(c + 45)/48⌋ − ⌊(c + 1197)/1200⌋ + ⌊(c + 4797)/4800⌋ + d +
1721029
We run through the same procedure as in the previous section, but in the opposite direction.
Calculate the running day number y₂ by subtracting the
CJDN of running day number 0 from CJDN J.
(Eq. 435) y₂ = J − J₀ = J − 1721060
With q = 30, g = 4800, {d₁,h₁,s₁} = {1,2800,2000}, {d₂,h₂,s₂} =
{−2,400,4000}, {d₃,h₃,s₃} = {1,100,4600}, {d₄,h₄,s₄} = {−1,4,4792},
{d₅,h₅,s₅} = {1,1,4798} we have f = qg + ∑dihi =
30×4800 + 1×2800 − 2×400 + 1×100 − 1×4 + 1×1 = 146097, so the
average month length is f/g = 146097⁄4800 = 30 +
699⁄1600 days. Also, ∑disi = 1×2000 − 2×4000 +
1×4600 − 1×4792 + 1×4798 = −1394.
Translate to calculation year x₁, calculation month
z₁, and calculation day z₂:
(Eq. 436) x₂ = c'₂(y₂) = ⌊(4800y₂ + 15793)/146097⌋
(Eq. 437) c₂ = 30x₂ + ⌊(2800x₂ + 2000)/4800⌋ − 2⌊(400x₂ + 4000)/4800⌋ +
⌊(100x₂ + 4600)/4800⌋ − ⌊(4x₂ + 4792)/4800⌋ + ⌊(x₂ +
4798)/4800⌋ = 30x₂ + ⌊(7x₂ + 5)/12⌋ − 2⌊(x₂ + 10)/12⌋ + ⌊(x₂ +
46)/48⌋ − ⌊(x₂ + 1198)/1200⌋ + ⌊(x₂ + 4798)/4800⌋
(Eq. 438) z₂ = y₂ − c₂
(Eq. 439) ζ = ⌊z₂/33⌋
(Eq. 440) x₂ → x₂ + ζ
(Eq. 441) c₂ → 30x₂ + ⌊(2800x₂ + 2000)/4800⌋ − 2⌊(400x₂ + 4000)/4800⌋ +
⌊(100x₂ + 4600)/4800⌋ − ⌊(4x₂ + 4792)/4800⌋ + ⌊(x₂ +
4798)/4800⌋ = 30x₂ + ⌊(7x₂ + 5)/12⌋ − 2⌊(x₂ + 10)/12⌋ + ⌊(x₂ +
46)/48⌋ − ⌊(x₂ + 1198)/1200⌋ + ⌊(x₂ + 4798)/4800⌋
(Eq. 442) z₂ → y₂ − c₂
(Eq. 443) y₁ = x₂
(Eq. 444) x₁ = c'₁(y₁) = ⌊y₁/12⌋
(Eq. 445) c₁ = 12x₁
(Eq. 446) z₁ = y₁ − c₁
Then translate to year j, month m, and
day d:
(Eq. 447) j = x₁
(Eq. 448) m = z₁ + 1
(Eq. 449) d = z₂ + 1
For example, which date in the Gregorian calendar corresponds to CJDN
2452827? Then J = 2452827 and then y₂ = J −
1721060 = 731767, x₂ = ⌊(4800×731767 + 15793)/146097⌋ =
⌊3512497393⁄146097⌋ = 24042, c₂ = 30×24042 +
⌊(2800×24042 + 2000)/4800⌋ − 2×⌊(400×24042 + 4000)/4800⌋ + ⌊(100×24042
+ 4600)/4800⌋ − ⌊(4×24042 + 4792)/4800⌋ + ⌊(24042 + 4798)/4800⌋ =
721260 + ⌊67319600⁄4800⌋ − 2×⌊9620800⁄4800⌋ + ⌊2408800⁄4800⌋ −
⌊100960⁄4800⌋ + ⌊28840⁄4800⌋ = 721260 + 14024 − 4008 + 501 − 21 + 6 =
731762, z₂ = 731767 − 731762 = 5, ζ =
⌊5⁄33⌋ = 0. ζ = 0 so x₂, c₂, z₂
remain the same. Then y₁ = 24042, x₁ =
⌊24042⁄12⌋ = 2003, c₁ = ⌊12×2003⌋ = 24036,
z₁ = 24042 − 24036 = 6. Then j = 2003,
m = 6 + 1 = 7, d = 5 + 1 = 6. The date
is July 6th, 2003.
This can be condensed a bit to
(Eq. 450) y₂ = J − J₀ = J − 1721060
(Eq. 451) x₂ = ⌊(4800y₂ + 15793)/146097⌋
(Eq. 452) c₂ = 30x₂ + ⌊(7x₂ + 5)/12⌋ − 2⌊(x₂ + 10)/12⌋ + ⌊(x₂ + 46)/48⌋ −
⌊(x₂ + 1198)/1200⌋ + ⌊(x₂ + 4798)/4800⌋
(Eq. 453) z₂ = y₂ − c₂
(Eq. 454) ζ = ⌊z₂/33⌋
(Eq. 455) u = x₂ + ζ
(Eq. 456) d = y₂ − (30u + ⌊(7u + 5)/12⌋ − 2⌊(u + 10)/12⌋ + ⌊(u + 46)/48⌋
− ⌊(u + 1198)/1200⌋ + ⌊(u + 4798)/4800⌋) + 1
(Eq. 457) j = ⌊u/12⌋
(Eq. 458) m = u − 12j + 1
In the calculation of x₂, the numerator can get very
large. In a computer program that uses 4-byte values, the calculation
of x₂ will yield wrong results when |y₂|
exceeds about 447,000 (days), which corresponds to only 1224 years.
Section 5.1 explains how to find a solution for this. Such
a solution is to replace the formula for x₂ with
(Eq. 459) q = ⌊y₂/761⌋
(Eq. 460) r = y₂ mod 761
(Eq. 461) x₂ = 25q + ⌊(375q + 4800r + 15793)/146097⌋
For example, if y₂ = 730,000, then x₂ =
⌊(4800×730000 + 15793)/146097⌋ = ⌊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 4 bytes wide. With the alternative method, we find
q = ⌊730000⁄761⌋ = 959, r = 730000 mod 761 = 201, x₂ = 959×25
+ ⌊(959×375 + 4800×201 + 15793)/146097⌋ = 23975 + ⌊1340218⁄146097⌋ =
23975 + 9 = 23984, which is the same result as before, but now
with the greatest intermediate result equal to 1,340,218, which is
comfortably small enough to fit in 4 bytes.
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 = 328718 days. The conversion of a date to CJDN is nearly the same for the Milanković calendar as for the Gregorian calendar (see Section 6.0.5):
(Eq. 462) c₀ = ⌊(m − 3)/12⌋
(Eq. 463) x₄ = j + c₀
(Eq. 464) x₃ = ⌊x₄/100⌋
(Eq. 465) x₂ = x₄ mod 100
(Eq. 466) x₁ = m − 12c₀ − 3
(Eq. 467) J = ⌊(328718x₃ + 6)/9⌋ + ⌊36525x₂/100⌋ + ⌊(153x₁ + 2)/5⌋ + d +
1721119
For example, which CJDN corresponds to Milanković date July 6th, 2003?
Then j = 2003, m = 7, d = 6 hence c₀ = ⌊(7 −
3)/12⌋ = 0, x₄ = 2003 + 0 = 2003, x₃ = ⌊2003⁄100⌋ = 20, x₂ = 2003 −
100×20 = 3, x₁ = 7 − 12×0 − 3 = 4, z₁ = 6 − 1 = 5. Then
c₁ = ⌊(153×4 + 2)/5⌋ = ⌊614⁄5⌋ = 122, y₁ = 122 + 5 = 127, z₂ =
127, c₂ = ⌊36525×3⁄100⌋ = ⌊109575⁄100⌋ = 1095, y₂ = 1095 + 127 = 1222,
z₃ = 1222, c₃ = ⌊(328718×20 + 6)/9⌋ = ⌊6574366⁄9⌋ = 730485, y₃ =
730485 + 1222 = 731707, and then J = 731707 + 1721120 =
2452827.
Also in the opposite direction, we do the same as for the Gregorian
calendar (see Section 6.0.6), except that we use
different formulas to calculate x₃ and
k₃:
(Eq. 468) k₃ = 9×(J − 1721120) + 2
(Eq. 469) x₃ = ⌊k₃/328718⌋
(Eq. 470) k₂ = 100⌊(k₃ mod 328718)/9⌋ + 99
(Eq. 471) x₂ = ⌊k₂/36525⌋
(Eq. 472) k₁ = 5⌊(k₂ mod 36525)/100⌋ + 2
(Eq. 473) x₁ = ⌊k₁/153⌋
(Eq. 474) c₀ = ⌊(x₁ + 2)/12⌋
(Eq. 475) j = 100×x₃ + x₂ + c₀
(Eq. 476) m = x₁ − 12c₀ + 3
(Eq. 477) d = ⌊(k₁ mod 153)/5⌋ + 1
For example, which date in the Gregorian calendar corresponds to CJDN
2452827? Then J = 2452827 en dan k₃ =
9×(2452827 − 1721120) + 2 = 6585365, x₃ = ⌊6585365⁄328718⌋ = 20, k₂ =
100⌊(6585365 mod 328718)/9⌋ + 99 = 100⌊11005⁄9⌋ + 99 = 100×1222 + 99
= 122299, x₂ = ⌊122299⁄36525⌋ = 3, k₁ = 5⌊(122299 mod 36525)/100⌋ + 2
= 5⌊12724⁄100⌋ + 2 = 5×127 + 2 = 637, x₁ = ⌊637⁄153⌋ = 4, c₀ = ⌊(4 +
2)/12⌋ = 0, j = 100×20 + 3 + 0 = 2003, m = 4 − 12×0 + 3 = 7, d = ⌊(637
mod 153)/5⌋ + 1 = ⌊25⁄5⌋ + 1 = 6. The date is July 6th,
2003.
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, i.e., to JD 1448273 (= J₀).
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, with z₂ =
y₁.
For day d of month m of year
j we then find
(Eq. 478) x₂ = j − 1
(Eq. 479) x₁ = m − 1
(Eq. 480) z₁ = d − 1
(Eq. 481) c₁ = 30x₁
(Eq. 482) y₁ = c₁ + z₁
(Eq. 483) z₂ = y₁
(Eq. 484) c₂ = 365x₂
(Eq. 485) y₂ = c₂ + z₂
(Eq. 486) J = y₂ + J₀
This condenses to
(Eq. 487) J = 365×(j − 1) + 30×(m − 1) + d − 1 + J₀ = 365j + 30m + d +
1447877
For example, which CJDN corresponds to day 7 of month 5 of year 218 in
the Egyptian calendar? Then we find x₂ = j − 1 = 218 − 1 =
217, x₁ = m − 1 = 5 − 1 = 4, z₁ = d − 1
= 7 − 1 = 6, c₁ = 30x₁ = 30×4 = 120, z₂
= y₁ = c₁ + z₁ = 120 + 6 = 126, c₂ = 365x₂ = 365×217 =
79205, y₂ = c₂ + z₂ = 79205 + 126 = 79331,
J = y₂ + J₀ = 79331 + 1448273 = 1527604, so the answer
is CJDN 1527604.
With the condensed formula we find J = 365j + 30m + d + 1447877
= 365×218 + 30×5 + 7 + 1447877 = 79570 + 150 + 7 + 1447877 =
1527604, which is the same answer as before.
In the opposite direction, the calculations are simple as well.
(Eq. 488) y₂ = J − J₀
(Eq. 489) x₂ = ⌊y₂/365⌋
(Eq. 490) z₂ = y₂ mod 365
(Eq. 491) y₁ = z₂
(Eq. 492) x₁ = ⌊y₁/30⌋
(Eq. 493) z₁ = y₁ mod 30
(Eq. 494) j = x₂ + 1
(Eq. 495) m = x₁ + 1
(Eq. 496) d = z₁ + 1
This condenses to
(Eq. 497) y₂ = J − J₀
(Eq. 498) x₂ = ⌊y₂/365⌋
(Eq. 499) y₁ = y₂ mod 365
(Eq. 500) j = x₂ + 1
(Eq. 501) m = ⌊y₁/30⌋ + 1
(Eq. 502) d = y₁ − 30m + 31 = (y₁ mod 30) + 1
What date in the Egyptian calendar corresponds
to CJDN 1527604? Then y₂ = J − J₀ = 1527604 − 1448273 =
79331, x₂ = ⌊y₂/365⌋ = ⌊79331⁄365⌋ = 217,
y₁ = z₂ = y₂ mod 365 = 79331 mod 365 = 126, x₁
= ⌊y₁/30⌋ = ⌊126⁄30⌋ = 4, c₁ = 30x₁ = 30×4 =
120, z₁ = y₁ − c₁ = 126 − 120 = 6, j =
x₂ + 1 = 217 + 1 = 218, m = x₁ + 1 = 4 + 1 = 5,
d = z₁ + 1 = 6 + 1 = 7, so it is day 7 of month 5 of year 218.
And with the more condensed formulas:
y₂ = J − J₀ = 1527604 − 1448273 = 79331, x₂ =
⌊y₂/365⌋ = ⌊79331⁄365⌋ = 217, y₁ = y₂ − 365x₂ = 79331 −
365×217 = 79331 − 79205 = 126, j = x₂ + 1 = 217 + 1 =
218, m = ⌊y₁/30⌋ + 1 = ⌊126⁄30⌋ + 1 = 4 + 1 =
5, d = y₁ − 30m + 31 = 126 − 30×5 + 31 = (y₁ mod 30) +
1 = (126 mod 30) + 1 = 6 + 1 = 7,
which is the same result as before.
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. We
go from year number y (the first year has number 1),
month number m (the first month has number 1), and day
number d (the first day has number 1) to running day
number y₂ as follows:
(Eq. 503) x₁ = j − 1
(Eq. 504) z₁ = m − 1
(Eq. 505) z₂ = d − 1
(Eq. 506) c₁ = ⌊(235x₁ + 13)/19⌋
(Eq. 507) y₁ = c₁ + z₁
(Eq. 508) x₂ = y₁
(Eq. 509) c₂ = ⌊6940x₂/235⌋
(Eq. 510) y₂ = c₂ + z₂
(Eq. 511) J = y₂ + 1607558
This can be compressed to
(Eq. 512) y₁ = ⌊(235j − 241)/19⌋ + m
(Eq. 513) J = ⌊6940y₁/235⌋ + d + 1607557
The number of years since the beginning of the current Metonic cycle
is equal to y₁ mod 19.
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 y₁ = ⌊(235×3 − 241)/19⌋ + 9 = ⌊464⁄19⌋ + 9 = 24
+ 9 = 33, J = ⌊6940×33⁄235⌋ + 27 + 1607557 = ⌊229020⁄235⌋ + 1607584 =
974 + 1607584 = 1608558.
Now we go in the opposite direction, from Julian Day number
J to day d, month m, year
j in the era of Seleukos.
(Eq. 514) y₂ = J − 1607558
(Eq. 515) k₂ = 235y₂ + 234
(Eq. 516) x₂ = ⌊k₂/6940⌋
(Eq. 517) z₂ = ⌊(k₂ mod 6940)/235⌋
(Eq. 518) y₁ = x₂
(Eq. 519) k₁ = 19y₁ + 5
(Eq. 520) x₁ = ⌊k₁/235⌋
(Eq. 521) z₁ = ⌊(k₁ mod 235)/19⌋
(Eq. 522) j = x₁ + 1
(Eq. 523) m = z₁ + 1
(Eq. 524) d = z₂ + 1
For example, which date in the Babylonian calendar corresponds to CJDN
1608558? Then J = 1608558, so y₂
= 1608558 − 1607558 = 1000, k₂ = 235×1000 + 234 = 235234, x₂ =
⌊235234⁄6940⌋ = 33, z₂ = ⌊(235234 mod 6940)/235⌋ = ⌊6214⁄235⌋ = 26,
k₁ = 19×33 + 5 = 632, x₁ = ⌊632⁄235⌋ = 2, z₁ = ⌊(632 mod 235)/19⌋ =
⌊162⁄19⌋ = 8, so j = x₁ + 1 = 3, m = z₁ + 1 = 9, d = z₂
+ 1 = 27, which means day 27 of month 9 of year 3.
This can be compressed to
%ignore>
(Eq. 525) k₂ = 235×(J − 1607558) + 234
(Eq. 526) k₁ = 19⌊k₂/6940⌋ + 5
(Eq. 527) j = ⌊k₁/235⌋ + 1
(Eq. 528) m = ⌊(k₁ mod 235)/19⌋ + 1
(Eq. 529) d = ⌊(k₂ mod 6940)/235⌋ + 1
For example, which date in the Babylonian calendar corresponds to CJDN
1608558? Then J = 1608558, so k₂
= 235×(1608558 − 1607558) + 234 = 235234, k₁ = 19×⌊235234⁄6940⌋ + 5 =
19×33 + 5 = 632, so j = ⌊632⁄235⌋ + 1 = 3, m = ⌊(632
mod 235)/19⌋ + 1 = ⌊162⁄19⌋ + 1 = 9, d = ⌊(235234 mod 6940)/235⌋ + 1
= ⌊6214⁄235⌋ + 1 = 27, which means day 27 of month 9 of year
3.
The Jewish calendar is a lunisolar calendar, like the Babylonian calendar. The Jewish calendar is a lot more complicated than the Babylonian one, because
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.
For the calendrical calculations, it is convenient when each calendar
period begins counting at 0. It is therefore inconvenient that the
year number changes at the beginning of the 7th month. We calculate
with a calculation year that begins with the 1st month (corresponding
to calculation month number x₃ = 0). Months
m = 1 through 6 of the preceding calendar year j
− 1 and months 7 through 12 or 13 of the current calendar year
j are part of calculation year x₁ = j −
1 as calculation months x₃ = 0 through 11 or
12. The first day of each month has calculation day number z₃
= 0. New Year's Day of calendar year j
corresponds to x₁ = j − 1, x₃ = 6, and
z₄ = 0.
m | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
x₃ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
x₁ − j | 0 | 0 | 0 | 0 | 0 | 0 | −1 | −1 | −1 | −1 | −1 | −1 | −1 |
For converting from year j, month m, day
d in the Jewish calendar to calculation year
x₁, calculation month x₃, and
calculation day z₄, we find
(Eq. 530) c₀ = ⌊(13 − m)/7⌋
(Eq. 531) x₁ = j − 1 + c₀
(Eq. 532) x₃ = m − 1
(Eq. 533) z₄ = d − 1
For example, after the last day of month 13 of year 4682 in the Jewish calendar comes the first day of month 1 of year 4682. 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 | c₀ | x₁ | x₃ | z₄ |
|---|---|---|---|---|---|---|
| 4682 | 13 | 29 | 0 | 4681 | 12 | 28 |
| 4682 | 1 | 1 | 1 | 4682 | 0 | 0 |
| 4682 | 6 | 29 | 1 | 4682 | 5 | 28 |
| 4683 | 7 | 1 | 0 | 4682 | 6 | 0 |
| 4683 | 12 | 30 | 0 | 4682 | 11 | 29 |
Transforming a date from the Jewish calendar into CJDN requires combining four calendar levels:
c₁ of the first month (calculation month number
z₁ = 0) of calculation year x₁.c₂ of New
Year (calculation day number 0, calculation month number 6) of
calculation year x₁ from the running calculation month
number c₁. With that, we can calculate the length of
the year, and from that the length of all of the months.y₃, the day number in the year,
from month number x₃ in the calculation year.y₄ of the
desired date from the running day number c₂ of New Year
and from the day number y₃ in the current calculation
year and from the calculation day number z₄ in the
calculation month.y₄ = 0
to get the CJDN of the desired date.At the first calendar level, y₁ = c₁(x₁) + z₁, where
y₁ is the running month number, x₁ is
the calculation year number, z₁ is the calculation
month number in the calculation year, and c₁ is the
running month number of the first month (z₁ = 0) of the
calculation year.
The leap 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 c₁ of the first
calculation month (z₁ = 0) of year x₁ is
(Eq. 534) c₁ = ⌊(235x₁ + 1)/19⌋
As an example we look at the beginning of the Jewish year A.M. 4682.
Then x₁ = 4681 so c₁ = ⌊(235×4681 +
1)/19⌋ = ⌊1100036⁄19⌋ = 57896. New Year of A.M. 4682 is
57896 months after New Year of A.M. 1.
If you're working in a calculation environment where whole numbers
cannot be greater than a certain value w, then (to
avoid overflow) |x₁| in the preceding formula must not
exceed w/235, instead of w. For
w = 231, 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 5.1. One alternative
is, if w > 133
(Eq. 535) c₁ = 12x₁ + ⌊(7x₁ + 1)/19⌋
for which |x₁| must not exceed w/7.
Another alternative is, for w = 231 = 2147483648
(Eq. 536) q = ⌊x₁/3⌋
(Eq. 537) r = x₁ mod 3
(Eq. 538) c₁ = 37q + ⌊(2q + 235r + 1)/19⌋
for which |x₁| may have any value up to w.
At the second calendar level, y₂ = c₂(x₂) + z₂, where
x₂ = c₁ is the running calculation month number of the
first calculation month of the year, z₂ is the
calculation day number in the current month of the first day of that
month, and y₂ is the running day number of the first
day of that month.
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₀).
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 μ 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 c₁ is equal to
(Eq. 539) μ = (5604 + 765433×c₁)/25920
The running day number υ₀ of the calendar day on which
that New Moon occurs is
(Eq. 540) υ₀ = ⌊μ⌋
We again look at New Year of the Jewish year A.M. 4682. We earlier
found that c₁ = 57896. Then μ = (5604 +
765433×57896)/25920 = 44315514572⁄25920 = 1709703 +
12812⁄25920 and υ₀ = 1709703.
If you're working in a calculation environment where whole numbers
cannot exceed a certain value w, then (to avoid
overflow) in equation 539 |c₁| must not exceed
w/765433, which is far less than w. For
32-bit numbers this corresponds to only about 226 jaar − far too few
to be practical. Using the methods of Sec. 5.1 we can
find better alternatives. One alternative, when w >
356,477,760, is
(Eq. 541) μ = 29c₁ + (5604 + 13753c₁)/25920
for which |c₁| must not exceeed w/13753,
which for 32-bit numbers corresponds to about 156146 months, or about
12624 years. Another alternative, for w = 231 =
2147483648, is
for which |c₁| may have any value up to
w, which corresponds to about 173 million years.
The following table shows some results.
x₁ | c₁ | q | r | μ | υ₀ |
|---|---|---|---|---|---|
| 4681 | 57896 | 52 | 956 | 1709703 + 12812/25920 | 1709703 |
| 4682 | 57909 | 52 | 969 | 1710087 + 10161/25920 | 1710087 |
| 4683 | 57921 | 52 | 981 | 1710441 + 19677/25920 | 1710441 |
| 5516 | 68224 | 62 | 334 | 2014695 + 12196/25920 | 2014695 |
| 5517 | 68236 | 62 | 346 | 2015049 + 21712/25920 | 2015049 |
| 5518 | 68249 | 62 | 359 | 2015433 + 19061/25920 | 2015433 |
The running day number υ₀ can be modified by four
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 μ mod 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 μ mod 1 ≥ ¾, then
New Year is delayed by one day. If μ mod 1 ≥ ¾ then
(μ mod 1) + ¼ ≥ 1 so ⌊μ + ¼⌋ = ⌊μ⌋ +
1, so the running day number υ₁ of the first
day of the month, including the effect of the first delay, is
(Eq. 542) υ₁ = ⌊μ + ¼⌋ = ⌊μ + 6480⁄25920⌋ = 29c₁ + ⌊(12084 +
13753c₁)/25920⌋
For A.M. 4682 we find υ₁ = ⌊1709703 + (12812 + 6480)/25920⌋ =
1709703 + ⌊19292⁄25920⌋ = 1709703 = υ₀, 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.
υ₀ = υ₁ = 0 corresponds to CJDN 347998 which was a
Monday, because 347998 mod 7 = 0 and 0 corresponds to
Monday. The second delay occurs when
(Eq. 543) δ = υ₁ mod 7
is equal to 2, 4, or 6.
We seek a formula for v₂(δ) that returns 0 if
δ is equal to 0, 1, 3, or 5, and that returns 1 if
δ is equal to 2, 4, or 6. Because we only want 0 or 1
to be returned, something involving mod 2 seems to be
needed. That we only want whole numbers as results points at
something looking like ⌊...δ...⌋ mod 2. The simplest
formula that might work is then v₂(δ) = ⌊qδ⌋ mod 2 for
a suitable factor q. Some searching shows that we get
the desired outcomes when 5⁄6 < q < 1. A few
ratios with small denominators that are suitable for q
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
v₂(υ₁) instead of v₂(δ) = v₂(υ₁ mod 7):
that saves one modulus calculation. With that, the running day number
υ₂ of the first day of the month, including the first
two delays, is equal to
(Eq. 544) υ₂ = υ₁ + (⌊6υ₁/7⌋ mod 2)
If you're working in a calculation environment where whole numbers
must not exceed some value w, then υ₁
must not exceed w/6. For 32-bit numbers this
corresponds to about 979,914 years. If that is not enough, then you
can use v₂(υ₁ mod 7) after all:
(Eq. 545) υ₂ = υ₁ + (⌊6×(υ₁ mod 7)/7⌋ mod 2)
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₂(x₁) of year x₁ (including
the effects of the first two delays) is equal to
(Eq. 546) L₂(x₁) = υ₂(x₁ + 1) − υ₂(x₁)
so New Year of year x₁ is delayed by 2 days if
L₂(x₁) = 356. We achieve the desired effect with
formula
(Eq. 547) v₃ = 2(⌊(L₂ + 19)/15⌋ mod 2)
L₂ | 353 | 354 | 355 | 356 | 382 | 383 | 384 | 385 |
v₃ | 0 | 0 | 0 | 2 | 0 | 0 | 0 | 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 x₁ is delayed by 1 day when
L₂(x₁ − 1) = 382. We get the desired effect with
formula
(Eq. 548) v₄ = ⌊(L₂(x₁ − 1) + 7)/15⌋ mod 2
L₂ | 353 | 354 | 355 | 356 | 382 | 383 | 384 | 385 |
v₄ | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
Years do not exist for which L₂(x₁) = 356 and at the
same time L₂(x₁ − 1) = 382, so the third and fourth
delays are never active at the same time.
The running day number c₂ of New Year, taking into
account all four delays, is
(Eq. 549) c₂ = υ₂ + v₃ + v₄
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 x₁ = 4681 we found earlier that υ₀ =
1709703. Equation 542 then yields υ₁ = 1709703 =
υ₀, so the first delay does not affect that year. Equation
544 yields υ₂ = υ₁ + (⌊6υ₁/7⌋ mod 2) = 1709703 +
(⌊6×1709703⁄7⌋ mod 2) = 1709703 + (⌊10258218⁄7⌋ mod 2) = 1709703 +
(1465459 mod 2) = 1709703 + 1 = 1709704, so the second delay
does have effect. The length of year x₁ = 4681 taking
into account the first two delays is L₂(4681) = υ₂(4682) −
υ₂(4681) = 1710087 − 1709704 = 383 days. The year with
x₁ = 4682 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 listsed in the following table. The column with title
"v" mentions the numbers of the delays that applied.
x₁ | υ₀ | υ₁ | υ₂ | L₂ | c₂ | L₄ | v |
|---|---|---|---|---|---|---|---|
| 4681 | 1709703 | 1709703 | 1709704 | 383 | 1709704 | 385 | 2 |
| 4682 | 1710087 | 1710087 | 1710087 | 356 | 1710089 | 354 | 3 |
| 4683 | 1710441 | 1710442 | 1710443 | 353 | 1710443 | 353 | 1, 2 |
| 5516 | 2014695 | 2014695 | 2014696 | 355 | 2014696 | 355 | 2 |
| 5517 | 2015049 | 2015050 | 2015051 | 382 | 2015051 | 383 | 1, 2 |
| 5518 | 2015433 | 2015433 | 2015433 | 355 | 2015434 | 354 | 4 |
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×765433/25920 = 35975351/5184 days, so each period of 5184 cycles covers a whole number of days, namely 35975351. This number of days is not a multiple of 7, so the calendar only repeats itself after 7×35975351 = 251827457 days = 35975351 weeks = 689472 years = 8527680 months.
The distribution of the calendar year lengths in that period of 689472 years is listed in the following table, including how many of those years have that length if you take into account different delays.
| 353 | 354 | 355 | 356 | 382 | 383 | 384 | 385 | |
|---|---|---|---|---|---|---|---|---|
υ₀ | 275583 | 159873 | 25984 | 228032 | ||||
υ₁ | 275583 | 159873 | 25984 | 228032 | ||||
υ₂ | 78738 | 140946 | 192933 | 22839 | 3712 | 116288 | 36288 | 97728 |
υ₄ | 69222 | 167497 | 198737 | 106677 | 36288 | 111051 |
The next table shows of how many years from that big cycle of 689472 years the New Year is affected by the delays mentioned in the column with title "v".
| v | # | % |
|---|---|---|
− | 268937 | 39.0 |
| 1 | 98496 | 14.3 |
| 2 | 221616 | 32.1 |
| 3 | 22839 | 3.3 |
| 4 | 3712 | 0.5 |
| 1 + 2 | 73872 | 10.7 |
| rest | 0 | 0 |
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 40000 times in the great cycle of 689472 years.
| 353 | 354 | 355 | 383 | 384 | 385 | |
| 353 | 0 | 16404 | 16404 | 0 | 0 | 36414 |
| 354 | 13776 | 0 | 54468 | 53354 | 0 | 45899 |
| 355 | 9516 | 54491 | 16381 | 53323 | 36288 | 28738 |
| 383 | 0 | 40000 | 66677 | 0 | 0 | 0 |
| 384 | 29965 | 0 | 13323 | 0 | 0 | 0 |
| 385 | 22965 | 56602 | 31484 | 0 | 0 | 0 |
We now know the running day number c₂ of New Year (1
Tishri) of calculation year x₁.
The length L of calendar year x₁ is then
equal to
(Eq. 550) L = c₂(x₁ + 1) − c₂(x₁)
The month lengths are as follow, in years with different lengths:
m | 353 | 354 | 355 | 383 | 384 | 385 | |
|---|---|---|---|---|---|---|---|
| 1 | Nisan | 30 | 30 | 30 | 30 | 30 | 30 |
| 2 | Iyar | 29 | 29 | 29 | 29 | 29 | 29 |
| 3 | Sivan | 30 | 30 | 30 | 30 | 30 | 30 |
| 4 | Tammuz | 29 | 29 | 29 | 29 | 29 | 29 |
| 5 | Av | 30 | 30 | 30 | 30 | 30 | 30 |
| 6 | Elul | 29 | 29 | 29 | 29 | 29 | 29 |
| 7 | Tishri | 30 | 30 | 30 | 30 | 30 | 30 |
| 8 | Ḥeshvan | 29 | 29 | 30 | 29 | 29 | 30 |
| 9 | Kislev | 29 | 30 | 30 | 29 | 30 | 30 |
| 10 | Tevet | 29 | 29 | 29 | 29 | 29 | 29 |
| 11 | Shevat | 30 | 30 | 30 | 30 | 30 | 30 |
| 12 | Adar Ⅰ | 0 | 0 | 0 | 30 | 30 | 30 |
| 13 | 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. 5.10), 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
(Eq. 551) y₃ = ⌊(384×x₃ + 7)/13⌋ + z₃
where x₃ is the calculation month number in the year,
y₃ is the running day number in the year,
z₃ is the running day number in the month, and all of
them begin at 0 for the first month and day.
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 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, month 9 must be one day shorter. In a year with 355 or 385
days, month 8 must be one day longer. The corrections
c₈ for month 8 and c₉ for month 9 as a
function of year length L are
L | 353 | 354 | 355 | 383 | 384 | 385 |
c₈ | 0 | 0 | 1 | 0 | 0 | 1 |
c₉ | −1 | 0 | 0 | −1 | 0 | 0 |
We find the following formula for the month-8 correction
(Eq. 552) c₈ = ⌊(L + 353)/2⌋ mod 15 = ⌊(L + 7)/2⌋ mod 15
and for the month-9 correction
(Eq. 553) c₉ = −(⌊(385 − L)/2⌋ mod 15)
We calculate the running day number of a date in months 1 through 6
(x₃ = 0 through 5) from the following New Year (the
first day of month 7), and the length of those months is the same in
every year, so the month-8 and month-9 corrections do not affect such
dates. We calculate the running day number of a date in months 7
through 13 (x₃ = 6 through 12) from the preceding New
Year. The month-8 correction applies to dates in months 9 through 13,
and the month-9 correction to dates in months 10 through 13. In the
following table, f₈ shows (with value 1) to which
months the month-8 correction applies, and f₉ likewise
for the month-9 correction.
x₃ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
f₈ | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |
f₉ | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
We get that using the equations
(Eq. 554) f₈ = ⌊(x₃ + 4)/12⌋
(Eq. 555) f₉ = ⌊(x₃ + 3)/12⌋
With that, the formula to go from month number x₃ in
the calculation year to day number c₃ in the
calculation year of the first day of that month is
(Eq. 556) c₃ = ⌊(384x₃ + 7)/13⌋ + c₈⌊(x₃ + 4)/12⌋ + c₉⌊(x₃ +
3)/12⌋
and we add the day number z₃ in the month to get that
day's day number y₃ in the calculation year
(Eq. 557) y₃ = c₃ + z₃
The running day number c₄ (since 1 Tishri of A.M. 1) of
the first day of the desired month is
(Eq. 558) c₄ = c₂ + c₃
The first six months (from Nisan through Elul) together always have
177 days, regardless of the length of the calendar year, so the
running day number c₂ of 1 Tishri of the calculation
year is 177 days greater than the running day number of 1 Nisan of
that same calculation year. So, the running day number
y₄ (since 1 Nisan of A.M. 1) of the desired date is
(Eq. 559) y₄ = c₄ + z₃ − 177
The epoch of the calendar is 1 Tishri of the year A.M. 1 and
corresponds to CJDN 347998 = J₀. So, the CJDN
J of the desired date is
(Eq. 560) J = J₀ + y₄ = J₀ + c₂ + c₃ + z₃ − 177 = 347821 + c₂ + c₃ +
z₃
Now we go in the opposite direction.
J into running day number
y₄ since 1 Tishri A.M. 1:
(Eq. 561) y₄ = J − J₀ + 177 = J − 347821
As examples we'll calculate the Hebrew calendar dates that correspond
to the following CJDN: 2000087, 2001327, 2057986. For J =
2057986 we find y₄ = 2057986 − 347821 =
1710165. All in all we find
J | y₄ |
|---|---|
| 2000087 | 1652266 |
| 2001327 | 1653506 |
| 2057986 | 1710165 |
| 119311997 | 118964176 |
Using the inverse of equation 542 we can calculate the
provisional running calculation month number y₁′ for
running day number y₄ as if the second, third, and
fourth delays do not exist:
(Eq. 562) y₁′ = ⌊(25920y₄ + 25920 − 12084 − 1)/765433⌋ = ⌊(25920y₄ +
13835)/765433⌋
For y₄ = 1710165 we find y₁′ = ⌊(25920×1710165 +
13835)/765433⌋ = ⌊44327490635⁄765433⌋ = 57911.
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 562 |y₄| 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. 5.1 we can find better
alternatives. One alternative, when w = 231 =
2147483648, is
(Eq. 563) q = ⌊y₄/1447⌋
(Eq. 564) r = y₄ mod 1447
(Eq. 565) y₁′ = 49q + ⌊(23q + 25920r + 13835)/765433⌋
for which |y₄| may have any value up to
w, which corresponds to about 5.9 million years.
For y₄ = 1710165 we find q = ⌊1710165⁄1447⌋ =
1181, r = 1710165 mod 1447 = 1258, y₁′
= 49×1181 + ⌊(23×1181 + 25920×1258 + 13835)/765433⌋ = 57869 +
⌊32648358⁄765433⌋ = 57869 + 42 = 57911, just like before.
For all example CJDN we find
J | q | r | y₁′ |
|---|---|---|---|
| 2000087 | 1141 | 1239 | 55951 |
| 2001327 | 1142 | 1032 | 55992 |
| 2057986 | 1181 | 1258 | 57911 |
| 119311997 | 82214 | 518 | 4028506 |
If we calculate the running day number c₄(y₁′) of the
first day of that running calculation month with all applicable delays
included, and then calculate the provisional day-number-in-the-month
y₄ − c₄(y₁′), then we find results that vary between −2
en 29. The days for which this day number is negative belong in the
previous month (with y₁ = y₁′ − 1). There are 5963491
such days in each great calendar cycle of 251827457 days, which means
that for one in about every 42 days y₁′ is one too
great.
The days for which this day number is not less than 0 and not greater
than 28 certainly belong in the current month (with y₁ =
y₁′), 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, but can also belong 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., y₄ − c₄(y₁′ + 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 (with y₁ = y₁′ + 1);
There really are days for which the provisional running month number
y₁′ is too small. There are 163258 such days in each
great calendar cycle of 251827457 days, so for roughly one out of 1543
days (about one day out of every 52 months) y₁′ is one
too small. For 97.6% of days, y₁′ is already the
correct month.
Unfortunately, there is no simple relationship between the day number
relative to month y₁′ and that relative to month
y₁′ + 1, so we must calculate both day numbers to
figure out the month into which the desired day falls.
The minimal calculation is as follows: Calculate y₄ −
c₄(y₁′). If that value is negative, then y₁ = y₁′ −
1. If that value is not negative and is not greater than 28,
then y₁ = y₁′. If that value is greater than 28, then
also calculate y₄ − c₄(y₁′ + 1). If that second value
is negative, then y₁ = y₁′. If that second value is
not negative, then y₁ = y₁′ + 1.
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.
ξ₁ and calculation month number μ₁ in
the calculation year, for running calculation month number
γ₁:
(Eq. 566) γ₁ = y₁′ + 1
(Eq. 567) κ₁ = 19γ₁ + 17
(Eq. 568) ξ₁ = ⌊κ₁/235⌋
(Eq. 569) μ₁ = ⌊(κ₁ mod 235)/19⌋
For our first example CJDN we had y₁′ = 57911. Then
γ₁ = y₁′ + 1 = 57912, κ₁ = 19×57912 + 17 =
1100345, ξ₁ = ⌊1100345⁄235⌋ = 4682 and
μ₁ = ⌊(1100345 mod 235)/19⌋ = ⌊75⁄19⌋ = 3.
For all example CJDNs we find
J | y₁′ | γ₁ | κ₁ | ξ₁ | μ₁ |
|---|---|---|---|---|---|
| 2000087 | 55951 | 55952 | 1063105 | 4523 | 10 |
| 2001327 | 55992 | 55993 | 1063884 | 4527 | 2 |
| 2057986 | 57911 | 57912 | 1100345 | 4682 | 3 |
| 119311997 | 4028506 | 4028507 | 76541650 | 325709 | 1 |
c₄′(ξ₁,μ₁) of the
beginning of calculation month μ₁ of calculation year
ξ₁ in the way described in the previous section, and
then the day number ζ₁ of the month, relative to
c₄′(ξ₁,μ₁):
(Eq. 570) ζ₁ = y₄ − c₄′(ξ₁,μ₁)
Apply a correction in case ζ₁ turns out to be negative:
(Eq. 571) γ₂ = γ₁ + ⌊ζ₁/33⌋
If ζ₁ is not negative, then the correction is equal to
0.
For calculation year 4682 we found earlier that it has a length of
L = 354 days, and that its New Year has for its running
day number c₂′ = 1710089. For calculation month
μ₁ = 3 the month-8 and month-9 corrections c₈,
c₉ are equal to 0 and we find c₃′ = ⌊(384×μ₁ + 7)/13⌋ +
c₈×⌊(μ₁ + 4)/12⌋ + c₉×⌊(μ₁ + 3)/12⌋ = ⌊(384×3 + 7)/13⌋ = ⌊1159⁄13⌋ =
89 and then c₄′ = c₂′ + c₃′ = 1710089 + 89 =
1710178. Then ζ₁ = y₄ − c₄′ = 1710165 − 1710178 =
−13, so the target day does not belong to calculation month 3
of calculation year 4682. Then γ₂ = γ₁ + ⌊ζ₁/33⌋ = 57912 +
⌊−13⁄33⌋ = 57912 + (−1) = 57911.
For all example CJDNs we find
J | y₄ | γ₁ | ξ₁ | μ₁ | c₄′ | ζ₁ | ⌊ζ₁/33⌋ | γ₂ |
|---|---|---|---|---|---|---|---|---|
| 2000087 | 1652266 | 55952 | 4523 | 10 | 1652296 | −30 | −1 | 55951 |
| 2001327 | 1653506 | 55993 | 4527 | 2 | 1653506 | 0 | 0 | 55993 |
| 2057986 | 1710165 | 57912 | 4682 | 3 | 1710178 | −13 | −1 | 57911 |
| 119311997 | 118964176 | 4028507 | 325709 | 1 | 118964207 | −31 | −1 | 4028506 |
so y₁′ was one too small for J =
2001327.
ξ₂, calculation month number μ₂, running
day number c₄′(ξ₂,μ₂) of the first day of that month,
day-number-in-the-month ζ₂, running month number
γ₃, calculation year number ξ₃,
calculation month number μ₃, running day number
c₄′(ξ₃,μ₃) of the first day of that month, and
day-number-in-the-month ζ₃. The final calculation year
number is then
(Eq. 572) x₁ = ξ₃
and the final calculation month number is
(Eq. 573) x₃ = μ₃
and the final calculation day number is
(Eq. 574) z₄ = ζ₃
Running month number γ₂ = 57911 corresponds to
ξ₂ = ⌊(19×57911 + 17)/235⌋ = ⌊1100326⁄235⌋ = 4682 and
μ₂ = γ₂ − ⌊(235ξ₂ + 1)/19⌋ = 57911 − ⌊(235×4682 + 1)/19⌋ =
57911 − ⌊1100271⁄19⌋ = 57911 − 57909 = 2.
For calculation year 4682 we earlier found that it has a length of
L = 354 days, and that its New Year has for its running
day number c₂′ = 1710089. For calculation month
μ₂ = 2 the month-8 and month-9 corrections c₈,
c₉ are equal to 0, and we find c₃′ = ⌊(384μ₂ + 7)/13⌋ +
c₈×⌊(μ₂ + 4)/12⌋ + c₉×⌊(μ₂ + 3)/12⌋ = ⌊(384×2 + 7)/13⌋ = ⌊775⁄13⌋ =
59 and then c₄′ = c₂′ + c₃′ = 1710089 + 59 =
1710148. Then ζ₂ = y₄ − c₄′ = 1710165 − 1710148 =
17. This is not negative and also not greater than 28, so we
have found the correct month.
For all example CJDNs we find
J | y₄ | γ₁ | γ₂ | ξ₂ | μ₂ | c₄′ | ζ₂ | γ₃ | x₁=ξ₃ | x₃=μ₃ | c₄′ | z₄=ζ₃ |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2000087 | 1652266 | 55952 | 55951 | 4523 | 9 | 1652267 | −1 | 55950 | 4523 | 8 | 1652237 | 29 |
| 2001327 | 1653506 | 55993 | 55993 | 4527 | 2 | 1653506 | 0 | 55993 | 4527 | 2 | 1653506 | 0 |
| 2057986 | 1710165 | 57912 | 57911 | 4682 | 2 | 1710148 | 17 | 57911 | 4682 | 2 | 1710148 | 17 |
| 119311997 | 118964176 | 4028507 | 4028506 | 325709 | 0 | 118964177 | −1 | 4028505 | 325708 | 12 1 | 18964148 | 28 |
so y₁′ was correct for J = 2057986, and
y₁′ was one too great for J = 2000087.
x₁, calculation month
x₃, and calculation day z₄ into
calendar year j, calendar month m, and
calendar day d:
(Eq. 575) c = ⌊(12 − x₃)/7⌋
(Eq. 576) j = x₁ + 1 − c
(Eq. 577) m = x₃ + 1
(Eq. 578) d = z₄ + 1
For calculation year 4682, calculation month 2, calculation day 17 we
find c = ⌊(12 − 2)/7⌋ = ⌊10⁄7⌋ = 1, j = x₁ + 1 −
c = 4682 + 1 − 1 = 4682, m = 2 + 1 = 3,
d = 17 + 1 = 18, so the date is day 18 of calendar
month 3 (Sivan) of year 4682.
For all example-CJDNs we find
J | x₁ | x₃ | z₄ | c | j | m | d |
|---|---|---|---|---|---|---|---|
| 2000087 | 4523 | 8 | 29 | 0 | 4524 | 9 | 30 |
| 2001327 | 4527 | 2 | 0 | 1 | 4527 | 3 | 1 |
| 2057986 | 4682 | 2 | 17 | 1 | 4682 | 3 | 18 |
| 119311997 | 325708 | 12 | 28 | 0 | 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. The Cycle of Meton requires 125 = 6×19 + 11 long months, so then we'd need to have 11 long months among the 7 months that have number 13, and that won't fit. We'll have to vary the length of some of the first 12 months of every year, too, if we want most calendar months in each year to have a fixed length. We want to use 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 saw before that 6 long months in the first 12 months of the year is not enough, so we must use a formula that yields 7 long months in the first 12 months. With 7 long months in the first 12 months of every year, we have 7×12 = 133 long months in the 19-year cycle, and that is too many, because the Cycle of Meton only has 125 long months in 19 years. So, the 13th month must be a short month, and also we have to change 8 long months (of 30 days) into short months (of 29 days) in the short years (of 12 months). We can do that by making short years one day shorter, but then month 12 must be a long month, otherwise month 12 would have only 28 days in short years.
We can arrange all of that with the following three types of years in the 19-year cycle:
7 years of 13 months with 384 days (7 long months, 6 short months).
4 years of 12 months with 355 days (7 long months, 5 short months).
8 years of 12 months with 354 days (6 long months, 6 short months).
Then there are in total 7×13 + 4×12 + 8×12 = 235 months, with is as expected. There are then 7×7 + 4×7 + 8×6 = 125 long months, which is correct.
The straight line must yield a long month 12 (with 30 days) and a short month 13 (with 29 days), and that 7 of the first 13 months are long months.
The following formula provides this (with x₁ the number
of months since the first month, and c₁ the number of
days from the first day of the year to the first day of month
x₁):
(Eq. 579) c₁ = 29×x₁ + ⌊(7x₁ + 3)/13⌋ = ⌊(384x₁ +
3)/13⌋
For example, if x₁ = 4, then equation 579
yields c₁ = ⌊(384×4 + 3)/13⌋ = ⌊1539⁄13⌋ = 118, so the
first day of the fifth month (x₁ = 4) is the 118th day
since the first day of the year.
For the first day of the first 14 months, equation 579
gives the following results (with L the length of the
month):
m | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
x₁ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
c₁ | 0 | 29 | 59 | 88 | 118 | 147 | 177 | 207 | 236 | 266 | 295 | 325 | 354 | 384 |
L | 29 | 30 | 29 | 30 | 29 | 30 | 30 | 29 | 30 | 29 | 30 | 29 | 30 |
Now we need a second calendar level to get the right number of days in
each year. We can use the following formula for that, where
x₂ is the number of years since the first year, and
c₂ is the running day number of the first day of the
year:
(Eq. 580) c₂ = 354×x₂ + 30⌊(7x₂ + 1)/19⌋ + ⌊(4x₂ +
12)/19⌋
For example, if x₂ = 8, then equation 580
yields c₂ = 354×8 + 30⌊(7×8 + 1)/19⌋ + ⌊(4×8 + 12)/19⌋ = 2832 +
30×3 + 2 = 2837, so the first day of year x₂ =
9 has running day number 2837.
This is calendar type 4, with q = 354, g = 19, {d₁,h₁,s₁} =
{30,7,1}, {d₂,h₂,s₂} = {1,4,12}. The complete algorithm is
then, from year j, month m, day
d to CJDN J:
(Eq. 581) x₂ = j − 1
(Eq. 582) x₁ = m − 1
(Eq. 583) z₁ = d − 1
(Eq. 584) c₁ = ⌊(384x₁ + 3)/13⌋
(Eq. 585) y₁ = c₁ + z₁
(Eq. 586) z₂ = y₁
(Eq. 587) c₂ = 354×x₂ + 30⌊(7x₂ + 1)/19⌋ + ⌊(4x₂ + 12)/19⌋
(Eq. 588) y₂ = c₂ + z₂
(Eq. 589) J = y₂ + 1607558
For example, which CJDN corresponds to day 27 of month 9 of year 3 in
this calendar? Then j = 3, m = 9,
d = 27, and then x₂ = 3 − 1 = 2,
x₁ = 9 − 1 = 8, z₁ = 27 − 1 = 26,
c₁ = ⌊(384×8 + 3)/13⌋ = ⌊3075⁄13⌋ = 236, y₁ =
236 + 26 = 262, z₂ = 262, c₁ = 354×2 +
30×⌊(7×2 + 1)/19⌋ + ⌊(4×2 + 12)/19⌋ = 708 + 30×⌊15⁄19⌋ + ⌊20⁄19⌋ = 708
+ 0 + 1 = 709, y₂ = 709 + 262 = 971, and
finally J = 971 + 1607558 = 1608529.
This can be compressed to
(Eq. 590) J = 354×j + 30⌊(7j − 6)/19⌋ + ⌊(4j + 8)/19⌋ + ⌊(384m − 381)/13⌋
+ d + 1607203
In the opposite direction, the formulas are
(Eq. 591) y₂ = J − 1607558
(Eq. 592) x₂ = ⌊(19y₂ + 546)/6940⌋
(Eq. 593) c₂ = 354×x₂ + 30⌊(7x₂ + 1)/19⌋ + ⌊(4x₂ + 12)/19⌋
(Eq. 594) z₂ = y₂ − c₂
(Eq. 595) ζ = ⌊z₂/385⌋
(Eq. 596) x₂ → x₂ + ζ
(Eq. 597) c₂ → 354×x₂ + 30⌊(7x₂ + 1)/19⌋ + ⌊(4x₂ + 12)/19⌋
(Eq. 598) z₂ → y₂ − c₂
(Eq. 599) y₁ = z₂
(Eq. 600) k₁ = 13y₁ + 9
(Eq. 601) x₁ = ⌊k₁/384⌋
(Eq. 602) z₁ = ⌊(k₁ mod 384)/13⌋
(Eq. 603) j = x₂ + 1
(Eq. 604) m = x₁ + 1
(Eq. 605) d = z₁ + 1
For example, which day in this calendar corresponds to CJDN 1608529?
Then J = 1608529 and then y₂ = 1608529 − 1607558
= 971, x₂ = ⌊(19×971 + 546)/6940⌋ = ⌊18995⁄6940⌋ =
2, c₂ = 354×2 + 30×⌊(7×2 + 1)/19⌋ + ⌊(4×2 + 12)/19⌋ =
708 + 30×⌊15⁄19⌋ + ⌊20⁄19⌋ = 708 + 0 + 1 = 709, z₂ =
971 − 709 = 262, ζ = ⌊262⁄385⌋ = 0. ζ =
0 so x₂, c₂, z₂ remain the same. Then
y₁ = 262, k₁ = 13×262 + 9 = 3415,
x₁ = ⌊3415⁄384⌋ = 8, z₁ = ⌊(3415 mod 384)/13⌋ =
⌊343⁄13⌋ = 26, so j = 2 + 1 = 3, m = 8 +
1 = 9, and d = 26 + 1 = 27, so the date is day
27 of month 9 of year 3.
This can be compressed a little, to
%ignore>
(Eq. 606) y₂ = J − 1607558
(Eq. 607) x′ = ⌊(19y₂ + 546)/6940⌋
(Eq. 608) ζ = ⌊(y₂ − 354x′ − 30⌊(7x′ + 1)/19⌋ − ⌊(4x′ + 12)/19⌋)/385⌋
(Eq. 609) x₂ = x′ + ζ
(Eq. 610) c₂ = 354x₂ + 30⌊(7x₂ + 1)/19⌋ + ⌊(4x₂ + 12)/19⌋
(Eq. 611) k₁ = 13×(y₂ − c₂) + 9
(Eq. 612) j = x₂ + 1
(Eq. 613) m = ⌊k₁/384⌋ + 1
(Eq. 614) d = ⌊(k₁ mod 384)/13⌋ + 1
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
http://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 2 lists those
ways and their leap year distributions, and shows the corresponding
s (as in equation 159).
| Type | Leap Years | s | 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
(Eq. 615) N = ⌊(11j + s)/30⌋
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 1948438.75), and the civil epoch "c" according to which the calendar began on the evening of Thursday 15 July 622 (approximately CJD 1948439.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 + 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 2455774 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 2455774 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 2455774, but in the Islamic calendar it is already the next day (i.e., 1 Ramaḍān).
| Type | s | J₀ |
| Ia | 15 | 1948439 |
| Ic | 15 | 1948440 |
| IIa | 14 | 1948439 |
| IIc | 14 | 1948440 |
| IIIa | 11 | 1948439 |
| IIIc | 11 | 1948440 |
| IVa | 9 | 1948439 |
| IVc | 9 | 1948440 |
(Eq. 616) x₂ = j − 1
(Eq. 617) x₁ = m − 1
(Eq. 618) z₁ = d − 1
(Eq. 619) c₁ = ⌊(325x₁ + 5))/11⌋
(Eq. 620) y₁ = c₁ + z₁
(Eq. 621) z₂ = y₁
(Eq. 622) c₂ = ⌊(10631x₂ + s)/30⌋
(Eq. 623) y₂ = c₂ + z₂
(Eq. 624) J = y₂ + J₀
For example, which CJDN corresponds to the Islamic date of 29 Sha`ban
1432 according to calendar type IIc? Then j = 1432, m = 8,
d = 29, s = 14, J₀ = 1948440, and then x₂ = 1432 − 1 =
1431, x₁ = 8 − 1 = 7, z₁ = 29 − 1 = 28, c₁ = ⌊(325×7 + 5)/11⌋ =
⌊2280⁄11⌋ = 207, y₁ = 207 + 28 = 235, z₂ = 235, c₂ = ⌊(10631×1431 +
14)/30⌋ = ⌊15212975⁄30⌋ = 507099, y₂ = 507099 + 235 = 507334,
and finally J = 507334 + 1948440 = 2455774.
This can be condensed to
(Eq. 625) J = ⌊(10631×j − 10631 + s)/30⌋ + ⌊(325×m − 320)/11⌋ + d − 1 +
J₀
i.e.,
| Ia | J = ⌊(10631j − 10616)/30⌋ + ⌊(325m − 320)/11⌋ + d + 1948438 |
| Ic | J = ⌊(10631j − 10616)/30⌋ + ⌊(325m − 320)/11⌋ + d + 1948439 |
| IIa | J = ⌊(10631j − 10617)/30⌋ + ⌊(325m − 320)/11⌋ + d + 1948438 |
| IIc | J = ⌊(10631j − 10617)/30⌋ + ⌊(325m − 320)/11⌋ + d + 1948439 |
| IIIa | J = ⌊(10631j − 10620)/30⌋ + ⌊(325m − 320)/11⌋ + d + 1948438 |
| IIIc | J = ⌊(10631j − 10620)/30⌋ + ⌊(325m − 320)/11⌋ + d + 1948439 |
| IVa | J = ⌊(10631j − 10622)/30⌋ + ⌊(325m − 320)/11⌋ + d + 1948438 |
| IVc | J = ⌊(10631j − 10622)/30⌋ + ⌊(325m − 320)/11⌋ + d + 1948439 |
For the same Islamic date as before we now find J =
⌊(10631×1432 − 10617)/30⌋ + ⌊(325×8 − 320)/11⌋ + 29 + 1948439 =
⌊15212975⁄30⌋ + ⌊2280⁄11⌋ + 29 + 1948439 = 507099 + 207 + 29 + 1948439
= 2455774, which is the same answer as before.
In the opposite direction we find:
(Eq. 626) y₂ = J − J₀
(Eq. 627) k₂ = 30y₂ + 29 − s
(Eq. 628) x₂ = ⌊k₂/10631⌋
(Eq. 629) z₂ = ⌊(k₂ mod 10631)/30⌋
(Eq. 630) y₁ = z₂
(Eq. 631) k₁ = 11y₁ + 5
(Eq. 632) x₁ = ⌊k₁/325⌋
(Eq. 633) z₁ = ⌊(k₁ mod 325)/11⌋
(Eq. 634) j = x₂ + 1
(Eq. 635) m = x₁ + 1
(Eq. 636) d = z₁ + 1
For example, which Islamic date (calendar type IIc) corresponds to
CJDN 2455774? Then J = 2455774, s = 14, J₀ = 1948440,
and then y₂ = 2455774 − 1948440 = 507334, k₂ = 30×507334 + 15 =
15220035, x₂ = ⌊15220035⁄10631⌋ = 1431, z₂ = ⌊(15220035 mod
10631)/30⌋ = ⌊7074⁄30⌋ = 235, y₁ = 235, k₁ = 11×235 + 5 = 2590, x₁ =
⌊2590⁄325⌋ = 7, z₁ = ⌊(2590 mod 325)/11⌋ = ⌊315⁄11⌋ = 28, so
j = 1432, m = 8, d = 29 which means 29 Sha`ban 1432.
This can be condensed to
%ignore>
(Eq. 637) k₂ = 30×(J − J₀) + 29 − s
(Eq. 638) k₁ = 11⌊(k₂ mod 10631)/30⌋ + 5
(Eq. 639) j = ⌊k₂/10631⌋ + 1
(Eq. 640) m = ⌊k₁/325⌋ + 1
(Eq. 641) d = ⌊(k₁ mod 325)/11⌋ + 1
For example, which Islamic date (calendar type IIc) corresponds to
CJDN 2455774? Then J = 2455774, s = 14, J₀ = 1948440,
and then k₂ = 30×(2455774 − 1948440) + 29 − 14 = 15220035, k₁ =
11×⌊(15220035 mod 10631)/30⌋ + 5 = 11×⌊7074⁄30⌋ + 5 = 11×235 + 5 =
2590, j = ⌊15220035⁄10631⌋ + 1 = 1431 + 1 = 1432, m = ⌊2590⁄325⌋ + 1 =
7 + 1 = 8, d = ⌊(2590 mod 325)/11⌋ + 1 = ⌊315⁄11⌋ + 1 = 29,
so j = 1432, m = 8, d = 29 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 {hd,hm} where
hd is the day number (from 0 through 19) and
hm is the month number (from 1 through 19).
To translate a CJDN J to a Haab date
{hd,hm} 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).
(Eq. 642) H = (J + 65) mod 365
(Eq. 643) hm = ⌊H/20⌋ + 1
(Eq. 644) hd = H mod 20
For example, which Haab date corresponds to 15 December 1965 = CJDN
2439110? Then J = 2439110 and H = (J + 65) mod
365 = 2439175 mod 365 = 245, hm = ⌊245⁄20⌋ + 1 = 13, hd = 245 mod
20 = 5, 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 {hd,hm} to a CJDN we first
calculate H.
(Eq. 645) H = hd + 20×(hm − 1)
We know that
(Eq. 646) J ≡ H − 65 (mod 365)
Because there is no year number in the Haab, this Haab date returns
every 365 days. We can use equation 269 to find the last
J that corresponds to this Haab date, on or before a
specific J₀:
(Eq. 647) J = J₀ − ((J₀ − H + 65) mod 365)
Which CJDN corresponds to Haab date {5,13}? Then
hd = 5, hm = 13, so H = 5 + 20×(13 − 1) =
245 and then J ≡ 245 − 65 ≡ 180 (mod 365).
That fits the original J that we began with in the
previous example (2439110), because 2439110 = 6682×365 + 180 ≡
180 (mod 365).
What is the last CJDN in the year 1965 that corresponds to Haab date
{5,13}? We seek the last J ≡ 180 (mod
365) on or before CJDN J₀ = 2439126 (which
corresponds to 31 December 1965), using equation 269. We
find J = J₀ − ((J₀ − 180) mod 365) = 2439126 − (2438946 mod
365) = 2439126 − 16 = 2439110.
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 {tt,tv}, where
tt is the day number in the trecena (from 1 through
13) and tv 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:
(Eq. 648) tt = ((J + 5) mod 13) + 1
(Eq. 649) tv = ((J + 16) mod 20) + 1
What is the Tzolkin date corresponding to CJDN 2439110? Then
tt = ((2439110 + 5) mod 13) + 1 = 3 + 1 = 4 and
tv = ((2439110 + 16) mod 20) + 1 = 6 + 1 = 7, so that
date is {4,7}.
To translate a Tzolkin date {tt,tv} to a CJDN we need
to solve the two simultaneous congruences of equations 648
and 649, i.e.,
(Eq. 650) J ≡ tt − 6 (mod 13)
(Eq. 651) J ≡ tv − 17 (mod 20)
We combine those congruences in the way of section 5.9.3.
We have x₁ = tt, x₂ = tv, p₁ = 13, p₂ = 20, a₁ = 6, a₂ =
17. Then
(Eq. 652) C₁ = x₁ − a₁ = tt − 6
(Eq. 653) P₁ = p₁ = 13
The greatest common divisor of 13 and 20 is 1:
(Eq. 654) g₂ = 1
(Eq. 655) Q₁ = P₁/g₂ = 13⁄1 = 13
(Eq. 656) q₂ = p₂/g₂ = 20⁄1 = 20
We now seek a r₂ that solves r₂Q₁ ≡ 1 (mod
q₂), i.e., 13r₂ ≡ 1 (mod 20), and find
r₂ = 17, because 13×17 = 221 ≡ 1 (mod
20).
(Eq. 657) C₂ = C₁ (1 − r₂Q₁) + (x₂ − a₂) r₂Q₁ = (tt − 6)×(1 − 17×13) +
(tv − 17)×17×13 = 221 tv − 220 tt − 2437
(Eq. 658) P₂ = p₂Q₁ = 20×13 = 260
so the solution is
(Eq. 659) J ≡ 221 tv − 220 tt − 2437 = −39 tv + 40 tt − 97 (mod
260)
Which days correspond to Tzolkin date {4,7}? Those
days have J ≡ −39×7 + 40×4 − 97 ≡ 50 (mod 260). That
fits with J = 2439110 because 2439110 = 9381×260
+ 50 ≡ 50 (mod 260).
Because there is no year number in the Tzolkin, this Tzolkin date
returns every 260 days. We can use equation 269 to find
the last J on or before a particular J₀
that corresponds with this Tzolkin date:
(Eq. 660) J = J₀ − ((J₀ − 40 tt + 39 tv + 97) mod 365)
The last Tzolkin date {4,7} that occurs on or before 31
December 1965 (= CJDN 2439126) is J = 2439126 − ((2439126 − 50)
mod 260) = 2439126 − 16 = 2439110.
For the number of days T since the last
{1,1} we have
(Eq. 661) T ≡ 40 (tt − 1) − 39 (tv − 1) ≡ 40 tt − 39 tv − 1 ≡ 40 tt
+ 221 tv − 1 (mod 260)
so
(Eq. 662) T ≝ (40 tt + 221 tv − 1) mod 260
For CJDN 2439110 (with {tt,tv} = {4,7}) we find
T = (40×4 + 221×7 − 1) mod 260 = 1706 mod 260 = 146,
so the last day before then that had {1,1} was CJDN
J = 2439110 − 146 = 2438964, and that fits, because
tt = ((J + 5) mod 13) + 1 = (2438969 mod 13) + 1 = 1
and tv = ((J + 16) mod 20) + 1 = (2438980 mod 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:
(Eq. 663) J ≡ H − 65 (mod 365)
(Eq. 664) J ≡ T − 96 (mod 260)
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 5.9.3, with x₁ = H, x₂ = T, p₁ = 365, p₂ =
260, a₁ = 65, a₂ = 96. Then
(Eq. 665) C₁ = x₁ − a₁ = H − 65
(Eq. 666) P₁ = p₁ = 365
The greatest common divisor of 365 and 260 is 5, so
(Eq. 667) g₂ = 5
(Eq. 668) Q₁ = P₁/g₁ = 365⁄5 = 73
(Eq. 669) q₂ = p₂/g₁ = 260⁄5 = 52
We now seek r₂ that satisfies r₂Q₁ ≡ 1 (mod
q₂), i.e., 73r₂ ≡ 1 (mod 52), and find
r₂ = 5, because 73×5 = 365 = 7×52 + 1 ≡ 1 (mod
52). Then
(Eq. 670) C₂ = C₁ (1 − r₂Q₁) + (x₂ − a₂) r₂Q₁ = (H − 65)×(1 − 5×73) +
(T − 96)×5×73 = 365 T − 364 H − 11380
(Eq. 671) P₂ = p₂Q₁ = 365×52 = 18980
so the solution is
(Eq. 672) J ≡ 365 T − 364 H − 11380 ≡ 365 T − 364 H + 7600 (mod
18980)
The Tzolkin and Haab together have a period of 18980 days, which is approximately 52 years.
Which CJDN corresponds to {tt,tv,hd,hm} =
{4,7,5,13}? Then H = 245 and T =
146, so J ≡ 365×146 − 364×245 + 7600 ≡ −28290 ≡ 9670
(mod 18980), and that fits with the original J =
2439110 that we began with, because 2439110 = 128×18980
+ 9670 ≡ 9670 (mod 18980).
Because g₂ 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 (mod 5).
In the example that we've been using we have H = 245
and T = 146, so H − T = 99 ≡ 4 (mod 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 of 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₀ = 584283 (6 September −3113 in the Julian
calendar).
Translating CJDN J to Long Count L ≝
l₅.l₄.l₃.l₂.l₁ goes as follows:
(Eq. 673) x₅ = J − J₀
(Eq. 674) l₅ = ⌊x₅/144000⌋
(Eq. 675) x₄ = x₅ mod 144000
(Eq. 676) l₄ = ⌊x₄/7200⌋
(Eq. 677) x₃ = x₄ mod 7200
(Eq. 678) l₃ = ⌊x₃/360⌋
(Eq. 679) x₂ = x₃ mod 360
(Eq. 680) l₂ = ⌊x₂/20⌋
(Eq. 681) l₁ = x₂ mod 20
and translating a Long Count to CJDN goes as follows:
(Eq. 682) J = l₁ + 20×(l₂ + 18×(l₃ + 20×(l₄ + 20×l₅))) + J₀ = l₁ + 20×l₂
+ 360×l₃ + 7200×l₄ + 144000×l₅
Which Long Count L corresponds to CJDN J =
2439110? Then x₅ = J − J₀ = 2439110 − 584283 =
1854827, l₅ = ⌊1854827⁄144000⌋ = 12, x₄
= 1854827 mod 144000 = 126827, l₄ = ⌊126827⁄7200⌋ =
17, x₃ = 126827 mod 7200 = 4427, l₃ =
⌊4427⁄360⌋ = 12, x₂ = 4427 mod 360 = 107,
l₂ = ⌊107⁄20⌋ = 5, l₁ = 107 mod 20 = 7.
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))) + 584283 = 2439110.
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
(Eq. 683) v'(x) ≥ 1
(Eq. 684) v(w(x)) = w(v(x)) = x
(so v and w are each other's inverse
functions) then the calendar formulas become
(Eq. 685) y = ⌊v(x)⌋ + z
(Eq. 686) x = ⌈(w(y + 1)⌉ − 1 = −⌊−w(y + 1)⌋ − 1
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 bytes
wide, then the greatest number that it can handle is equal to w
= 2(8n − 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 3.
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 4 bytes 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 145,
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:
(Eq. 687) x = ⌊(gy + t)/f⌋
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| < w, so |y| < 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| < w/4800. For
numbers of 4 bytes wide, this algorithm would be useful as long as
approximately |y| < 447392, 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 5.1 describes how we can rearrange the calculation to avoid this problem.
As an example we look at equation 436, which we repeat here:
x₂ = ⌊(4800y₂ + 15793)/146097⌋
Then g = 4800, t = 15793, f =
146097. Suppose that y₂ = 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 = 231 = 2,147,483,648.
Then 4800y₂ + 15793 = 3,504,015,793, which is greater
than w, and 3504015793⁄146097 = 23984 +
25345⁄146097, so x₂ = 23984. If we calculate
x₂ in this way then we get an intermediate result that
is too great to fit into a number of 4 bytes wide.
Now we use the alternative method. Then
(Eq. 688) x₂ = 4800⌊y₂/146097⌋ + ⌊(4800(y₂ mod 146097) +
15793)/146097⌋
We find ⌊y₂/146097⌋ = ⌊730000⁄146097⌋ = 4, y₂
mod 146097 = y₂ − 146097⌊y₂/146097⌋ = 145612, so x₂ =
4800×4 + ⌊(4800×145612 + 15793)/146097⌋ = 19200 + ⌊698953393⁄146097⌋ =
19200 + 4784 = 23984. 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×146097 + 15793 = 701,135,296, which fits into a
number of 4 bytes 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 < w.
Table 4 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 2, 4, and 8 ― the width in bytes 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 nmin in bytes that is required for the
alternative method to work well in the computer program.
| Calendar | g | y | y/365.25 | t | f | η | nmin | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 2 | 4 | 8 | 2 | 4 | 8 | ||||||
| CJDN → Julian (1) | 4 | 8192 | 536 × 106 | 2305 × 1015 | 22 | 1469872 | 6313 × 1012 | 3 | 1461 | 4386 | 2 |
| CJDN → Julian (2) | 48 | 682 | 44 × 106 | 192 × 1015 | 1 | 122489 | 526 × 1012 | 109 | 1461 | 68776 | 3 |
| CJDN → Gregorian (1) | 4 | 8192 | 536 × 106 | 2305 × 1015 | 22 | 1469872 | 6313 × 1012 | 3 | 146097 | 438294 | 2 |
| CJDN → Gregorian (2) | 400 | 81 | 5 × 106 | 23 × 1015 | 0 | 14698 | 63 × 1012 | 799 | 146097 | 58293502 | 4 |
| CJDN → Gregorian (3) | 4800 | 6 | 447392 | 1.9 × 1015 | 0 | 1224 | 5 × 1012 | 15793 | 146097 | 701135296 | 4 |
| CJDN → Babylonian (1) | 235 | 139 | 9 × 106 | 39 × 1015 | 0 | 25019 | 10 × 1012 | 234 | 6940 | 1624194 | 3 |
| CJDN → Babylonian (2) | 19 | 1724 | 113 × 106 | 485 × 1015 | 4 | 309446 | 1329 × 1012 | 546 | 6940 | 125466 | 3 |
| CJDN → Islamic | 30 | 1092 | 71 × 106 | 307 × 1015 | 3 | 195983 | 841 × 1012 | 15 | 10631 | 308314 | 3 |
The "CJDN → Gregorian (3)" algorithm is, for whole numbers of 4 bytes 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 8 bytes wide (then the algorithm is valid for about 5,000,000,000,000 years), or use whole numbers of 4 bytes 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) forjfrom 0 throught − 1: sety[j]todate[0,j]forifrom 0 throughn − 1: ifMOD(b[i],2) = 1then: 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]forkfrom 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]returnyend 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) forifrom 0 throughn − 1: setdp[i]to0sets2[i]to0setf[i]toq[i]×g[i]forkfrom 0 throughm − 1: setf[i]tof[i] + d[i][k]×h[i][k]ifd[i][k]> 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] − 1setzz[i]toq[i] + dp[i]forjfrom 0 throught − 1: sety[j]today[j]forifromn − 1through 0: setx[j]toDIV(g[i]×y[j] + s2[i],f[i])setc[j]toq[i]×x[j]forkfrom 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] > 2then: whilez[j] < 0: setx[j]tox[j] + DIV(z[j],zz[i])setc[j]toq[i]×x[j]forkfrom 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) = 1then: 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 | |||||||
%ignore>
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
(Eq. 689) n = ⌊a j + b m + c d⌋
with a, b, and c from the
following table:
a | b | c | |Δ|max | σ | p0 | |
|---|---|---|---|---|---|---|
| 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 |Δ|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 sigma shows the standard deviation (say,
the average error, also measured in days). The p0
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.
http://aa.quae.nl/en/reken/juliaansedag.html;
Last updated: 2013-02-19