X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Futils_time.h;h=9e98040694eb8b57822653e6fc1df5296646a314;hb=306810f293c3bc1f3cbf2793a228d2113500e573;hp=2cc84b5dec4013eb00a720e0132280cafd00aa2a;hpb=d6f0273b2ebae6995d69c7701838825b96e4f424;p=collectd.git diff --git a/src/daemon/utils_time.h b/src/daemon/utils_time.h index 2cc84b5d..9e980406 100644 --- a/src/daemon/utils_time.h +++ b/src/daemon/utils_time.h @@ -29,6 +29,12 @@ #include "collectd.h" +#ifdef TESTING_H +/* cdtime_mock is the time returned by cdtime() when build with + * -DMOCK_TIME */ +extern cdtime_t cdtime_mock; +#endif + /* * "cdtime_t" is a 64bit unsigned integer. The time is stored at a 2^-30 second * resolution, i.e. the most significant 34 bit are used to store the time in @@ -72,15 +78,19 @@ (tsp)->tv_sec = CDTIME_T_TO_TIME_T (cdt); \ (tsp)->tv_nsec = (long) CDTIME_T_TO_NS ((cdt) & 0x3fffffff); \ } while (0) -#define TIMESPEC_TO_CDTIME_T(ts) NS_TO_CDTIME_T(1000000000 * (ts)->tv_sec + (ts)->tv_nsec) +#define TIMESPEC_TO_CDTIME_T(ts) NS_TO_CDTIME_T(1000000000ULL * (ts)->tv_sec + (ts)->tv_nsec) cdtime_t cdtime (void); -/* format a cdtime_t value in ISO 8601 format: - * returns the number of characters written to the string (not including the - * terminating null byte or 0 on error; the function ensures that the string - * is null terminated */ -size_t cdtime_to_iso8601 (char *s, size_t max, cdtime_t t); +#define RFC3339_SIZE 26 +#define RFC3339NANO_SIZE 36 + +/* rfc3339 formats a cdtime_t time in RFC 3339 format with second precision. */ +int rfc3339 (char *buffer, size_t buffer_size, cdtime_t t); + +/* rfc3339nano formats a cdtime_t time in RFC 3339 format with nanosecond + * precision. */ +int rfc3339nano (char *buffer, size_t buffer_size, cdtime_t t); #endif /* UTILS_TIME_H */ /* vim: set sw=2 sts=2 et : */