Skip to the content of the web site.

Project O.2: Printing the Islamic calendar

Write a program that prints the Islamic calendar for a given year starting at 1. As of the authoring of this file, January 22, 2019, it is the year 1440 of the Islamic calendar.

The Islamic calendar is a lunar calendar, and therefore each year is either 354 or 355 days. Each month begins with the start of the lunar cycle. If a new crescent Moon following a New Moon is seen just after Sunset, that day is the start of the next month (the day begins at sunset); otherwise, the day thereafter is the first day of the next month.

A calendar based on astronomical observation cannot be calculated unless one were to create a reasonable model of the Earth and Moon in relation to the Sun determining start of the next month based on the exact alignment of the Sun, Moon and Earth. You are welcome to attempt such a model.

Some Islamic communities use a formulaic approach. Here is one such approach you can program:

  1. Each year has twelve months.
  2. Odd numbered months have 30 days and even numbered months have 29 days, with one exception.
  3. Using a 30-year cycle, years 2, 5, 7, 10, 13, 16 18, 21, 24, 26 and 29 are leap years, whereby the last month has 30 days instead of 29.

Request from the author: this author is attempting to understand the days of the week for such a calendar as described here. If someone with greater understanding of the Islamic calendar would like to describe relationship between the days of the week and the Islamic year, please contact Douglas Harder. Thank you.

The lunar month is approximately 29.53058796 days, so without the leap years, the average 29.5 day calendar would drift relative to the Lunar cycle. The introduction of 11 leap years in each 30-year cycle gives the formula $29.5 + \frac{11}{30\cdot 12} = 29.530\overline{5}$, yielding a relative error of less than 0.00011% per month.

Incidentally, the next best approximation to the lunar calendar would be to have 29 leap years every 79 years, yeilding $29.5 + \frac{29}{79\cdot 12} = 29.53\overline{0590717299578}$, yielding a relative error of less than 0.00000933%; approximately a factor of 12 better.