mirror of
https://github.com/eclipse/mosquitto.git
synced 2025-05-09 01:01:11 +08:00
Fix date format in mosquitto_sub output.
Closes #2353. Thanks to Norman Rasmussen.
This commit is contained in:
parent
9e5b850181
commit
20d2935d81
@ -17,6 +17,9 @@ Client library:
|
|||||||
- Initialise sockpairR/W to invalid in `mosquitto_reinitialise()` to avoid
|
- Initialise sockpairR/W to invalid in `mosquitto_reinitialise()` to avoid
|
||||||
closing invalid sockets in `mosquitto_destroy()` on error. Closes #2326.
|
closing invalid sockets in `mosquitto_destroy()` on error. Closes #2326.
|
||||||
|
|
||||||
|
Clients:
|
||||||
|
- Fix date format in mosquitto_sub output. Closes #2353.
|
||||||
|
|
||||||
|
|
||||||
2.0.12 - 2021-08-31
|
2.0.12 - 2021-08-31
|
||||||
===================
|
===================
|
||||||
|
@ -248,6 +248,16 @@ static int json_print_properties(cJSON *root, const mosquitto_property *properti
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static void format_time_8601(const struct tm *ti, int ns, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
|
||||||
|
strftime(buf, len, "%Y-%m-%dT%H:%M:%S.000000%z", ti);
|
||||||
|
c = buf[strlen("2020-05-06T21:48:00.000000")];
|
||||||
|
snprintf(&buf[strlen("2020-05-06T21:48:00.")], 9, "%06d", ns/1000);
|
||||||
|
buf[strlen("2020-05-06T21:48:00.000000")] = c;
|
||||||
|
}
|
||||||
|
|
||||||
static int json_print(const struct mosquitto_message *message, const mosquitto_property *properties, const struct tm *ti, int ns, bool escaped, bool pretty)
|
static int json_print(const struct mosquitto_message *message, const mosquitto_property *properties, const struct tm *ti, int ns, bool escaped, bool pretty)
|
||||||
{
|
{
|
||||||
char buf[100];
|
char buf[100];
|
||||||
@ -262,9 +272,7 @@ static int json_print(const struct mosquitto_message *message, const mosquitto_p
|
|||||||
return MOSQ_ERR_NOMEM;
|
return MOSQ_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.000000Z%z", ti);
|
format_time_8601(ti, ns, buf, sizeof(buf));
|
||||||
snprintf(&buf[strlen("2020-05-06T21:48:00.")], 9, "%06d", ns/1000);
|
|
||||||
buf[strlen("2020-05-06T21:48:00.000000")] = 'Z';
|
|
||||||
|
|
||||||
tmp = cJSON_CreateStringReference(buf);
|
tmp = cJSON_CreateStringReference(buf);
|
||||||
if(tmp == NULL){
|
if(tmp == NULL){
|
||||||
@ -367,9 +375,7 @@ static int json_print(const struct mosquitto_message *message, const mosquitto_p
|
|||||||
UNUSED(properties);
|
UNUSED(properties);
|
||||||
UNUSED(pretty);
|
UNUSED(pretty);
|
||||||
|
|
||||||
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.000000Z%z", ti);
|
format_time_8601(ti, ns, buf, sizeof(buf));
|
||||||
snprintf(&buf[strlen("2020-05-06T21:48:00.")], 9, "%06d", ns/1000);
|
|
||||||
buf[strlen("2020-05-06T21:48:00.000000")] = 'Z';
|
|
||||||
|
|
||||||
printf("{\"tst\":\"%s\",\"topic\":\"%s\",\"qos\":%d,\"retain\":%d,\"payloadlen\":%d,", buf, message->topic, message->qos, message->retain, message->payloadlen);
|
printf("{\"tst\":\"%s\",\"topic\":\"%s\",\"qos\":%d,\"retain\":%d,\"payloadlen\":%d,", buf, message->topic, message->qos, message->retain, message->payloadlen);
|
||||||
if(message->qos > 0){
|
if(message->qos > 0){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user