/*蔡勒公式:w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1 计算的时间在1582年之后
c:世纪(年的高两位数); 输入年月日,计算出周几
y:年(年的低两位数);
m:月(m大于等于3,小于等于14,即在蔡勒公式中,某年的1、2月要看作上一年的13、14月*/
u8 get_week(u8 *in_time_str,struct SD3078_TIMER *out_timer) //2022-03-09 03:26:49
{
short century = 0,year = 0,month = 0,day = 0,week = 0;//世纪
u8 tmp_data[20] = {0},len = 0;
len = strlen(in_time_str);
strncpy(tmp_data,in_time_str,len);
out_timer->year = asc_int(tmp_data, 4);
out_timer->month = asc_int(&tmp_data[5], 2);
out_timer->day = asc_int(&tmp_data[8], 2);
out_timer->hour = asc_int(&tmp_data[11], 2);
out_timer->minute = asc_int(&tmp_data[14], 2);
out_timer->second = asc_int(&tmp_data[17], 2);
century = asc_int(tmp_data,2); //20世纪
year = asc_int(&tmp_data[2],2); //22年
month = out_timer->month;
if(month == 1 || month == 2)
{
if(month == 1)
month = 13;
else if(month == 2)
month = 14;
if((year/10) || (year % 10))
year -= 1; //如果是2000年,那么世纪减1:19 年份为:99 合计:1999
else
{
century -= 1;
year = 99;
}
}
week = year+(year/4)+(century/4)-2*century+(26*(month+1)/10)+out_timer->day-1;
week = (week%7+7)%7;
out_timer->week = week;
printf("week:%d\n",week);
return 0;
}