[an error occurred while processing this directive]
[an error occurred while processing this directive]
|
/******************************************************************************
* DESCRIPTION:
* convert Date and Time to long seconds
*****************************************************************************/
u32_t DateTime_ToLong(Time_t *ttime)
{
u8_t month;
u16_t year;
u32_t c,ya;
u32_t res;
month = ttime->month;
year = ttime->year;if(month > 2)
month -= 3;
else {
month += 9;
year--;
}
c = year / 100;
ya = year - 100 * c;
res = (146097 * c)/4 + (1461 * ya)/4 + (153 * month + 2)/5 + ttime->day;
return (res - 720000) * 86400l + (ttime->hour * 60l + ttime->minute) * 60l + ttime->sec;
}
/******************************************************************************
* DESCRIPTION:
* convert long seconds to Date and Time
*****************************************************************************/
void LongTo_DateTime(u32_t j,Time_t *ttime)
{
u32_t d,m,y;
u32_t date,t;
date = j/86400l;
t = j - (date * 86400l);
date += 720000;
y = (4 * date - 1) / 146097;
d = (4 * date - 1 - 146097 * y) / 4l;
date = (4 * d + 3) / 1461;
d = (4 * d + 7 - 1461 * date) / 4l;
m = (5 * d - 3) / 153;
d = (5 * d + 2 - 153 * m) / 5l;
y = 100 * y + date;
if (m < 10)
m += 3;
else {
m -= 9;
y++;
}ttime->month = m;
ttime->year = y;
ttime->day = d;
ttime->sec = t % 60l; t /= 60l;
ttime->hour = t / 60l;
ttime->minute = t % 60l;
};
E-mail: info@telesys.ru