万年历算法

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

万年历算法

程序匠人发表于 2006-11-28 22:43:00 阅读全文(763) | 回复(1) | 引用通告(0) | 编辑

万年历算法

一、阳历算法

具体算法见函数Void get_solar_day_date(void),这样阳历日历的星期排法就确定了。

表1:

月份 1 2 3 4 5 6 7 8 9 10 11 12

闰年 31 29 31 30 31 30 31 31 30 31 30 31

非闰年 31 28 31 30 31 30 31 31 30 31 30 31

变量定义:

Public:

Unsigned int temp_total_day;

Unsigned char gc_solar_calendar_year;

Unsigned char gc_solar_calendar_month;

Unsigned char gc_solar_calendar_date;

Unsigned char gc_lunar_calendar_year;

Unsigned char gc_lunar_calendar_month;

Unsigned char gc_lunar_calendar_date;

Unsigned char start_day_of_week;

说明:函数get_solar_day_date(void)的输入变量:gc_solar_calendar_year和gc_solar_calendar_month

输出变量:start_day_of_week和temp_total_day

Void get_solar_day_date(void)

{

unsigned char temp01;

/*------calculate what day is the day of the current month and year. Mon~Sun?---*/

/*条件初始化二次,减少运算数据量. temp_total_day 是int型变量*/

start_day_of_week = 2; temp_total_day = 0;calculate_temp = 1;

if(gc_solar_calendar_year > 99)

{start_day_of_week = 6;calculate_temp = 100;}

for(temp01 = calculate_temp; temp01

{ if(temp014 == 0){start_day_of_week =2;temp_total_day = 366; }

else {start_day_of_week =1;temp_total_day = 365;}}

for(temp01 = 1;temp01

{ switch(temp01)

{case 1,3,5,7,8,10,12: start_day_of_week =3;temp_total_day =31;break;

case 2: if(((gc_solar_calendar_year4) == 0)&&(gc_solar_calendar_year != 200))

{start_day_of_week =1; temp_total_day =29;}

else {start_day_of_week =0;temp_total_day =28;} break;

case 4,6,9,11: start_day_of_week =2; temp_total_day =30; break;}}

start_day_of_week =7;

/*-end of calculate what day is the day(Mon~Sun?) and total day --*/

}

二、阴历算法

200年需要200 × 2 = 400个字节,构成阴历压缩数据表lunar_calendar_month_table[]如下:

const char lunar_calendar_month_table[]={ //从阴历年1900年到2100年

/*the total day of each month pointer */

/* from 1901~2100*/

/* (0110)110000001001 (0110)leap month,110000001001

lunar month total day: 1:29 0:30*/

0x00,0x04,0xad,0x08,0x5a,0x01,0xd5,0x54,0xb4,0x09,0x64,0x05,0x59,0x45, 0x95,0x0a,0xa6,0x04,0x55,0x24,0xad,0x08, 0x5a,0x62,0xda,0x04,0xb4,0x05, 0xb4,0x55,0x52,0x0d,0x94,0x0a,0x4a,0x2a,0x56,0x02,0x6d,0x71,0x6d,0x01, 0xda,0x0 2,0xd2,0x52,0xa9,0x05,0x49,0x0d,0x2a,0x45,0x2b,0x09,0x56,0x01, 0xb5,0x20,0x6d,0x01,0x59,0x69,0xd4,0x0a,0xa8,0x 05,0xa9,0x56,0xa5,0x04, 0x2b,0x09,0x9e,0x38,0xb6,0x08,0xec,0x74,0x6c,0x05,0xd4,0x0a,0xe4,0x6a, 0x52,0x05,0x95, 0x0a,0x5a,0x42,0x5b,0x04,0xb6,0x04,0xb4,0x22,0x6a,0x05, 0x52,0x75,0xc9,0x0a,0x52,0x05,0x35,0x55,0x4d,0x0a,0x5a, 0x02,0x5d,0x31, 0xb5,0x02,0x6a,0x8a,0x68,0x05,0xa9,0x0a,0x8a,0x6a,0x2a,0x05,0x2d,0x09, 0xaa,0x48,0x5a,0x01,0xb 5,0x09,0xb0,0x39,0x64,0x05,0x25,0x75,0x95,0x0a, 0x96,0x04,0x4d,0x54,0xad,0x04,0xda,0x04,0xd4,0x44,0xb4,0x05,0x 54,0x85, 0x52,0x0d,0x92,0x0a,0x56,0x6a,0x56,0x02,0x6d,0x02,0x6a,0x41,0xda,0x02, 0xb2,0xa1,0xa9,0x05,0x49,0x0d, 0x0a,0x6d,0x2a,0x09,0x56,0x01,0xad,0x50, 0x6d,0x01,0xd9,0x02,0xd1,0x3a,0xa8,0x05,0x29,0x85,0xa5,0x0c,0x2a,0x09, 0x96,0x54,0xb6,0x08,0x6c,0x09,0x64,0x45,0xd4,0x0a,0xa4,0x05,0x51,0x25, 0x95,0x0a,0x2a,0x72,0x5b,0x04,0xb6,0x0 4,0xac,0x52,0x6a,0x05,0xd2,0x0a, 0xa2,0x4a,0x4a,0x05,0x55,0x94,0x2d,0x0a,0x5a,0x02,0x75,0x61,0xb5,0x02, 0x6a,0

相关文档
最新文档