The API uses the Date And Time Handling API. The date can be set and extracted from the calendar using the TDateTime
class, which is a calendar-independent representation of the date.
The API consists of two calendar classes with a common base class and two calendar-specific date classes. The calendar classes are
which stores a Gregorian date, and TGregorianCalendar
which stores a Chinese date. Both calendar classes derive from the base class TChineseCalendar
, which internally stores the date as a Julian day value (a number of days since 24/11/4713 BC). The Gregorian date (year, month, day) is represented by TCalendar
and the Chinese date (year cycle, year, month, leap month and day) by TArithmeticalDate
.TChineseDate
To convert dates both ways between the Chinese and Gregorian calendars, use TCalendar::operator=()
. For example, the following code fragment converts a date stored in the Gregorian calendar into the Chinese calendar:
TArithmeticalDate date;
date.iYear=2001;
date.iMonth=1;
date.iDay=24; // 24th January 2001
TChineseCalendar chineseCalendar;
TGregorianCalendar gregorianCalendar;
gregorianCalendar.SetDate(date);
static_cast<TCalendar&>(chineseCalendar)=gregorianCalendar;
TChineseDate chineseDate;
chineseCalendar.GetDate(chineseDate); // cycle=78, Year=18, Month=1, Day=1 (New Year's day)
This is possible because both Chinese and Gregorian calendars are derived from TCalendar
, which stores the date as a Julian day value. TCalendar::operator=()
simply assigns the Julian day value stored in one calendar to another.
To extract the date from the calendar, use GetDate()
. This gets the date as a TArithmeticalDate
or a TChineseDate
. The date can also be extracted as a TDateTime
(note that with TDateTime
, the month and day values begin at zero).