找回密码
 注册
搜索
查看: 709|回复: 2

[讨论] 25平台农历问题

[复制链接]
发表于 2008-12-31 11:35:57 | 显示全部楼层 |阅读模式
MTK25平台2008年12月31日与2009年1月1日农历重复,怎样修正呢?
本文来自:我爱研发网(52RD.com) 详细出处:http://www.52rd.com/bbs/post.asp?action=new&boardid=15
发表于 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;
    }
点评回复

使用道具 举报

发表于 2009-1-16 14:10:19 | 显示全部楼层
在MTK新版本已经修正这个问题,楼主用的是哪个版本啊
点评回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

Archiver|手机版|小黑屋|52RD我爱研发网 ( 沪ICP备2022007804号-2 )

GMT+8, 2024-11-16 02:51 , Processed in 0.046006 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表