0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00

Time: added to_double, delta_float, and delta_str methods

Signed-off-by: James Yonan <james@openvpn.net>
This commit is contained in:
James Yonan 2017-10-20 15:27:01 -06:00 committed by Antonio Quartulli
parent 569b1da08e
commit 49e933d275

View File

@ -44,6 +44,7 @@
#include <openvpn/common/platform.hpp>
#include <openvpn/common/exception.hpp>
#include <openvpn/common/olong.hpp>
#include <openvpn/common/to_string.hpp>
#ifdef OPENVPN_PLATFORM_WIN
#include <time.h> // for ::time() on Windows
@ -167,6 +168,11 @@ namespace openvpn {
return duration_ - (duration_ * T(3) / T(128));
}
double to_double() const
{
return double(duration_) / double(prec);
}
T raw() const { return duration_; }
# define OPENVPN_DURATION_REL(OP) bool operator OP(const Duration& d) const { return duration_ OP d.duration_; }
@ -253,6 +259,23 @@ namespace openvpn {
return delta_prec(t) / long(prec);
}
double delta_float(const TimeType& t) const
{
return (double(time_) - double(t.time_)) / double(prec);
}
std::string delta_str(const TimeType& t) const
{
if (!defined())
return "UNDEF-TIME";
const double df = delta_float(t);
std::string ret;
if (df >= 0.0)
ret += '+';
ret += std::to_string(df);
return ret;
}
# define OPENVPN_TIME_REL(OP) bool operator OP(const TimeType& t) const { return time_ OP t.time_; }
OPENVPN_TIME_REL(==)
OPENVPN_TIME_REL(!=)