- 论坛徽章:
- 0
|
大家帮看看这个简单的c函数,计算两个日期之间的天数,其中一个日期规定为0年0月0日,
代码如下:
long calc_daynr(uint year,uint month,uint day)
{
long delsum;
int temp;
int y= year; /* may be < 0 temporarily */
DBUG_ENTER("calc_daynr");
if (y == 0 && month == 0 && day == 0)
DBUG_RETURN(0); /* Skip errors */
/* Cast to int to be able to handle month == 0 */
delsum= (long) (365 * y + 31 *((int) month - 1) + (int) day);
if (month <= 2)
y--;
else
delsum-= (long) ((int) month * 4 + 23) / 10;
temp=(int) ((y/100+1)*3)/4;
DBUG_PRINT("exit",("year: %d month: %d day: %d -> daynr: %ld",
y+(month <= 2),month,day,delsum+y/4-temp));
DBUG_RETURN(delsum+(int) y/4-temp);
} /* calc_daynr */
此代码来自mysql源码,实在是看不懂这里面的逻辑啊?求明解,谢谢! |
|