|
发表于 2009-1-4 14:33:38
|
显示全部楼层
将函数ClndrComputeLunarInfo改成如下这样:
void ClndrComputeLunarInfo(clndr_lnuar_date_info_struct *DI)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
U8 LeapDay;
S16 StartMonth;
S16 YearIndex;
S16 AccumulateDay;
S16 KanChiDay;
S16 DateDiff;
S16 IntercalaryMonth;
S16 LunarDays;
S16 SolarDate1, SolarDate2, SolarDate3;
S16 MonthIndex;
S8 dummyString[CLNDR_TITLE_LEN];
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* to check if the month out of boundary */
StartMonth = DI->SolarMonth - 1;
/* to calculate the number of days in Feb. this year */
if (StartMonth > 1)
{
LeapDay = (U8) IsLeapYear(DI->SolarYear);
}
else
{
LeapDay = 0;
}
YearIndex = DI->SolarYear - CLNDR_TABLE_START_YEAR;
/* to calculate weekday */
AccumulateDay = (gClndrAccuDays[StartMonth] + LeapDay + DI->SolarDay);
/* to calculate the Kan and Chin of today */
KanChiDay = AccumulateDay + gClndrLunarInfo[YearIndex].BaseKanChi;
/* to check if today is earlier than the Chinese New Year day of this year */
LeapDay = (U8) IsLeapYear(DI->LunarYear);
if (g_clndr_cntx->CalTime.nMonth == 1 || (g_clndr_cntx->CalTime.nMonth == 2 && g_clndr_cntx->CalTime.nDay < 29))
{
LeapDay = 0;
}
if (AccumulateDay <= gClndrLunarInfo[YearIndex].BaseDays)
{
YearIndex--;
DI->LunarYear = DI->SolarYear - 1;
StartMonth += 12;
LeapDay = (U8) IsLeapYear(DI->LunarYear);
AccumulateDay = (gClndrAccuDays[StartMonth] + LeapDay + DI->SolarDay);
}
else
{
DI->LunarYear = DI->SolarYear;
}
/* to calculate the lunar month and day */
IntercalaryMonth = gClndrLunarInfo[YearIndex].Intercalary;
DateDiff = gClndrLunarInfo[YearIndex].BaseDays;
for (MonthIndex = 0; MonthIndex < 13; MonthIndex++)
{
LunarDays = DateDiff + 29;
if (gClndrLunarInfo[YearIndex].MonthDays & (0x01 << MonthIndex))
{
LunarDays++;
}
if (AccumulateDay <= LunarDays)
{
break;
}
DateDiff = LunarDays;
}
DI->LunarMonth = (MonthIndex + 1);
DI->LunarDay = AccumulateDay - DateDiff;
/* to adjust Lunar month if there is a intercalary month in this year */
if (IntercalaryMonth != 0 && DI->LunarMonth > IntercalaryMonth)
{
DI->LunarMonth--;
}
if (DI->LunarMonth > 12)
{
DI->LunarMonth -= 12;
}
/* the unfortunate direction, age, and animal today */
DI->Direction = KanChiDay % 4;
DI->Age = (82 - (KanChiDay % 60) + (DI->LunarYear - CLNDR_BASE)) % 60;
if (DI->Age <= 10)
{
DI->Age += 60;
}
DI->Animal = (KanChiDay + 6) % 12;
/* to calculate the Kan and Chin of this year */
if (DI->LunarYear == DI->SolarYear)
{
DI->KanYear = (DI->SolarYear - 1900 + 36) % 10;
DI->ChiYear = (DI->SolarYear - 1900 + 36) % 12;
/* to calculate the animal of this year */
DI->YearAnimal = (DI->SolarYear + 8) % 12;
}
else
{
DI->KanYear = (DI->SolarYear - 1900 + 36 - 1) % 10;
DI->ChiYear = (DI->SolarYear - 1900 + 36 - 1) % 12;
/* to calculate the animal of this year */
DI->YearAnimal = (DI->SolarYear + 8 - 1) % 12;
}
/* to calculate the lunar day of solar term in this month */
SolarDate1 = ClndrComputeSolarTerm(DI->SolarYear, DI->SolarMonth, (S16) ((DI->SolarMonth - 1) * 2));
SolarDate2 = ClndrComputeSolarTerm(DI->SolarYear, DI->SolarMonth, (S16) ((DI->SolarMonth - 1) * 2 + 1));
if (DI->SolarMonth < 12)
{
SolarDate3 = ClndrComputeSolarTerm(DI->SolarYear, (S16) (DI->SolarMonth + 1), (S16) ((DI->SolarMonth - 1) * 2 + 2));
}
else
{
SolarDate3 = ClndrComputeSolarTerm((S16) (DI->SolarYear + 1), (S16) 1, (S16) (0));
}
if (DI->SolarDay < SolarDate1)
{
DI->SolarTerm = 0;
DI->SolarDate = SolarDate1 - DI->SolarDay + DI->LunarDay;
}
else if (DI->SolarDay == SolarDate1)
{
DI->SolarTerm = 0;
DI->SolarDate = 0;
}
else if (DI->SolarDay < SolarDate2)
{
DI->SolarTerm = 1;
DI->SolarDate = SolarDate2 - DI->SolarDay + DI->LunarDay;
}
else if (DI->SolarDay == SolarDate2)
{
DI->SolarTerm = 1;
DI->SolarDate = 0;
}
else
{
DI->SolarTerm = 2;
if (DI->SolarMonth == 2)
{
if (DI->SolarMonth + 1 == 1 || (DI->SolarMonth + 1 == 2 && SolarDate3 < 29))
{
LeapDay = 0;
}
else
{
LeapDay = (U8) IsLeapYear(DI->SolarYear);
}
DI->SolarDate = gDaysInMonth[DI->SolarMonth - 1] - DI->SolarDay + SolarDate3 + DI->LunarDay + LeapDay;
}
else
{
DI->SolarDate = gDaysInMonth[DI->SolarMonth - 1] - DI->SolarDay + SolarDate3 + DI->LunarDay;
}
}
if (gClndrLunarInfo[YearIndex].MonthDays & (0x01 << MonthIndex))
{
LunarDays = 30;
}
else
{
LunarDays = 29;
}
if (DI->SolarDate > LunarDays)
{
DI->SolarDate -= LunarDays;
} |
|