diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2013-11-30 13:45:41 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2013-11-30 13:45:41 -0800 |
commit | 95a207ac94980b02ef3ea5d58e697089955ff9b5 (patch) | |
tree | 6cae416db70ad7e9467a65227506786a00994085 /runtime/datetime.c | |
parent | 9859818eccb27a330537258d9149c7c5f32292f6 (diff) | |
download | rsyslog-95a207ac94980b02ef3ea5d58e697089955ff9b5.tar.gz rsyslog-95a207ac94980b02ef3ea5d58e697089955ff9b5.tar.bz2 rsyslog-95a207ac94980b02ef3ea5d58e697089955ff9b5.zip |
New feature: date-strftime().HEADv3-stable-kaz
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; } |