The Sentience

The Sentience

Monday, July 11, 2011

The Hindu Calendar

Introduction
Hindu Calendars are by far the nearest approaches to the actual machinery of astronomical phenomena governing life on our planet. (Hashim Amir Ali)

The are more than 30 variations of the calendars used in India, the best known of which is the classical Hindu Calendar Surya Siddhanta which is said to have been revealed to Asura Maya the Assyrian at the end of the last Golden Age (2,163,154 BCE). The Hindu lunisolar calendar is similar to the Chinese calendar, but varies in terms of application of fixed ancient methods to approximate true sun and true moon, based on sidereal year. Hindu longitudes are sidereal, having their origin near Piscium, the 6th brightest star in Pisces. However, having sidereal longitudes doesn't really affect the calculations. The calendar is lunisolar in the sense that it uses lunar months to approximate the sidereal year. The epoch used for Hindu calendars dates to January 23, -3101 in the Gregorian Calendar. The era in the Indian calendar is called the Vikram Era, or the Vikram Samvat, which began in 57 BCE.

There are two types of Hindu Lunisolar Calendars:
  • Amanta - one which is based on new moon ending of the lunar month
  • Parimanta - the other is based on full moon ending of the lunar month
I would be designing the Amanta Lunisolar Calendar for KCalendarSystem.

The Month
The amanta month runs from new moon to the next new moon. Each amanta month and hence the lunar year are expressed in integral number of civil days. The lunar month is either 29 or 30 civil days long but always comprises of 30 lunar days. In general, the month is named after the solar month in which the moment of its defining initial new moon falls. The month is divided into two halves, the sudi and the vadi. The sudi half is also known as the sukla paksha or the bright half-month, covering the time period from new moon to the next full moon. The vadi half, also known as the krishna paksha or the dark half-month, covers the period from the full moon to the next new moon.

There are twelve months in Hindu lunar Calendar:

  1. Chaitra (चैत्र, चैत)
  2. Vaishakh (वैशाख, बैसाख)
  3. Jyeshtha(ज्येष्ठ, जेठ)
  4. Ashadha (आषाढ, आषाढ़)
  5. Shravana (श्रावण, सावन)
  6. Bhadrapada (भाद्रपद, भादो)
  7. Ashwin (आश्विन)
  8. Kartik (कार्तिक)
  9. Margashirsha (मार्गशीर्ष, अगहन)
  10. Paush (पौष)
  11. Magh (माघ)
  12. Phalgun (फाल्गुन)
Leap Months
The lunar calendar year is shorter than the solar sidereal year and hence leap months are occasionally added at intervals to keep the lunar calendar and the solar calendar in sync. When a solar month completely covers a lunar month, that is when there are two new moons (one falling at the beginning and the other falling at the end of the solar month), the lunar month that begins at the first new moon is treated as a leap month and is prefixed with the title adhika. An adhika month generally occurs at average intervals of 2 years 8.4 months.

Missing Months
Very rarely, the lunar month can completely cover a solar month, i.e, there is no new moon falling in that solar month and hence no lunar month naming after it. This missing month is called the kshaya or decayed month. When a kshaya month occurs in a lunar year, there will always be two adhika months (one before and on after the kshaya month).

Days
In the Hindu calendar, the day starts with local sunrise. It is allotted five properties, called angas. They are:
  • the tithi (one of 30 divisions of a synodic month) active at sunrise
  • the vaasara, vaar (ravi-vaar, som-vaar, etc.) or weekday
  • the nakshatra (one of 27 divisions of the celestial ecliptic) in which the moon resides at sunrise
  • the yoga (one of 27 divisions based on theecliptic longitude of the sun and moon) active at sunrise
  • the karana (divisions based on tithis) active at sunrise.
Together these are called the panchangas.

Vaar refers to the days of the week and bear striking similarities with the names of the week in many western cultures:

No.↓

Sanskrit name of
the weekday
Celestial object
1

Ravi vaar रविवार Sun
2

Soma vaar सोमवार Moon
3

Mangala vaar मंगलवार Mars
4

Budha vaar बुधवार Mercury
5

Guru vaar गुरुवार
or
Bruhaspati vaar बृहस्पतिवार
Jupiter
6

Shukra vaar शुक्रवार Venus
7

Shani vāsara शनिवार Saturn

Day numbers are determined by the tithi, the time required by the longitude of the moon to increase by 12 degrees over the longitude of the Sun. Sometimes we call it a lunar day. There are 29 or 30 days in a lunar month. Each day is assigned the number of the tithi in effect at sunrise,. However, days are not always counted serially from 1 to 29 or 30. To understand why, it is important to note the fact that the value of a tithi varies from 19.48 hours to 26.78 hours. A short tithi, may begin after sunrise and end before the next sunrise. In this case, a number is omitted from the day count and hence we have skipped a kshaya day. Similarly, a longer tithi may span two sunrises, i.e., there is no tithi ending in that day. Then a day number is carried over to the second day and is treated as a leap day, suffixed by the term adhika.

Thursday, July 7, 2011

The Chinese Lunisolar Calendar

The header file defining the implementation of Chinese Lunisolar Calendar is kcalendarsystemchinese.h. It has defined two classes:

KCalendarSystemChinese

Class definition in the public domain, publicly inherited from KCalendarSystem. It re-implements the virtual functions defined in the KCalendarSystem class. The re-implemented functions are defined in the public domain of the class.

virtual QString calendarType() const

Returns the calendar system type.

virtual QDate epoch() const

Returns a QDate holding the epoch of the calendar system. Chinese epoch is defined on Julian Day 758326. (8th March 2637 BCE in Julian Calendar)

virtual QDate earliestValidDate() const

Returns the earliest date valid in this calendar system implementation, i.e. the epoch of the calendar system as the Chinese calendar is not proleptic

virtual QDate latestValidDate() const

Returns the latest date valid in this calendar system implementation, i.e. 30th December 9999 in Chinese Calendar (which becomes 5th February 7303 in Gregorian Calendar).

virtual bool isValid(int year, int month, int day) const

Returns whether a given date is valid in this calendar system.

virtual bool isValid(const QDate &date) const

Returns whether a given date is valid in this calendar system.

virtual bool isLeapYear(int year) const

Returns whether a given year is a leap year.

virtual bool isLeapYear(const QDate &date) const

Returns whether a given year(taken from the QDate) is a leap year.

virtual QString monthName(double month, int year, MonthNameFormat format = LongName) const

Gets specific calendar type month name for a given month number If an invalid month is specified, QString() is returned. The double data type is used for the month to implement functionalities requiring leap months in the Chinese calendar.

virtual QString monthName(const QDate &date, MonthNameFormat format = LongName) const

Gets specific calendar type month name for a given date.

virtual QString weekDayName(int weekDay, WeekDayNameFormat format = LongDayName) const

Gets specific calendar type week day name. If an invalid week day is specified, QString() is returned.

virtual QString weekDayName(const QDate &date, WeekDayNameFormat format = LongDayName) const

Gets specific calendar type week day name.

virtual int weekDayOfPray() const

Returns the weekday of pray for this calendar system, i.e. Sunday (7th day of the Chinese Week).

virtual bool isLunar() const

Returns whether the calendar is lunar. (False)

virtual bool isLunisolar() const

Returns whether the calendar is lunisolar. (True)

virtual bool isSolar() const

Returns whether the calendar is solar. (False)

virtual bool isProleptic() const

Returns whether the calendar is proleptic, i.e, supports dates before the epoch. (False)

KCalendarSystemChinesePrivate

Class definition in the private domain, publicy inherited from KCalendarSystemPrivate. It re-implements the virtual functions defined in the KCalendarSystem class. The re-implemented functions are defined in the public domain of the class.

virtual AstroLocale* chineseLocation(int date)

Defines the Chinese Locale(as explained in the previous section) for implementing the Chinese Calendar

double midnightInChina(int date)

Computes the Chinese Universal Time for implementing astronomical calculations

int currentMajorSolarTerm(int date)

Returns the major solar term number at the given date, after computing the solar longitude at the given date.

int winterSolsticeOnOrAfter(int date)

Returns the date of December Solstice on or after the given date.

int chineseNewMoonOnOrAfter(int date)

Returns the date when the New Moon is observed at the Chinese Locale on or after the given date.

int chineseNewMoonBefore(int date)

Returns the date when the New Moon is observed at the Chinese Locale before the given date.

bool noMajorSolarTerm(int date)

Checks whether the month containing the given date has a major solar term or not.

bool priorLeapMonth(int m1, int m2)

Checks whether there is a leap month from the date m1(inclusive) to date m2.

int newYearInSui(int date)

Returns the starting date of Chinese New Year after December Solstice.

int newYearOnOrBefore(int date)

Returns the date of Chinese New Year on or before the given date.

void chineseDateToJulianDay(int year, double month, bool leap, int day, int &jd)

Converts Chinese date to Julian day.

void julianDayToChineseDate(int &year, double &month, bool &leap, int &day, int jd)

Converts Julian day to Chinese date. An indicator value (o.5) is added to the month to denote that it is a leap month.

virtual KLocale::CalendarSystem calendarSystem() const

Returns the calendar type.

virtual int monthsInYear(int year) const

Returns the number of months in the year used by this calendar system.

virtual int daysInMonth(int year, double month) const

Returns the number of days in a month used by this calendar system. The double data type implements functionalities for leap months.

virtual int daysInYear(int year) const

Returns the number of days in a year used by this calendar system.

virtual int daysInWeek() const

Returns the number of days in a week used by this calendar system, i.e, 7.

virtual bool isLeapYear(int year) const

Checks whether a year is a leap year or not.

virtual bool hasLeapMonths() const

Returns true is this calendar system has leap months. The Chinese calendar has leap months.

virtual bool hasYearZero() const

Returns true is this calendar system uses year 0. The Chinese calendar doesn't have a year 0.

virtual int maxDaysInWeek() const

Returns the maximum number of days in a week in this calendar system, i.e, 7.

virtual int maxMonthsInYear() const

Returns the maximum number of months in a year in this calendar system, i.e. 13.

virtual int earliestValidYear() const

Returns the earliest valid year in this calendar system, i.e., year 1.

virtual int latestValidYear() const

Returns the latest valid year in this calendar system, i.e., year 9999.

virtual QString monthName(double month, int year, Locale::DateTimeComponentFormat format, bool possessive) const

Gets specific calendar type month name for a given month number If an invalid month is specified, QString() is returned.

virtual QString weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const

Gets specific calendar type weekday name for a given month number If an invalid weekday is specified, QString() is returned.

Astronomical Implementation

Re-implementations of the functions dateToJulianDay() and julianDayToDate() using the functions defined in the Astro Library.

bool julianDayToDate(int jd, int &year, double &month, double &day) const

Returns the date implemented in this calendar system from Julian day. It implements the previously defined julianDayToChineseDate() function. The double data type for month and days implement the functionalities of leap months and leap days (as in the Hindu Calendar).

bool dateToJulianDay(int &jd, int year, double month, double day) const

Returns the Julian day from the date in this calendar system. It implements the previously defined chineseDateToJulianDay() function.

Astro Library

Most of the astronomical functions have already been described in the implementation of Chinese Calendar. A few functions were appended to the Astro Library, namely:

astro.h

int roundOff(double value)

Rounds off the double value to the integer value

astrolunar.h

double newMoonBefore(double time)

Returns the moment of a New Moon occurrence before the given time

double newMoonAtOrAfter(double time)

Returns the moment of a New Moon occurrence at or after the given time

astrosolar.h

double estimatePriorSolarLongitude(double longitude, double time)

This function has an important role to play in implementing astronomical solar calendars, as it determines a particular solar longitude on or before the given date. The solar longitude can correspondingly help to find the day of the New Year as per the astronomical calendar.

The calculations for implementing the Chinese Calendar have been derived from the public domain Lisp code/Mathematical functions of Calendrical Calculations by Edward M. Reingold on the Illinois Institute of Technology website, and from the book Astronomical Algorithms by Jean Meeus.