mirror of
https://github.com/morgan9e/UxPlay
synced 2026-04-14 00:04:13 +09:00
fix timestamp_to_date, etc. for nanosecond timestamps
This commit is contained in:
@@ -300,7 +300,7 @@ raop_ntp_thread(void *arg)
|
||||
(struct sockaddr *) &raop_ntp->remote_saddr, &raop_ntp->remote_saddr_len);
|
||||
if (response_len < 0) {
|
||||
timeout_counter++;
|
||||
char time[28];
|
||||
char time[30];
|
||||
int level = (timeout_counter == 1 ? LOGGER_DEBUG : LOGGER_ERR);
|
||||
ntp_timestamp_to_time(send_time, time, sizeof(time));
|
||||
logger_log(raop_ntp->logger, level, "raop_ntp receive timeout %d (limit %d) (request sent %s)",
|
||||
|
||||
13
lib/utils.c
13
lib/utils.c
@@ -21,6 +21,7 @@
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
#define SECOND_IN_NSECS 1000000000UL
|
||||
|
||||
char *
|
||||
utils_strsep(char **stringp, const char *delim)
|
||||
@@ -218,21 +219,21 @@ char *utils_data_to_text(const char *data, int datalen) {
|
||||
}
|
||||
|
||||
void ntp_timestamp_to_time(uint64_t ntp_timestamp, char *timestamp, size_t maxsize) {
|
||||
time_t rawtime = (time_t) (ntp_timestamp / 1000000);
|
||||
time_t rawtime = (time_t) (ntp_timestamp / SECOND_IN_NSECS);
|
||||
struct tm ts = *localtime(&rawtime);
|
||||
assert(maxsize > 26);
|
||||
assert(maxsize > 29);
|
||||
#ifdef _WIN32 /*modification for compiling for Windows */
|
||||
strftime(timestamp, 20, "%Y-%m-%d %H:%M:%S", &ts);
|
||||
#else
|
||||
strftime(timestamp, 20, "%F %T", &ts);
|
||||
#endif
|
||||
snprintf(timestamp + 19, 8,".%6.6u", (unsigned int) ntp_timestamp % 1000000);
|
||||
snprintf(timestamp + 19, 11,".%9.9lu", (unsigned long) ntp_timestamp % SECOND_IN_NSECS);
|
||||
}
|
||||
|
||||
void ntp_timestamp_to_seconds(uint64_t ntp_timestamp, char *timestamp, size_t maxsize) {
|
||||
time_t rawtime = (time_t) (ntp_timestamp / 1000000);
|
||||
time_t rawtime = (time_t) (ntp_timestamp / SECOND_IN_NSECS);
|
||||
struct tm ts = *localtime(&rawtime);
|
||||
assert(maxsize > 9);
|
||||
assert(maxsize > 12);
|
||||
strftime(timestamp, 3, "%S", &ts);
|
||||
snprintf(timestamp + 2, 8,".%6.6u", (unsigned int) ntp_timestamp % 1000000);
|
||||
snprintf(timestamp + 2, 11,".%9.9lu", (unsigned long) ntp_timestamp % SECOND_IN_NSECS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user