The following is an exercise in calendar design intended for teaching purposes. We will consider how a class could implement one mathematical version of the Islamic (Hijri) calendar, using fixed arithmetic rules rather than observations of the Moon.
The Islamic calendar is lunar, not lunisolar. It has twelve months each year and does not insert leap months to keep the calendar aligned with the seasons. As a result, Islamic months move through the seasons over time.
A mean lunar month lasts approximately 29.53059 days. Twelve such months total approximately 354.37 days, around eleven days less than a tropical year. A calendar cannot use fractional days for ordinary date labels, so its months must be assigned whole numbers of days.
In the tabular Islamic calendar described here, odd-numbered months have 30 days and even-numbered months have 29 days. In an ordinary year, the twelve months therefore contain 354 days. In a leap year, the twelfth month receives an additional day, making a 355-day year.
This mathematical calendar uses a repeating cycle of 30 years, containing 19 ordinary years and 11 leap years. The leap years are years 2, 5, 7, 10, 13, 16, 18, 21, 24, 26, and 29 within each 30-year cycle.
The cycle contains 10,631 days, giving an average year length of 354 + 11/30 days and an average month length of approximately 29.53056 days. This is very close to the average astronomical lunar month, although it is not exactly equal to it.
Because the pattern is fixed, the calendar can be calculated for arbitrarily distant years without knowing the future weather or observing the Moon.
| Month | Number | Days |
|---|---|---|
| Muharram | 1 | 30 |
| Safar | 2 | 29 |
| Rabi al-Awwal | 3 | 30 |
| Rabi al-Thani | 4 | 29 |
| Jumada al-Ula | 5 | 30 |
| Jumada al-Akhirah | 6 | 29 |
| Rajab | 7 | 30 |
| Sha'ban | 8 | 29 |
| Ramadan | 9 | 30 |
| Shawwal | 10 | 29 |
| Dhu al-Qadah | 11 | 30 |
| Dhu al-Hijjah | 12 | 29 or 30 |
The final month has 30 days in a tabular leap year and 29 days otherwise. The spellings of month names vary when transliterated into English.
A possible implementation could proceed as follows:
For positive year numbers, the tabular leap-year rule can also be implemented using integer arithmetic. Care is needed when extending the calculation to years before the epoch, since programming languages may differ in their conventions for division and remainder with negative integers.
Islamic years are traditionally numbered from the Hijra, the migration of Muhammad from Mecca to Medina in 622 CE. For this particular tabular calendar, a commonly used civil epoch assigns 1 Muharram, year 1, to 16 July 622 in the Julian calendar. Other calendar conventions may use a different epoch or day boundary.
The Julian date must not be confused with a proleptic Gregorian date. A conversion program should specify exactly which civil calendar it uses when identifying the epoch.
Traditionally, the beginning of an Islamic month is associated with the sighting of the first visible crescent Moon after the astronomical new moon. This is not the same event as the instant of the astronomical new moon, and it is not determined by the fixed 29-day and 30-day pattern used in this exercise.
Actual visibility depends on the positions of the Sun and Moon, the observer's location, atmospheric conditions, and the criteria used for accepting a sighting. Religious communities and authorities also differ in whether they require local observations, accept observations from elsewhere, or use astronomical calculations.
Consequently, the tabular calendar is fully predictable but its dates need not match the dates declared by a particular religious authority. Differences of one day are common, and larger differences are possible. In particular, the dates of Ramadan and the two Eids should not be inferred from this mathematical model when an official local religious date is required.
The purpose of this exercise is to demonstrate how a lunar calendar can be implemented with a short, repeating mathematical cycle, and how its dates can be converted to and from a common era calendar. It is not a model of actual crescent sightings and should not be used to determine religious observances without consulting the appropriate community or authority.