From 2de1e79310f2cd60cff31aa76ae19a43d43b2c9e Mon Sep 17 00:00:00 2001 From: John Kerl Date: Fri, 11 Dec 2015 16:54:51 -0500 Subject: [PATCH] neaten --- c/containers/mlrval.c | 4 +--- c/containers/mlrval.h | 4 ++++ c/mapping/mapper_sec2gmt.c | 13 ++++--------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/c/containers/mlrval.c b/c/containers/mlrval.c index 5e0553828..f20cfbc74 100644 --- a/c/containers/mlrval.c +++ b/c/containers/mlrval.c @@ -34,8 +34,6 @@ // type(s). // ================================================================ -#define ISO8601_TIME_FORMAT "%Y-%m-%dT%H:%M:%SZ" - // For some Linux distros, in spite of including time.h: char *strptime(const char *s, const char *format, struct tm *tm); @@ -476,7 +474,7 @@ mv_t s_s_toupper_func(mv_t* pval1) { #define NZBUFLEN 63 // Precondition: psec is either int or float. -static mv_t time_string_from_seconds(mv_t* psec, char* format) { +mv_t time_string_from_seconds(mv_t* psec, char* format) { time_t clock = 0; if (psec->type == MT_FLOAT) { if (isinf(psec->u.fltv) || isnan(psec->u.fltv)) { diff --git a/c/containers/mlrval.h b/c/containers/mlrval.h index d916fe140..502528173 100644 --- a/c/containers/mlrval.h +++ b/c/containers/mlrval.h @@ -27,6 +27,8 @@ #define MV_SB_ALLOC_LENGTH 32 +#define ISO8601_TIME_FORMAT "%Y-%m-%dT%H:%M:%SZ" + typedef struct _mv_t { union { int boolv; @@ -270,6 +272,8 @@ mv_t f_s_hms2fsec_func(mv_t* pval1); mv_t i_s_dhms2sec_func(mv_t* pval1); mv_t f_s_dhms2fsec_func(mv_t* pval1); +mv_t time_string_from_seconds(mv_t* psec, char* format); + mv_t i_s_strlen_func(mv_t* pval1); // ---------------------------------------------------------------- diff --git a/c/mapping/mapper_sec2gmt.c b/c/mapping/mapper_sec2gmt.c index b3f68c48f..020d89c03 100644 --- a/c/mapping/mapper_sec2gmt.c +++ b/c/mapping/mapper_sec2gmt.c @@ -1,5 +1,6 @@ #include "lib/mlrutil.h" #include "containers/lrec.h" +#include "containers/mlrval.h" #include "containers/slls.h" #include "containers/mixutil.h" #include "mapping/mappers.h" @@ -82,16 +83,10 @@ static sllv_t* mapper_sec2gmt_process(lrec_t* pinrec, context_t* pctx, void* pvs if (*sval == 0) { lrec_put(pinrec, name, "", NO_FREE); } else { - double dval = mlr_double_from_string_or_die(sval); + mv_t mval = mv_scan_number_or_die(sval); + mv_t stamp = time_string_from_seconds(&mval, ISO8601_TIME_FORMAT); - // xxx make mlrutil func - time_t clock = (time_t) dval; - struct tm tm; - struct tm *ptm = gmtime_r(&clock, &tm); - char* stamp = mlr_malloc_or_die(32); - (void)strftime(stamp, 32, "%Y-%m-%dT%H:%M:%SZ", ptm); - - lrec_put(pinrec, name, stamp, FREE_ENTRY_VALUE); + lrec_put(pinrec, name, stamp.u.strv, FREE_ENTRY_VALUE); } } return sllv_single(pinrec);