Bueno, más bien me preguntaba cómo sumará horas esa función, pero ya lo he mirado, suma segundos:
Código SQL
[-]
ISC_QUAD * addhour (ISC_QUAD *date, int *hours)
{
if (!date || !hours)
return NULL;
else
return addseconds(date, 60 * 60 * *hours);
}
static ISC_QUAD * addseconds (ISC_QUAD *date, int seconds)
{
struct tm t;
isc_decode_date(date,&t);
t.tm_sec += seconds;
if (t.tm_sec >= 60) {
t.tm_min += (t.tm_sec / 60);
t.tm_sec ٪= 60;
t.tm_hour += (t.tm_min / 60);
t.tm_min ٪= 60;
t.tm_mday += (t.tm_hour / 24);
t.tm_hour ٪= 24;
while (t.tm_mday > daysoftsmonth(&t)) {
t.tm_mday -= daysoftsmonth(&t);
t.tm_mon++;
if (t.tm_mon > 11) {
t.tm_mon=0;
t.tm_year++;
}
}
}
else if (t.tm_sec < 0) {
t.tm_min += ((t.tm_sec - 59) / 60);
if (t.tm_sec ٪ 60 == 0) {
t.tm_sec = (t.tm_sec ٪ 60);
}
else {
t.tm_sec = (t.tm_sec ٪ 60) + 60;
}
if (t.tm_min < 0) {
t.tm_hour += ((t.tm_min - 59) / 60);
if (t.tm_min ٪ 60 == 0) {
t.tm_min = (t.tm_min ٪ 60);
}
else {
t.tm_min = (t.tm_min ٪ 60) + 60;
}
if (t.tm_hour < 0) {
t.tm_mday += ((t.tm_hour - 23) / 24);
if (t.tm_hour ٪ 24 == 0) {
t.tm_hour = (t.tm_hour ٪ 24);
}
else {
t.tm_hour = (t.tm_hour ٪ 24) + 24;
}
while (t.tm_mday < 1) {
t.tm_mon--;
if (t.tm_mon < 0) {
t.tm_mon = 11;
t.tm_year--;
}
t.tm_mday += daysoftsmonth(&t);
}
}
}
}
return (ISC_QUAD *) gen_ib_date(&t);
}
static int daysoftsmonth(struct tm *t)
{
int month = t->tm_mon + 1;
int year = t->tm_year + 1900;
return intern_daysofmonth(month, year);
}