From 2fbac28d3c1335e1283596b4f574fd55d8117fd6 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 30 Mar 2012 09:55:45 +0200 Subject: ommongodb: now writes a real timestamp into mongo --- runtime/datetime.c | 30 ++++++++++++++++++++---------- runtime/datetime.h | 1 + 2 files changed, 21 insertions(+), 10 deletions(-) (limited to 'runtime') diff --git a/runtime/datetime.c b/runtime/datetime.c index 830c67e3..10ab3c64 100644 --- a/runtime/datetime.c +++ b/runtime/datetime.c @@ -851,16 +851,9 @@ int formatTimestamp3164(struct syslogTime *ts, char* pBuf, int bBuggyDay) /** - * format a timestamp as a UNIX timestamp; subsecond resolution is - * discarded. - * Note that this code can use some refactoring. I decided to use it - * because mktime() requires an upfront TZ update as it works on local - * time. In any case, it is worth reconsidering to move to mktime() or - * some other method. - * Important: pBuf must point to a buffer of at least 11 bytes. - * rgerhards, 2012-03-29 + * convert syslog timestamp to time_t */ -int formatTimestampUnix(struct syslogTime *ts, char *pBuf) +time_t syslogTime2time_t(struct syslogTime *ts) { long MonthInDays, NumberOfYears, NumberOfDays, i; int utcOffset; @@ -956,7 +949,23 @@ int formatTimestampUnix(struct syslogTime *ts, char *pBuf) if(ts->OffsetMode == '+') utcOffset *= -1; /* if timestamp is ahead, we need to "go back" to UTC */ TimeInUnixFormat += utcOffset; - snprintf(pBuf, 11, "%u", (unsigned) TimeInUnixFormat); + return TimeInUnixFormat; +} + + +/** + * format a timestamp as a UNIX timestamp; subsecond resolution is + * discarded. + * Note that this code can use some refactoring. I decided to use it + * because mktime() requires an upfront TZ update as it works on local + * time. In any case, it is worth reconsidering to move to mktime() or + * some other method. + * Important: pBuf must point to a buffer of at least 11 bytes. + * rgerhards, 2012-03-29 + */ +int formatTimestampUnix(struct syslogTime *ts, char *pBuf) +{ + snprintf(pBuf, 11, "%u", (unsigned) syslogTime2time_t(ts)); return 11; } @@ -986,6 +995,7 @@ CODESTARTobjQueryInterface(datetime) pIf->formatTimestamp3339 = formatTimestamp3339; pIf->formatTimestamp3164 = formatTimestamp3164; pIf->formatTimestampUnix = formatTimestampUnix; + pIf->syslogTime2time_t = syslogTime2time_t; finalize_it: ENDobjQueryInterface(datetime) diff --git a/runtime/datetime.h b/runtime/datetime.h index bb5e5292..9f3611e1 100644 --- a/runtime/datetime.h +++ b/runtime/datetime.h @@ -46,6 +46,7 @@ BEGINinterface(datetime) /* name must also be changed in ENDinterface macro! */ void (*timeval2syslogTime)(struct timeval *tp, struct syslogTime *t); /* v7, 2012-03-29 */ int (*formatTimestampUnix)(struct syslogTime *ts, char*pBuf); + time_t (*syslogTime2time_t)(struct syslogTime *ts); ENDinterface(datetime) #define datetimeCURR_IF_VERSION 7 /* increment whenever you change the interface structure! */ /* interface changes: -- cgit