Ming Dynasty Islamic Calendar in China


Olli Salmi
7.12.2006 [latest revision 7.9.2009]

This is a rough and incomplete translation of the beginning of the description of the Islamic calendar in the History of the Ming Dynasty. The calendar has a solar Persian calendar and an Islamic lunar calendar. The formulas for determining the leap years and days of the week are interesting.

The description continues with astronomical tables. I have not translated 
this part but I have made an attempt to understand how solar longitude is calculated. The tables themselves are missing from my main source and apparently all mainland Web sites that I have come across.

The Chinese term for the calendar is
回 回历法 Huíhui lìfǎ, where Hui is the normal post-1949 term for Chinese speaking Muslims, formerly known as Dungans or Tungans.


明史卷三十七
志第十三  历七  
▲ 回回历法一
  《回回历法》,西域默狄纳国王马哈麻所作。其地北极高二十四度半,经度偏西一百零七度,约在云南之西八千馀里。 其历元用隋开皇己未,即其建国之年 也。 洪武初,得其书於元都。十五年秋,太祖谓西域推测天象最精,其五星纬度 又中国所无。命翰林李翀、吴伯宗同回回大师马沙亦黑等译其书。其法 不用闰月,以三百 六十五日为一岁。岁十二宫,宫有闰日,凡百二十八年而宫闰三十一日。 以 三百五十四日为一周,周十二月,月有闰日。凡三十年月闰十一日,历千九百四十一年,宫月日辰再会。此其立法之大概也。
Islamic calendar
“Islamic Calendar”, by King Mahama of  the Western country Modina, which is situated on 24.5 degrees northern latitude, 107 degrees to the west, about 8000 Chinese miles from Yunnan. The beginning of the era is Kaihuang ji-wei in the Sui Dynasty, which is the year of the establishment of the country. At the beginning of the Hongwu reign period [Jan. 23 1368–Feb. 5, 1399], this book was obtained in the Yuan capital. In the autumn of the fifteenth year [1382], the Emperor said that the Westerners were best in predicting astronomical phenomena, and China did not have their system of coordinates for the celestial bodies. He ordered the Hanlin Academicians Li Chong and Wu Bozong to translate the book with the Muslim master Sheikh Ma.
The method does not use intercalary months. A year has 365 days. The year is divided into 12 signs of the Zodiac, which have leap days, so that 128 years have 31 leap days. 354 days form a lunar year with 12 months which can have leap days. There are 11 leap days in 30 years. In 1941 years the lunar and the solar years coincide again. These are the main points of this calendar.

There are different opinions of the leap year cycle of Persian calendars. This is a relatively early source which clearly describes a very elegant and accurate mathematical calendar with a 128-year leap year cycle.

The prime factors of 1941 are 3 and 647. It is unclear what relevance it has to the calendar.

107° degrees east of Medina is in the Pacific Ocean east of Japan.


  按西域历术见於史者,在唐有《九执历》,元有札马鲁丁之《万年历》。《九执因》最疏,《万年历》行之未久。唯《回回历》设科,隶钦天监,与《大统》参 用二百七十馀年。虽於交食之有无深浅,时有出入,然胜於《九执》、《万年》远矣。但其书多脱误。盗盖其人之隶籍台官者,类以土盘布算,仍用其本国之书。而 明之习其术者,如唐顺之、陈壤、袁黄辈之所论著又自成一家言。以故翻译之本不行於世,其残缺宜也。今为博访专门之裔,考究其原书,以补其脱落,正其讹 舛,为《回回历尖》,著於篇。

The passage mentions older Western calendars, which have mistakes. The Muslim astronomer use books from their own countries and dust board. Dust board presumably refers to calculations with Arabic numerals.


  积年 起西域阿喇必年, 隋开皇己未。 下至洪武甲子,七百八十六年。
Elapsed years
Numbering the years starts from the western Alabi year, Kaihuang ji-wei (599 AD) in the Sui Dynasty. By Hongwu jia-zi (1384 AD) it is 786.

The beginning of the Islamic lunar calendar is 23 years too early because 786 has been taken to mean Chinese years (with intercalary months) instead of Islamic lunar years. The correct date is Friday, 16th July, 622 AD (Julian).
http://makuielys.info/wenz1/show.php?type=hjyanjiu&id=1049895895
This error has persisted until modern times.


The solar calendar starts in
599 AD, 786 solar years before 1384 AD (Shi Yunli, Tao Peipei). This fits the formula in the text.

  用数 天周度三百六十。 每度六十分,每分六十秒,微纤以下俱准此。 宫十二。 每宫三十度。 目周分一千四百四十,时二十四, 每时六十分。 刻九十六。 每刻十五分。 宫度起白羊,节气首春分,命时起午正。 午初四刻属前日。
Numbers used
The circle of heaven is divided into 360 degrees. Each degree has 60 minutes, each minute sixty seconds. These are also used for coordinates. There are 12 signs of the Zodiac, each of them 30 degrees. The day has 1440 minutes, 24 hours of 60 minutes, 96 quarters, each of them 15 minutes. The signs of the Zodiac start from Aries, on spring equinox. Hours are counted from noon. The four quarters before noon belong to the previous day.

It is traditional in the Persian calendar to round the times to the nearest midnight. (Heydari-Malayeri). This is equivalent to having integral days from noon to noon, a system that was also followed by Ptolemy.

  七曜数 日一,月二,火三,水四,木五,金六,土七。 以七曜纪不用甲子。
Days of the week
1. Sunday, 2. Monday, 3. Tuesday, 4. Wednesday, 5. Thursday,  6. Friday, 7. Saturday. The sexagenary cycle is not used.

The names are names of celestial bodies, Sun, Moon, and the planets named after elements, Fire (Mars), Water (Mercury), Wood (Jupiter), Gold (Venus), Earth (Saturn). These names are still used for the days of the week in Japanese.

Qi Zheng Tuibu gives the Persian names which are also ordinal with the counting starting from Sunday.


  宫数 白羊初,金牛一,阴阳二,巨蟹 三,狮子四,双女五,天 秤六,天蝎七,人马八,磨羯九,宝瓶十,双鱼十一。
The signs of the Zodiac

Aries 0, Taurus 1, Gemini 2, Cancer 3, Leo 4, Virgo 5, Libra 6, Scorpio 7, Sagittarius 8, Capricorn 9, Aquarius 10, Pisces 11.

Aries 0, because a sign is also an angle measure, 30°. This seemed to be so in Persian astronomical tables.

  宫日 白羊戌宫三十一日。金牛酉宫三十一日。阴阳申宫三十一 日。巨蟹未宫三十二日。狮子午宫三十一日。双 女巳宫三十一日。天秤辰宫三十日。天蝎卯宫 三十日。人马寅宫二十九日。磨羯丑宫二十九日。宝瓶子宫三十日。双鱼亥宫三十日。 已上十二宫,所谓不动之月,凡三百六十五日,乃岁周之日也。若遇宫分有闰之年,於变鱼宫加一日,凡三百六十六日。
The days of the signs of the Zodiac
Aries 31 days
Taurus 31 days
Gemini 31 days
Cancer 32 days
Leo 31 days
Virgo 31 days
Libra 30 days
Scorpio 30 days
Sagittarius 29 days
Capricorn 29 days
Aquarius 30 days
Pisces 30 days

These twelve signs are known as immovable months. Each period of 365 days is a year. In a leap year Pisces has an extra day and the year contains 366 days.

This is different from the pre-1925 Persian calendar described by Birashk, in which Gemini had 32 days instead of Cancer. The duration of these periods should change from year to year and with precession. Some sources say the pre-1925 solar months were astronomically determined. Afghanistan uses the names of the signs of the Zodiac for months and they are known in Tajik as well.

The duodecimal cycle is used in Chinese but I have omitted it from the translation.

Libra has 31 days in the version of the text I have used as my main source.

  月分大小 单月大,双月小。 凡十二月,所谓动之月也。月大三十日,月小二十九日,凡三百五十四日,乃十二月之日也。遇月分有闰之处,於第十二月内增一日,凡三百五十五日。
Full and hollow months
Odd numbered months are full, even numbered ones hollow. These are so called movable months. A full month has 30 days, a hollow one 29. Each period of 354 days is a period of twelve months. When a month is a leap month a day is added to the twelfth month to make a period of 355 days.

There is no attempt to use the original Arabic names of the months in Chinese, but Qi zheng tuibu gives the Persian names as well. These are used for the solar months in the present Persian calendar.

  太阳五星最高行度 隋己未测定。 太阳二宫二十九度二十一分。 土星八宫十四度四十八分。木星六宫初度八分。火星四宫十五度四分。金星二宫十七度六分。水星七宫六度十七分。

The apogee calculated for 622 AD.

Sun 89°21′
Saturn 254°48′
Jupiter 180°8′
Mars 135°4′
Venus 77°6′
Mercury 216°17′


These values are for
16th July, 622 AD (Julian). However, in the astronomical tables the accumulated change is -10°40′28″ at epoch and 0° in the year 660, so the values are actually for this year, AD 1262. The actual longitude of solar apogee is 89°21′-10°40′28″= 78°40′32″ at epoch.

The Ming History and the astronomical tables give the following values of mean longitudes and mean motion for 16th July, 622 AD (Julian).

first year daily increment In 1440 lunar years
Day of week 6 Friday 1 Sunday 1 Sunday
Sun 116°5′19 59′8″ 160°5′33
Saturn 359°18′ 58′
Jupiter 145°19′ 54′
Mars 274°6′ 28′
Venus 45°29′ 37′
Mercury 85°34′ 3°6′
Apogee -10°40′28 10‴ 12°36′53

From the above table one can calculate a more accurate value of the daily increments. 30 lunar years are 10631 days.

In earlier versions (27.4.2008, 23.5.2008
) the above passage was unfortunately confused and had imcomprehensible mistakes. I hope it is better now.

In the case of linear functions, the Ming History only describes how the tables are made, but Qi Zheng Tuibu has the tables written out. There are different tables of the mean motion for cycles of thirty lunar years, starting from epoch and jumping direct to year 600, as well as for individual years, months, both solar and lunar, and days.

The values derived from the tables are more accurate than the ones given by the Ming History. Huihui Lifa gives instructions for adding or subtracting the smallest units at certain intervals, leap seconds and thirds.
There are obvious mistakes in the tables. Digits may be missing and carried numbers added a few lines too late.

Now I will attempt to calculate the solar longitude at epoch. First, 1′4″ is subtracted from the mean solar longitude. There are different theories about this (Chen Jiujin, Shi Yunli). 116°5′19″ − 1′4″= 116°4′15″.

To get the mean anomaly,
subtract the longitude of the solar apogee from the mean solar longitude. At epoch it is 116°4′1578°40′32″= 37°2343″.

The mean anomaly is used as the index to get the equation of centre. Chen Jiujin (1989) states that the eccentricity is 0.0351295, but this does not generate the maximum value of
2°047″ at 92°. The following Excel function generates values that differ at most one second from the table in Qi Zheng Tuibu within the first 92 degrees:
G$1=0.035135
F2 mean anomaly
=DEGREES(-G$1*SIN(RADIANS(F2)))/(SQRT(1+2*G$1*COS(RADIANS(F2))+G$1^2))

In the table for the equation of the centre in Qi Zheng Tuibu, the value for 37° is
1°1041″. To make interpolation easy the table also gives the difference from the next value, 139″ or 99″. 2343″=1432″. x:99″= 1432″:3600″. x=39.38″. 1°1041″+ 39″ = 1°1120″( 1°1121″with the above Excel formula).

This is subtracted from the mean solar longitude. The solar longitude at epoch is
116°4′15″ −  1°1120″= 114°5255, which is reasonably close to the 114.796 (114°47′45″) given by Calendrica. Shi Yunli has made the same calculation and arrived at 114°5153″. It seems that the correction of 1′4 has not been included in his calculation.

The astronomical tables include the day of the week, which can be used to tie the system to the real world. Year one has Friday, which is
16th July, 622 AD (Julian). The next year in the table for every thirty years has 1 Sunday, which is the first day of the year 601 AH. In the yearly, monthly and daily tables the day indicated is an increment, although the name of the planet is included. Thus, the first year in the yearly table has 4 Wednesday, which means an increment of 4 days (modulo 7) after the 354 days of the first year of the cycle. Similarly, the first month has 2 Monday, a two day increment after a 30-day month. The daily table adds 1 Sunday, 2 Monday etc.

The text says that these should take to the first of Aries, but I cannot see how this is possible since the increments clearly take us to the current day.


  求宫分闰日 无〔 宫?〕之馀日。 置西域岁前积年,减一,以一百五十九乘之, 一百二十八年内,闰三十一日故以总数乘。 内加一十五, 闰应。 以一百二十八屡减之,馀不满之数,若在九十七已上, 闰限。 其年宫分有闰日,已下无闰日。於除得之数内加五, 宫分立成起火三,故须加五。 满七去之,馀即所求年白羊宫一日七曜。 有闰加一日,后同。
Obtaining the leap day for the signs of the Zodiac.
(Extra day in a sign of the Zodiac) Take the years accumulated before the Western year, subtract one, multiply it with 159 (there are 31 leap years in 128 years, so you multiply with the total). Add 15 to it (earlier error) to find the leap year. Repeatedly subtract 128. If the remainder is above 97 (intercalation), it is a leap year. Then add 5 to the quotient of the above division (because the starting point is Tuesday, one has to add 5). Divide by 7 and the remainder is the day of the week of the first day of Aries. (For a leap year add 1.)

This passage has two functions which find whether a solar year is a leap year and what is the day of the week of the first day of the year.

Leap year rule
The following Excel function determines whether the solar year
YS, is a leap year:
=IF(MOD((
YS-1)*159+15;128)>96;"leap";"common")
The year is a leap year if the remainder is greater than 96.

The rule creates a 128-year cycle which consists of the subcycles of 29+3*33 years. Each subcycle begins with four common years followed by a leap year.

97 is the smallest remainder that defines a leap year. Because 97+31=128, this means that the accumulated error carried over from previous years amounts to one full day. The error is checked at the beginning of the year, in other words, the formula finds out how much was left over after the previous year.

The number 15
, called leap constant by Shi Yunli, should mean the fractional days accumulated before the beginning of the era, in this case 15/128 of a day, 2h48'45". Since days are from noon to noon, the spring equinox occurred at 14h48'45" at the beginning of the calendar. However, in the following formulas where we know the longitude better the leap constant has no relation to the actual time of the spring equinox.

The rule described in this passage is a typical rule of the Persian calendar, but it checks the beginning of the year and also calculates the day of the week. Another rule is the one by Abdollahy in Encyclopedia Iranica s.v. Calendars:
=IF(MOD((YS+38)*31;128)<31;"leap";"common")
Mathworld misquotes this using the fractional part of the division instead of the remainder. The fractional part should be <0.24. With a calculator it would be easier to use the fractional part.

To check the end of the year the function should be written =IF(MOD((YS-1)*159+26;128)>96;"leap";"common"

Birashk uses a 2820-year cycle. The following Excel function agrees with his tables:
=IF(MOD((YS-1)*683+558;2820)>2136;";"leap";"common"). The equinox occurred at 5h48'45" after noon on the first day.

The remainder has to be greater than or equal to 2820-683=2137.

Day of the week
The second rule keeps track of the day of the week at the starting point of the era. This Excel function does it correctly:
=MOD(INT(((YS-1)*159+15)/128)+5;7)
This is 5, Thursday, if
YS is 1.

In both formulas the multiplier 159=128+31. The first number keeps track of the day of the week, the second number takes care of the leap years. The 15 in the formulas is the excess fractions of a day accumulated before the beginning of the calendar, 15/128 days.


  求月分闰日 朔之馀日。 置西域岁前积年,减一,以一百三十一年乘之, 总数乘。 内加一百九十四, 闰应。 以三十为法屡减之,馀在十九已上, 闰限。 其年月分有闰闰已下则无。於除得之数,满七去之,馀即所求年第一月一日七曜。
Obtaining the leap day for the lunar months
(Extra day before the new moon) Take the years accumulated before the Western year, subtract one, multiply it with 131 (multiply with the total). Add 194 to it (earlier error). Repeatedly subtract 30. If the remainder is above 19 (intercalation), it is a leap year. Divide the quotient of the above division by 7 and the remainder is the day of the week of first day of the first month.

This passage also has two functions, which generate a standard mathematical Islamic calendar.

Leap year
This function determines whether a year is a leap year:
=IF(MOD((
YL-1)*131+194;30)>18;"leap";"common")
The fractional part should be >0.6 if decimals are used.

Day of the week
This function calculates the day of the week of the first day of the year correctly:
=MOD(INT(((
YL-1)*131+194)/30);7)
The first day of the first year (AD 622) is correctly 6, Friday
, if YL is 1.

The total that is used to multiply means 4*30+11. Since the length of a common year is 354 days the day of the week advances by 4 every common year and the integral part of the quotient changes accordingly.

194=6*30+14 sets the first day of the first year of the era at 6, Friday. The accumulated error is 14/30 days. In Birashk's calendar it is 15/30.

An excursus: In Qizheng tuibu there is a passage which is of interest here:
求中国闰月(至元甲子至洪武甲子计积一百二十一算)
法曰距至元甲子岁为元至所求年内减一算却加一百三十七以一百二十三乘之又加一十以三百三十四除之得数寄左其除不尽之数若在二百一十一已上其年中国有闰月已 下其年中国无闰月若在已上者与三百三十四相减余以四乘之以四十一除之得数即求年中国闰月也
假令除得一数是正月二数是二月余仿此

“Calculating the Chinese leap months (with 121 years between Yuan jia-zi (1324 AD) and Hongwu jia-zi (1384 AD))
”Take the years from Yuan 甲子 (1324 AD), subtract one, add 137 and multiply with 123. Add 10 and divide by 334. If the remainder is above 211, the year is a Chinese leap year. If the remainder is below 211, the year is not a Chinese leap year. If the remainder is above 211, subtract it from 334, multiply the difference by 4 and divide by 41. The quotient is the Chinese leap month.

”If the result [rounded up?] is one, it is the first month, if it is two, it is the second month etc.”

The years are confused. 121 years before Hongwu jia-zi is before the Yuan dynasty rule in China.

According to this formula, there are 123 leap years in 334 years. 334 is the length of a twelfth of the solar year in units of time suitable for the accuracy of the calculation. The lunar year is 123 units shorter. This figure is equivalent to the epact of the Gregorian calendar. The solar year is 4008 units long and the lunar year 3885 units. The ratio 3885:4008 is the ratio of the lunar year to the solar year, although it is not exactly the ratio obtaining in the Huihui lifa. If 123 is divided by 12 the result is 10.25=41/4, the monthly difference, so dividing 334-remainder with 10.25 indicates in how many months an extra lunar month fits into the solar year. This means the formula relies on the mean sun
and the mean moon. The Chinese gave up the mean moon at the beginning of the Tang dynasty, about 619 (Aslaksen).

Alternatively, the solar year is 
12 123/334= 4131/334 lunations but the ramifications of this idea are not yet clear. The ratio of the lunar year to the solar year is 4008:4131.

It is difficult to anchor this scheme in time. The 123/334 formula produces an endless cycle of Metonic cycles with new moons that drift slowly towards the end of the solar year. At 334-year intervals the last new moon moves from February to January. This corresponds to the solar equation in the Gregorian calendar.

The remainder refers to the time before the the last possible new moon (or alternatively the time elapsed from the end of the lunar year). The remainder 0 means the last possible date and 333 the first possible date.

A somewhat fruitful approach is to compare these cycles to the Metonic cycle in the Gregorian calendar. The pattern of remainders and leap years fits an epoch with golden number 3 and epact 24 in the 14th or 15th century according to the Gregorian calendar. This is based on the idea that the last possible date of the New Year is near 20th February, which has epact 9. According to Calendrica the switch of the new moon from February to January takes place in 1423 which would place the epoch on 1351. The next switch is in 1890 while the formula predicts 1757 so there is some latitude in the choice of the epoch.

The pattern of leap years produced by the formula fits the present Chinese calendar for the years 1900-1918 as well, although an astronomical calendar may have exceptions to regular patterns.

A1 Year AD
B1 Years from 1351
C1 Quotient
D1 Remainder
E1 Leap/Common
F1 Leap month
G1 Golden number
A2 1351
B2 =A2-1351
C2 =((B2+137)*123+10)/334
D2 =334*MOD(C2;1)
E2 =IF(D2>=211;1;0)
F2 =IF(E2=1;CEILING((334-D2)/(41/4);1);"")

G2 =MOD(A2;19)+1


The number of leap years before the current year can be found with the formula =TRUNC((A2*123+161)/334)
Since the length of a lunar month is known it should be possible to find the date once the epoch is known.

Supposing the epoch is the new moon in February AD 1351 we can find its Julian date.
Julian date of lunar epoch 1948440
Initial value at lunar epoch: 14/30=168/360
750 years: 750*10631/30=12*750*10631/360
11 months: (11*10631/30)/12=11*10631/360
Days elapsed from lunar epoch:(168+12*750*10631+11*10631)/360=95796109/130=266100+109/360
Chinese New Year AD 1351: 266100+1948440=2214540

This date is two days after Calendrica's Chinese New Year because the Islamic tradition requires that the new moon should be visible. Besides, the day is the first day of the month, not the last day of the previous month. This is probably a mistake in most of my formulas.

Starting from this day any Chinese New Year can be calculated with the following Excel formulas.

A1 AD
B1 years elapsed from 1351
C1 Leap years from 1351
D1 JD
E1 JD in integers
F1 Golden number

A2 2009
B2=A2-1351
C2=TRUNC((B2*123+161)/334)  [perhaps FLOOR is needed]
D2=B2*(10631/30)+C2*((10631/30)/12)+
266100+109/360
E2=TRUNC(D2)
 [to be pasted on Calendrica; perhaps FLOOR is needed]
F2=MOD(A5;19)+1

The golden number is useful for studying the cycles. I have checked the years 2009–2028. All the dates are on the correct new moon, with the Chinese dates usually two days earlier. Calendrica's arithmetic Islamic new moons sometimes differ from the Ming formula.

A remarkable thing is that for the years AD 10000–10018 the agreement is almost as good. The date is even better because it is usually the same as the Chinese New Year. Only year 10001 (and 10020, golden number 8) starts a month earlier according to the Ming formula. The month in question is a leap 12th according to Calendrica while the Ming formula places the leap month two months later.

This is not bad for a little formula from the Ming dynasty meant for human computers who did their calculations on a sand board.
End of excursus [revised 7.9.2009]

  加次法 置积日, 全积并 宫闰所得数。 减月闰内加三百三十一日, 己未春正前日。 以三百五十四 一年数 除之,馀数内减去所加三百三十一,又减二十三, 足成一年日数。 又减二十四, 洪武甲子加次。 又减一, 改应所损之一日。 为实距年 己未至今 得数。又法:以气积 宫闰并通闰为气积 内减月闰, 置十一,以距年乘之,外加十四,以三十除之,得月闰数。 以三百五十四除之,馀减洪武加次二十四,又减补日二十三,又减改应损日一,得数如前。 求通闰,置十一日,以距年乘之。求宫闰前见。
Calculating the Epacts
Start with the total number of elapsed days (based on elapsed days and solar leap days). Subtract the number of lunar leap days, add 331 to reach the beginning of the era (spring equinox of AD 599). Divide it with 354 (the number of days in a year). Subtract from the remainder the 331 that was previously added. Subtract 23 (to a full year). Subtract 24 [years] to attain the year 1384. Subtract 1 once more to compensate for the lost day. The result is the difference between AD 599 and the present day.
Another method: From the accumulated number of solar leap years and general leap years subtract the number of lunar leap years.  (Take 11, multiply it by the difference in years, add 14, divide by 30 and you get the number of leap years.) Divide by 354.  Subtract 24 [years], the addition to Hongwu jia-zi, then subtract 23 and subtract one for the lost day. (To calculate general leap days, take 11 and multiply it by the difference in years. For calculating solar leap years, see above.)

This passage is unclear. Shi Yunli thinks it is a very confusing later addition, probably by Tang Shunzhi 唐顺之 while Tao Peipei thinks that the author is Huang Baijia 黄百家, an editor of the Ming Histories. The passage is made clear by the Nanjing manuscript.

What I translate(with hesitation) as ‘epacts’ means something like ‘adding instances’ and means the numbers that have to be added to the solar year to get the lunar year. They resemble the epact in the Gregorian calendar, but there are separate numbers for the year, month and day, which are separately added to the solar date.

The formula for calculating the number of lunar leap years is clear:
=INT((11*
YL+14)/30)
Shi Yulin gives the corresponding function for solar leap years:
=INT((31*Ys+15)/128)
These refer to a period of years starting from the epoch. If the period starts from another year, the remainder has to be adjusted. For instance, if we want to count the number of lunar leap years during the 24 years preceding and including 1 AH (with the remainder 14), we will have to find the remainder for the first year. We can use the formula =MOD(14-11*23;30). The remainder is 1 and the number of leap years is
INT((11*24+1)/30)=8.

The formula in the text has strange numbers, 331, 23, 24 and 1. The Nanjing manuscript has an example which makes clear that the figure 24 refers to years, while the other figures are days. The numbers are not really explained in Tao Peipei's article, although it is shown that the above formulas give a correct result. The number 8 is regarded as an error and it is said that 331 is very close to 339. Tao Peipei points out that the lunar new year preceding the epoch of the solar calendar is 339 before 1st Aries 599 AD and the following one is 15 days later.

The other numbers have an explanation. 331+15=354, equal to a common lunar year. Adding 331 moves the beginning of the period to a date 8 days short of the previous lunar new year (not the spring equinox as the text says). This will ensure that the leap days of the 24-year period are not counted twice. Then we move back to the original beginning by subtracting the 331 again, and move forward 15+8 days to a point eight days after the lunar new year, again taking care not to count the leap days twice.

Hopefully the following arrangement will clarify the relations between the times.
8 354 24 years
8 331 23
339 15 8
354 8

However, the period of 24 years has 9 leap years and the error is corrected at the end by subtracting 1.

It is not clear why such a complicated procedure is followed. It may be connected to a traditional algorithm.

Moving towards the preceding lunar year is totally unnecessary since at this point lunar leap years are counted and the year in question is a common year. The second method simply moves to the following lunar new year, plus 8.

The example of the Nanjing manuscript shows how to calculate the epacts corresponding to 21st March, 1629, the spring equinox (Julian day
1948440). The procedure calculates the number of days up to the day preceding the spring equinox. There are 1030 solar years (1629-599) containing 1030*365 days, plus 249 73/128 leap days, altogether 376199 73/128 days. Then the lunar leap days are calculated, first for 1030 lunar years, resulting in 378 4/30 days.

Interestingly, the lunar leap days are subtracted in two stages. First 376199-378+331=376152, the total number of days from the lunar new year prceding the solar epoch minus part of the lunar leap days. The resulting number of days is divided by 354 to get the number of years and remaining days, 1062 204/354 years. A preliminary epact is 1062 years 204 days – 331 days – 23 days – 24 years – 1 day = 7 years 203 days (Tao Peipei 2003).

This is then corrected by removing the lunar leap days. The formula is =MOD((Y-1)*11+14;30). This makes two days, so the correct epacts are 7 years 6 months 24 days. These are added to the spring equinox.

years months days
Spring equinox
1030
1 1
epacts 7 6 24
date 1037 7 25

In the example a date 93 days into the year is required. These days have to be separately added.

Proceding in two stages may be connected to the way the leap days in the 24 lunar days are taken into account.


Durations
The duration of a period in years or days are easy to calculate when the accumulated error and length of the year are known. The accumulated error is necessary to keep the leap years in the correct places. The formulas are not mentioned in the Ming dynasty history.

The number of days before the solar year 
Ys can be calculated with the Excel function =INT(((Ys-1)*(365+31/128))+15/128). When the leap constant and the length of the year is known, the leap year fall in their correct places.

If
DS is the number of days, the number of full solar years before the current year can be calculated from =INT((DS-15/128)/(365+31/128)).

The number of days in the lunar calendar before year YL can be calculated with the Excel function =INT(((YL-1)*(354+11/30))+14/30).

If 
DL is the number of days, the number of full lunar years before the current year can be calculated from =INT((DL-14/30)/(354+11/30)).

Converting between the solar and lunar calendar

To convert between the Hui solar and Hijra calendar it is necesary to calculate the number of days since the beginning of the calendars. If you start from the
Hui solar year, you can use the function
=INT(((Ys-1)*(365+31/128))+15/128). Then subtract the difference of the Hui solar and Hijra years from the total. The difference between the solar and lunar calendars is 8520 days.

For
an example, let's check 5th December, 2006 (Julian day 2454075), full moon according to the Gregorian calendar around the time of the writing of these lines. The year is 2006-598=1408. The 1st of Aries is Monday, 20st March ( Julian day 2453815), the 79th day of the Gregorian year (2*30+1-2+20=79; it is easier to count the days above or below 30 separately). The 5th of December is the 339th day of the Gregorian year (11*30+6-2+5=339) and the 261st day of the Hui solar year (339-78=261). Before the beginning of the year there have been INT((1407*(365+31/128))+15/128)=513895 full days and the 5th of December is the 513895+261=514156th day from the epoch of the solar calendar.

Using the formula YL=INT((DL-14/30)/(354+11/30)) we get (514156-8520-14/30)/(354+11/30)=1426 full years, 14/30+1426*(354+11/30)=505327 days. 505375-120-505327=309 days into the year. Ten lunar months make 10*10-5=295 days. You can also use the function =TRUNC(309/29.5). Subtract this from 309 to get the 14th of the eleventh month, 1427 AH, and the day after full moon.

Checking this on the Calendrical Calculations applet, we see that the date is correct.

These formulas can be used to find the epacts that can be added to the epoch of the solar calendar.

Julian days

If the Julian day is known, the following functions may be used to convert to the Hui calendar.
A1 Julian Day
B1 elapsed full solar years
C1 elapsed full days
before the beginning of the solar year
D1 days in the solar year
B1=INT(((A1-1939919)-15/128)/(365+31/128)) preceding full years
C1=INT((B1*(365+31/128))+15/128)
D1=A1-C1-1939919 (for epact D1=A1-C1-1939920)

E1
elapsed full lunar years
F1 elapsed full days before the beginning of the lunar year
G1 days in the lunar year

H1 day of the week
E1=INT(((A1-1948439)-14/30)/(354+11/30))
F1=INT((E1*(354+11/30))+14/30)
G1=A1-F1-
1948439 (for epact  G1=A1-F1-1948440)
H1=MOD(A1+2;7)

Key dates

1939920 Thursday, solar epoch
1948440 Friday, lunar epoch

I have calculated the longitude with the following Excel formulas:
A1 Julian day
B1 mean longitude
C1 change of apogee
D1 apogee
E1 mean anomaly
F1 equation of centre
G1 true longitude
H1 day of the week
A2 1948440
B2 =MOD((A2-1948439)*(59/60+8,3304045/3600)+116+5/60+19/3600-1/60-4/3600;360)
C2=((A2-1948439)*(9/3600+51,5/216000)/60)-(10+40/60+28/3600)
D2 =89+21/60+C2
E2 =B2-D2
F2=DEGREES(-0,035135*SIN(RADIANS(E2)))/(SQRT(1+2*0,035135*COS(RADIANS(E2))+0,035135^2))
G2=B2+F2
H2 =MOD(A2-1948434;7)
The longitudes can be displayed in degrees, minutes and seconds by dividing with 24 and displaying the result in hours, minutes and seconds.




Summary

The History of the Ming Dynasty decribes two calendars from the 14th century, a Persian mathematical solar clendar with the year starting on Thursday, the 1st of Aries, and a conventional Islamic mathematical lunar calendar starting 8520 days later on Fridayday, 16th July, 622 (Julian).

The solar calendar has years of 365 31/128 days and an accumulated error of 15/128 days at the starting point of the calendar. There is a leap year whenever the accumulated error reaches one full day. This can be calculated from the Excel formula
=IF(MOD((YS-1)*159+15;128)>96;"leap";"common").

The weekday of the first day of year
YS can be calculated from the Excel formula =MOD(INT(((YS-1)*159+15)/128)+5;7). This places the beginning of the first year on a Thursday. This is different from the modern Persian calendar, which has the 1st of Aries on a Friday.

The lunar calendar has years of 354 11/30 days with an accumulated error of 14/30 days at the starting point.
There is a leap year whenever the accumulated error reaches one full day. This can be calculated from the Excel formula =IF(MOD((YL-1)*131+194;30)>18;"leap";"common").

The weekday of the first day of year YL can be calculated from the Excel formula  =MOD(INT(((YL-1)*131+194)/30);7). This places the beginning of the first year on a Friday.


Links and references


Aslaksen, Helmer: Fake Leap Months in the Chinese Calendar:From the Jesuits to 2033.
http://www.math.nus.edu.sg/aslaksen/calendar/ichsea.pdf

Bär, Nikolaus A.
Iranische Zeitrechnungen
http://www.nabkal.de/irankal.html
Nasir ed-Din Tusi has lists of early leap years according to the Maliki calendar. They reveal no pattern of cycles.

Birashk. A Comparative Calendar of the Iranian, Muslim Lunar, and Christian Eras for Three Thousand Years. Persian Studies Series, No. 15. Mazda Publishers, 1993.
This book may not be fully trustworthy. The 1925 law says nothing about the 2820-year cycle, and the pre-1925 months were astronomically determined (Roozbeh Pournader, personal communication).

Fitzpatrick, Richard. A Modern Almagest: An updated version of Ptolemy's Almagest.
http://farside.ph.utexas.edu/syntaxis/Almagest.pdf
An excellent site which is reasonably close to the format of the astronomical tables.

Heydari-Malayeri, M.: A concise review of the Iranian calendar


Ptolemy’s Almagest (transl. and annotated by G. J. Toomer, London 1984)

Calendrical Calculations applet
Some glitches with MacOS 10.2.3. With MacOS 10.4.11 Safari refreshes the window three times before showing the result.

Colloquium No. 6 - Fung Kam Wing - 香港科技大學圖書館善本書室開幕 ...
Chinese and Muslim contacts

Encyclopedia Iranica: Calendars
A very detailed entry but not very clear on eras and early leap year rules.

Iranian Calendar -- from Eric Weisstein's World of Astronomy

Ma Zhaozeng. Converting between the Islamic, Gregorian and Chinese Calendars
马 肇曾 回历、公历、农历的换算
This text uses decimal numbers for conversion. There are numerous versions of this text, but I have not found one which contains the original tables.

Ming History 明 史
There are numerous versions online. The text is from this one, but because of the numerous mistakes the Academica Sinica version has also been used. This version has no tables.
http://www.sinica.edu.tw/ftms-bin/ftmsw3
The Islamic calendar description is on pages 744–880 of this version the Ming History. Starting from page 516 there is some history and comparison of calendars. The tables start on page 775. The site is hard to use.

Françoise Aubin. Notule sur les mathématiques et l’astronomie islamiques en Chine
http://science-islam.net/article.php3?id_article=554&lang=fr

Bagheri, Mohammad Books I and IV of Kūshyār ibn Labbān's Jāmic Zīj: An Arabic Astronomical Handbook by an Eleventh-Century Iranian Scholar /  - [S.l.] : [s.n.], 2006- Doctoral thesis Utrecht University
http://igitur-archive.library.uu.nl/dissertations/2007-0109-200521/

Jing Bing
Acceptance of Chinese Calendars, Sonmyong-ryok and Susi-ryok by Koryo Scholars
This has some traditional terms.


Shi, Yunli. 2003. The Korean Adaptation of the Chinese-Islamic Astronomical Tables. Arch. Hist. Exact Sci. 57 (2003) 25–60.
http://www.ihns.ac.cn/readers/2004/shiyunli1.pdf
This paper, a freely downloadable copy of which was found only after I uploaded the first version of the page.

Tao Peipei. Study on the Huihui Lifa Collected by Nanjing Library. Studies in the History of Natural Sciences, 2003 Vol.22 No.2 P.117-12
陶 培培∶南 京图书馆藏清抄 本《回回历法》 研究
The library copy has a full description of the method to calculate the time interval between the solar and lunar calendars. This paper can be downloaded for a few cent from
http://club.cqvip.com.

A short description which includes the Arabic names of the months
http://samuel.lamost.org/basic/dict/baike/twdbk28595.html

The same in a better format:
http://www.17348.com/wiki/%E4%BC%8A%E6%96%AF%E5%85%B0%E5%8E%86%E6%B3%95

七政推步 Qi zheng tuibu (
ISBN: 6669168055)
A fuller edition of the calendar with astronomical tables. Unfortunately this is a facsimile edition with many pages illegible.

回 回万年历 A modern Islamic calendar for sale. Example pages.
http://www.islambook.net/shop/hhwyl.htm

中国天文史
http://www.ikepu.com/astronomy/astronomy_history/china_astronomy_total.htm Mentions a few other names.

Yan Linshan: Islamic observatories
阎林山:
回回司天台
http://www.islamcn.net/article/list.asp?id=426 

Chen Jiujin: A detailed explanation of the principles of the lunar and solar eclipses in the Hui calendar
陈久金:回 历日月食原理
《自然科学史研究》-1990年9卷2期 -119-131页
Studies In The History of Natural Sciences, Vol. 9 No. 1 (1989), 119–131

Chen Jiujin: The calculation of the sun and the moon and geometric models of their motions in the Hui calendar
陈久金:回历 日月位置的计 算及其运动的几何模型 陈久金
《自然科学史研究》1989 年8卷3期-219-229页
Studies In The History of Natural Sciences, Vol. 8 No. 3 (1989), 219–229

Yang Yi: A study on the geometrical model explaining the movement of planets in Islamic calendar
杨怡:回历行 星运动几何模型之研究
《自然科学史研究》1991年10卷3期
Studies In The History of Natural Sciences, vol. 10 No. 3 (1991), 246–248

Time and Date of Vernal Equinox
http://aom.giss.nasa.gov/srver4x3.html

Hermetic Systems: Dates and Times of Equinoxes and Solstices
http://www.hermetic.ch/cal_sw/ve/ve.htm

Homepage