Skip to content

JSON timestamps are not valid ISO 8601 #2353

Closed
@normanr

Description

@normanr

b726e2f added a ISO 8601-like output with a Z (indicating UTC) and %z (offset from UTC). I don't think the Z should be present (also the man page doesn't include the Z in the example output).

Currently json_print does a special workaround after printing microseconds to replace the Z (where snprintf wrote it's null byte). It's probably simplest to just drop the microseconds from the time format, and call strftime a second time to format the timezone after the microseconds have been printed, eg:

char *bufp = buf;
int buf_size = sizeof(buf);
int n;

n = strftime(bufp, buf_size, "%Y-%m-%dT%H:%M:%S.", ti);
bufp += n; buf_size -= n;

n = snprintf(bufp, buf_size, "%06d", ns/1000);
bufp += n; buf_size -= n;

strftime(bufp, buf_size, "%z", ti);

I think it would also make sense to move the strftime/snprintf calls before the #ifdef WITH_CJSON because it can be shared with both parts. Also buf could be made smaller, only the first 32 bytes will ever be used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: mosquitto-clientsStatus: CompletedNothing further to be done with this issue, it can be closed by the requestor or committer.

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions