diff options
Diffstat (limited to 'runtime/datetime.c')
-rw-r--r-- | runtime/datetime.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/runtime/datetime.c b/runtime/datetime.c index bed33127..b795fc5d 100644 --- a/runtime/datetime.c +++ b/runtime/datetime.c @@ -83,6 +83,9 @@ static void getCurrTime(struct syslogTime *t) # else gettimeofday(&tp, NULL); # endif + + t->epoch = tp.tv_sec; + tm = localtime_r((time_t*) &(tp.tv_sec), &tmBuf); t->year = tm->tm_year + 1900; @@ -157,6 +160,35 @@ static int srSLMGParseInt32(char** ppsz) } +static void +ComputeEpoch(struct syslogTime *pTime) +{ + struct tm utc; + long offset = pTime->OffsetHour * 3600 + pTime->OffsetMinute * 60; + time_t epoch; + + utc.tm_year = pTime->year - 1900; + utc.tm_mon = pTime->month - 1; + utc.tm_mday = pTime->day; + utc.tm_hour = pTime->hour; + utc.tm_min = pTime->minute; + utc.tm_sec = pTime->second; + utc.tm_isdst = 0; + + epoch = timegm(&utc); + + switch (pTime->OffsetMode) { + case '-': + epoch += offset; + break; + case '+': + epoch -= offset; + break; + } + + pTime->epoch = epoch; +} + /** * Parse a TIMESTAMP-3339. * updates the parse pointer position. The pTime parameter @@ -280,6 +312,8 @@ ParseTIMESTAMP3339(struct syslogTime *pTime, char** ppszTS) pTime->OffsetHour = OffsetHour; pTime->OffsetMinute = OffsetMinute; + ComputeEpoch(pTime); + finalize_it: RETiRet; } @@ -501,6 +535,8 @@ ParseTIMESTAMP3164(struct syslogTime *pTime, char** ppszTS) pTime->secfracPrecision = 0; pTime->secfrac = 0; + ComputeEpoch(pTime); + finalize_it: RETiRet; } |