Browse Source

Try to parse timestamps as double, if int64 parse fails

tags/nilmdb-1.4.0
Jim Paris 11 years ago
parent
commit
d3efb829b5
1 changed files with 12 additions and 6 deletions
  1. +12
    -6
      nilmdb/server/rocket.c

+ 12
- 6
nilmdb/server/rocket.c View File

@@ -409,12 +409,15 @@ static PyObject *Rocket_append_string(Rocket *self, PyObject *args)

/* Extract timestamp */
t64.i = strtoll(buf, &endptr, 10);
if (endptr == buf)
return raise_str(linenum, buf - linestart + 1,
ERR_OTHER, "bad timestamp");
if (!isspace(*endptr))
return raise_str(linenum, buf - linestart + 1,
ERR_OTHER, "timestamp isn't an int");
if (endptr == buf || !isspace(*endptr)) {
/* Try parsing as a double instead */
t64.d = strtod(buf, &endptr);
if (endptr == buf)
goto bad_timestamp;
if (!isspace(*endptr))
goto cant_parse_value;
t64.i = round(t64.d);
}
if (t64.i <= last_timestamp)
return raise_int(linenum, buf - linestart + 1,
ERR_NON_MONOTONIC, t64.i);
@@ -497,6 +500,9 @@ static PyObject *Rocket_append_string(Rocket *self, PyObject *args)
err:
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
bad_timestamp:
return raise_str(linenum, buf - linestart + 1,
ERR_OTHER, "bad timestamp");
cant_parse_value:
return raise_str(linenum, buf - linestart + 1,
ERR_OTHER, "can't parse value");


Loading…
Cancel
Save