Skip to content

Commit

Permalink
Add support use system TimeZone
Browse files Browse the repository at this point in the history
As explain in the issue :
fluent#593
Defined parameter : Time_Offset to "System"
This will use the system local timestamp.

Very usefull when the timezone depending on Summer/Winter
  • Loading branch information
tguenneguez committed Feb 10, 2022
1 parent dea3fa9 commit 66c2646
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/flb_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <sys/stat.h>
#include <limits.h>
#include <string.h>
#include <time.h>

static inline uint32_t digits10(uint64_t v) {
if (v < 10) return 1;
Expand Down Expand Up @@ -934,6 +935,8 @@ int flb_parser_tzone_offset(const char *str, int len, int *tmdiff)
long min;
const char *end;
const char *p = str;
time_t t = time(NULL);
struct tm lt = {0};

/* Check timezones */
if (*p == 'Z') {
Expand All @@ -942,6 +945,15 @@ int flb_parser_tzone_offset(const char *str, int len, int *tmdiff)
return 0;
}

/* Check timezones */
if (*p == 'System') {
/* This is UTC, no changes required */

localtime_r(&t, &lt);
*tmdiff = lt.tm_gmtoff;
return 0;
}

/* Unexpected timezone string */
if (*p != '+' && *p != '-') {
*tmdiff = 0;
Expand Down

0 comments on commit 66c2646

Please sign in to comment.