Skip to content

Commit

Permalink
bugfix: unixtimestamp was incorrectly computed
Browse files Browse the repository at this point in the history
The problem happened in leap year from March til then end
of year and healed itself at the begining of the next year.
During the problem period, the timestamp was 24 hours too
low.

This is primarily a simple fix that can also be applied to
older rsyslog versions. However, we will see if we can
refactor the code to make use of mktime(). Originally, that
was not done for some issues seen, which may no longer
apply.

fixes rsyslog#830
  • Loading branch information
rgerhards committed Mar 3, 2016
1 parent 86076cb commit 5e9b959
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion runtime/datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,11 @@ time_t syslogTime2time_t(struct syslogTime *ts)
MonthInDays = 0; /* any value fits ;) */
break;
}
/* adjust for leap years */
if((ts->year % 100 != 0 && ts->year % 4 == 0) || (ts->year == 2000)) {
if(ts->month > 2)
MonthInDays++;
}


/* 1) Counting how many Years have passed since 1970
Expand All @@ -1064,7 +1069,7 @@ time_t syslogTime2time_t(struct syslogTime *ts)

NumberOfYears = ts->year - yearInSec_startYear - 1;
NumberOfDays = MonthInDays + ts->day - 1;
TimeInUnixFormat = yearInSecs[NumberOfYears] + NumberOfDays * 86400;
TimeInUnixFormat = (yearInSecs[NumberOfYears] + 1) + NumberOfDays * 86400;

/*Add Hours, minutes and seconds */
TimeInUnixFormat += ts->hour*60*60;
Expand Down

0 comments on commit 5e9b959

Please sign in to comment.