This commit is contained in:
John Kerl 2015-12-11 16:54:51 -05:00
parent d50ad82416
commit 2de1e79310
3 changed files with 9 additions and 12 deletions

View file

@ -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)) {

View file

@ -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);
// ----------------------------------------------------------------

View file

@ -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);