/** Gregorian Solar Calendar and Chinese Lunar Calendar; The Gregorian calendar. The lunar calendar. The festival; The time zone. Solar terms; Power; Zodiac * 1900-2100 super cool……

void Lunar(COleDateTime tmMeas);

static const int m_lunarInfo[]; 

static const CString m_GAN[]; 

static const CString m_ZHI[]; 

static const CString m_Animals[]; 

static const CString m_nStr1[]; 

static const CString m_nStr2[]; 

static const CString m_lFtv[];

static const int m_solarMonth[];    

static const CString m_solarTerm[];   

static const int     m_sTermInfo[]; 

static const CString m_monthName[]; 

static const CString m_sFtv[];

static const CString m_wFtv[];

int getMonthDays(int y,int m);

int getSTerm(int y,int n);

CString getWordDay(int d);

CString getYearName(int y);

CString getGZ(LONGLONG num);

void parseFtv(CString strInfo,int& nFirst,int& nLast,CString& strDesc,BOOL& bStrong);

int getWeekOfMonth(int y,int m,int d);

int getWeeksOfMonth(int y,int m);

LONGLONG getUTC(int nYear,

const int CLunar::m_lunarInfo[]={ 

0x4bd8,0x4ae0,0xa570,0x54d5,0xd260,0xd950,0x5554,0x56af,0x9ad0,0x55d2,

0x4ae0,0xa5b6,0xa4d0,0xd250,0xd255,0xb54f,0xd6a0,0xada2,0x95b0,0x4977,

0x497f,0xa4b0,0xb4b5,0x6a50,0x6d40,0xab54,0x2b6f,0x9570,0x52f2,0x4970,

0x6566,0xd4a0,0xea50,0x6a95,0x5adf,0x2b60,0x86e3,0x92ef,0xc8d7,0xc95f,

0xd4a0,0xd8a6,0xb55f,0x56a0,0xa5b4,0x25df,0x92d0,0xd2b2,0xa950,0xb557,

0x6ca0,0xb550,0x5355,0x4daf,0xa5b0,0x4573,0x52bf,0xa9a8,0xe950,0x6aa0,

0xaea6,0xab50,0x4b60,0xaae4,0xa570,0x5260,0xf263,0xd950,0x5b57,0x56a0,

0x96d0,0x4dd5,0x4ad0,0xa4d0,0xd4d4,0xd250,0xd558,0xb540,0xb6a0,0x95a6,

0x95bf,0x49b0,0xa974,0xa4b0,0xb27a,0x6a50,0x6d40,0xaf46,0xab60,0x9570,

0x4af5,0x4970,0x64b0,0x74a3,0xea50,0x6b58,0x5ac0,0xab60,0x96d5,0x92e0,

0xc960,0xd954,0xd4a0,0xda50,0x7552,0x56a0,0xabb7,0x25d0,0x92d0,0xcab5,

0xa950,0xb4a0,0xbaa4,0xad50,0x55d9,0x4ba0,0xa5b0,0x5176,0x52bf,0xa930,

0x7954,0x6aa0,0xad50,0x5b52,0x4b60,0xa6e6,0xa4e0,0xd260,0xea65,0xd530,

0x5aa0,0x76a3,0x96d0,0x4afb,0x4ad0,0xa4d0,0xd0b6,0xd25f,0xd520,0xdd45,

0xb5a0,0x56d0,0x55b2,0x49b0,0xa577,0xa4b0,0xaa50,0xb255,0x6d2f,0xada0,

0x4b63,0x937f,0x49f8,0x4970,0x64b0,0x68a6,0xea5f,0x6b20,0xa6c4,0xaaef,

0x92e0,0xd2e3,0xc960,0xd557,0xd4a0,0xda50,0x5d55,0x56a0,0xa6d0,0x55d4,

0x52d0,0xa9b8,0xa950,0xb4a0,0xb6a6,0xad50,0x55a0,0xaba4,0xa5b0,0x52b0,

0xb273,0x6930,0x7337,0x6aa0,0xad50,0x4b55,0x4b6f,0xa570,0x54e4,0xd260,

0xe968,0xd520,0xdaa0,0x6aa6,0x56df,0x4ae0,0xa9d4,0xa4d0,0xd150,0xf252,

const CString CLunar::m_GAN[]={ 

 _T("甲"),_T("乙"),_T("丙"),_T("丁"),_T("戊"),_T("己"),_T("庚"),_T("辛"),

const CString CLunar::m_ZHI[]={ 

 _T("子"),_T("丑"),_T("寅"),_T("卯"),_T("辰"),_T("巳"),_T("午"),_T("未"),

 _T("申"),_T("酉"),_T("戌"),_T("亥")  

const CString CLunar::m_Animals[]={ 

 _T("鼠"),_T("牛"),_T("虎"),_T("兔"),_T("龙"),_T("蛇"),_T("马"),_T("羊"),

 _T("猴"),_T("鸡"),_T("狗"),_T("猪")

const CString CLunar::m_nStr1[]={ 

 _T("日"),_T("一"),_T("二"),_T("三"),_T("四"),_T("五"),_T("六"),_T("七"),

const CString CLunar::m_nStr2[]={ 

 _T("初"),_T("十"),_T("廿"),_T("卅"),_T("□")

const int CLunar::m_solarMonth[]={    

31,28,31,30,31,30,31,31,30,31,30,31

const CString CLunar::m_solarTerm[]={   

 _T("小寒"),_T("大寒"),_T("立春"),_T("雨水"),_T("惊蛰"),_T("春分"),_T("清明"),

 _T("谷雨"),_T("立夏"),_T("小满"),_T("芒种"),_T("夏至"),_T("小暑"),_T("大暑"),

 _T("立秋"),_T("处暑"),_T("白露"),_T("秋分"),_T("寒露"),_T("霜降"),_T("立冬"),

 _T("小雪"),_T("大雪"),_T("冬至")

const int CLunar::m_sTermInfo[]={ 

0,21208,42467,63836,85337,107014,128867,150921,173149,195551,218072,240693,

263343,285989,308563,331033,353350,375494,397447,419210,440795,462224,483532,

const CString CLunar::m_monthName[]={ 

 _T("JAN"),_T("FEB"),_T("MAR"),_T("APR"),_T("MAY"),_T("JUN"),_T("JUL"),_T("AUG"),

 _T("SEP"),_T("OCT"),_T("NOV"),_T("DEC")

const CString CLunar::m_sFtv[]={ 

 _T("0321 世界森林日 消除种族歧视国际日"),

 _T("0401 愚人节 全国爱国卫生运动月(四月) 税收宣传月(四月)"),

 _T("0701 中国共产党建党日 世界建筑日"),

 _T("0908 国际扫盲日 国际新闻工作者日"),

 _T("1001*国庆节 世界音乐日 国际老人节"),

 _T("1010 辛亥革命纪念日 世界精神卫生日"),

 _T("1111 国际科学与和平周(本日所属的一周)"),

 _T("1129 国际声援巴勒斯坦人民国际日"),

 _T("1205 国际经济和社会发展志愿人员日"),

 _T("1213 南京大屠杀(1937年)纪念日!紧记血泪史!"),

const CString CLunar::m_wFtv[]={

 _T("1013 国际减轻自然灾害日(减灾日)"),

const CString CLunar::m_lFtv[]={

 _T("0323 妈祖生辰 (天上圣母诞辰)"),

int CLunar::getYearDays(int y)

for(i=0x8000; i>0x8; i>>=1)

  sum += (m_lunarInfo[y-1900] & i)? 1: 0;

return(sum+getLeapDays(y));

int CLunar::getLeapDays(int y)

return((m_lunarInfo[y-1899]&0xf)==0xf? 30: 29);

int CLunar::getLeapMonth(int y)

int lm = m_lunarInfo[y-1900] & 0xf;

int CLunar::getMonthDays(int y,int m)

return((m_lunarInfo[y-1900] & (0x10000>>m))? 30: 29 );

CString CLunar::getGZ(LONGLONG num) {

return m_GAN[num%10] + m_ZHI[num%12];

int CLunar::getSTerm(int y,int n)

 LONGLONG lUtc1=-22085493000000000; 

 LONGLONG lUtc2=-116444736000000000; 

 ULONGLONG lDate=315569259747000;

 lDate += UInt32x32To64(600000000,m_sTermInfo[n]);

 FileTimeToSystemTime((FILETIME*)&lDate,&st);

void CLunar::Lunar(COleDateTime tmMeas)

int y = m_tmMeas.GetYear();

int m = m_tmMeas.GetMonth();

int d = m_tmMeas.GetDay();

 ASSERT(y>1899 && y<2101);

 m_cYearName=getYearName(y);

int offset=static_cast<int>(getUTC(y,m,d)/864000000000 - getUTC(1900,1,31)/864000000000);

for(i=1900; i<2100 && offset>0; i++) { temp=getYearDays(i); offset-=temp; }

if(offset<0) { offset+=temp; i--; }

for(i=1; i<13 && offset>0; i++) {

if(leap>0 && i==(leap+1) && (!m_isLeap))

  { --i; m_isLeap = TRUE; temp = getLeapDays(m_lYear); }

  { temp = getMonthDays(m_lYear, i); }

if(m_isLeap==TRUE && i==(leap+1)) m_isLeap = FALSE;

if(offset==0 && leap>0 && i==leap+1)

 m_cWordDay= getWordDay(m_lDay);

 m_cMonthSB=((m_isLeap?getLeapDays(m_lYear):getMonthDays(m_lYear,m_lMonth))>29)?_T("大"):_T("小");

 m_cAnimal=m_Animals[(m_lYear-4)%12];

 m_cYear=getGZ(m_lYear-1900+36);

 m_cMonth= getGZ((m_lYear-1900)*12+m_lMonth+1+12);

 LONGLONG dayCyclical = getUTC(y,m,d)/864000000000+25567+10;

 m_cDay= getGZ(dayCyclical); 

int nMSterm=getSTerm(y,(m-1)*2);

if(d==getSTerm(y,(m-1)*2))

  m_solarTerms=m_solarTerm[(m-1)*2];

else if(d==getSTerm(y,(m-1)*2+1))

  m_solarTerms=m_solarTerm[(m-1)*2+1];

for(int i=0;i<sizeof(m_sFtv)/sizeof(m_sFtv[0]);i++)

  parseFtv(m_sFtv[i],nFtvM,nFtvD,strDesc,bStrong);

if(!m_solarFestival.IsEmpty())

    m_solarFestival+=_T(" ");

   m_solarFestival+=strDesc;

int nWeekNo=0,nWeekDay=0; 

for(int i=0;i<sizeof(m_wFtv)/sizeof(m_wFtv[0]);i++)

  parseFtv(m_wFtv[i],nFtvM,nFtvD,strDesc,bStrong);

  nWeekNo=nFtvD/10;nWeekDay=nFtvD%10; 

if((m==nFtvM) && (m_tmMeas.GetDayOfWeek()-1)==nWeekDay )   

if((nWeekNo<6 && (getWeekOfMonth(y,m,d)==nWeekNo)) ||

    (nWeekNo>=6 && ((getWeeksOfMonth(y,m)-getWeekOfMonth(y,m,d)+6)==nWeekNo)))

if(!m_solarFestival.IsEmpty())

     m_solarFestival+=_T(" ");

    m_solarFestival+=strDesc;

    m_bStrong=(m_bStrong?TRUE:bStrong); 

COleDateTime tmFirst(y,m,13,1,0,0);  

if(tmFirst.GetDayOfWeek()==6)

if(!m_solarFestival.IsEmpty())

   m_solarFestival+=_T(" ");

  m_solarFestival+=_T(" 黑色星期五");;

for(int i=0;i<sizeof(m_lFtv)/sizeof(m_lFtv[0]);i++)

  parseFtv(m_lFtv[i],nFtvM,nFtvD,strDesc,bStrong);

if((m_lMonth==nFtvM && m_lDay==nFtvD) ||

   (m_lMonth==nFtvM && nFtvD==0 &&  (m_isLeap?getLeapDays(m_lYear):getMonthDays(m_lYear,m_lMonth))==m_lDay)) 

   m_bStrong=(m_bStrong?TRUE:bStrong);

LONGLONG CLunar::getUTC(int nYear,

void CLunar::parseFtv(CString strInfo,int& nFirst,int& nLast,CString& strDesc,BOOL& bStrong)

 CString sFirstNum,sLastNum;

 nFirst=atoi(sFirstNum.GetBuffer(2));

 nLast=atoi(sLastNum.GetBuffer(2));

 sFirstNum.ReleaseBuffer();

 sLastNum.ReleaseBuffer();

 CString sStrong=sInfo.Mid(4,1);

int CLunar::getWeekOfMonth(int y,int m,int d)

COleDateTime tm(y,m,1,1,0,0);

COleDateTime tmCurr(y,m,d,1,0,0);

int nWeekSpan=nSpanDays/7+1;

int nWeekDay=tm.GetDayOfWeek()+nSpanDays%7;

 TRACE("week=%d/n",nWeekDay);

int CLunar::getWeeksOfMonth(int y,int m)

static int cDaysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

 nMonths=cDaysInMonth[m-1];

if(y % 100 != 0 && y % 4 == 0)

return getWeekOfMonth(y,m,nMonths); 

CString  CLunar::getWordDay(int d){

CString CLunar::getYearName(int y)

  (y-1874==1)?cTmp=_T("元"):cTmp.Format(_T("%d"),y-1874);

  cYear.Format(_T("光绪%s年"),cTmp);

else if(y>1908 && y<1912)  

  (y-1908==1)?cTmp=_T("元"):cTmp.Format(_T("%d"),y-1908);

  cYear.Format(_T("宣统%s年"),cTmp);

else if(y>1911 && y<1950) 

  (y-1911==1)?cTmp=_T("元"):cTmp.Format(_T("%d"),y-1911);

  cYear.Format(_T("民国%s年"),cTmp);

  (y-1949==1)?cTmp=_T("元"):cTmp.Format(_T("%d"),y-1949);

  cYear.Format(_T("共和国%s年"),cTmp);

  cYear.Format(_T("公元%d年"),y);
Copy the code