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 TGregorianCalendar
which stores a Gregorian date, and TChineseCalendar
which stores a Chinese date. Both calendar classes derive from the base class TCalendar
, 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 TArithmeticalDate
and the Chinese date (year cycle, year, month, leap month and day) by 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).