An Islamic calendar date class

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.

The lunar year

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.

The 30-year cycle

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.

Months

MonthNumberDays
Muharram130
Safar229
Rabi al-Awwal330
Rabi al-Thani429
Jumada al-Ula530
Jumada al-Akhirah629
Rajab730
Sha'ban829
Ramadan930
Shawwal1029
Dhu al-Qadah1130
Dhu al-Hijjah1229 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.

How a calendar class could work

A possible implementation could proceed as follows:

  1. Determine the position of the year in the 30-year cycle and whether it is a leap year.
  2. Determine the length of each month from its number, adjusting the twelfth month in a leap year.
  3. Count the days in complete 30-year cycles, the remaining complete years, and the preceding months of the requested year.
  4. Add the day of the month to obtain an absolute day count from a chosen Islamic epoch.
  5. Convert the absolute day count to a Julian or Gregorian date, or reverse the calculation to obtain an Islamic date.

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.

Choosing the epoch

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.

Why calculated dates may differ from religious practice

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.

Comments and disclaimer

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.