Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions c/lib/mlrutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,24 @@ char* mlr_get_line(FILE* input_stream, char rs) {

return line;
}

time_t mlr_timegm (struct tm* tm) {
time_t ret;
char* tz;

tz = getenv("TZ");
if (tz) {
tz = strdup(tz);
}
setenv("TZ", "GMT0", 1);
tzset();
ret = mktime(tm);
if (tz) {
setenv("TZ", tz, 1);
free(tz);
} else {
unsetenv("TZ");
}
tzset();
return ret;
}
4 changes: 4 additions & 0 deletions c/lib/mlrutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define TRUE 1
#define FALSE 0
Expand Down Expand Up @@ -56,4 +57,7 @@ int mlr_string_pair_hash_func(char* str1, char* str2);
// xxx cmt mem mgt
char* mlr_get_line(FILE* input_stream, char rs);

// portable timegm replacement
time_t mlr_timegm (struct tm *tm);

#endif // MLRUTIL_H
3 changes: 2 additions & 1 deletion c/mapping/mlr_val.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdlib.h>
#include <time.h>
#include "lib/mlr_globals.h"
#include "lib/mlrutil.h"
#include "mapping/mlr_val.h"

// For some Linux distros, in spite of including time.h:
Expand Down Expand Up @@ -246,7 +247,7 @@ mv_t i_s_gmt2sec_func(mv_t* pval1) {
return MV_NULL;
} else {
strptime(pval1->u.strv, "%Y-%m-%dT%H:%M:%SZ", &tm);
time_t t = timegm(&tm);
time_t t = mlr_timegm(&tm);

mv_t rv = {.type = MT_INT, .u.intv = (long long)t};
return rv;
Expand Down