diff --git a/include/meter.h b/include/meter.h index f5e3f7c..391b505 100644 --- a/include/meter.h +++ b/include/meter.h @@ -116,6 +116,14 @@ typedef struct { */ double tvtod(struct timeval tv); +/** + * Converts double to timeval structure + * + * @param ts the double value + * @return the timeval strucure + */ +struct timeval dtotv(double ts); + /** * Get list of available meter types */ diff --git a/src/meter.c b/src/meter.c index 25de90d..4721ae0 100644 --- a/src/meter.c +++ b/src/meter.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "meter.h" #include "options.h" @@ -115,3 +116,10 @@ double tvtod(struct timeval tv) { return tv.tv_sec + tv.tv_usec / 1e6; } +struct timeval dtotv(double ts) { + struct timeval tv; + tv.tv_usec = modf(timestamp, &tv.tv_sec); + + return tv; +} +