diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-09 17:43:24 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-16 23:48:46 +0000 |
commit | 6a807615c7ee6364362a9a14d725165e948c5585 (patch) | |
tree | 3981eab5e1a943e68f9a0bd7b738d506dc1ca01d /fastos/src | |
parent | 225be01d5405c179584eb7fc08309c8f4a08fb22 (diff) |
Drop all of TimeStamp too.
Diffstat (limited to 'fastos/src')
-rw-r--r-- | fastos/src/vespa/fastos/timestamp.cpp | 34 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/timestamp.h | 42 |
2 files changed, 2 insertions, 74 deletions
diff --git a/fastos/src/vespa/fastos/timestamp.cpp b/fastos/src/vespa/fastos/timestamp.cpp index d8e89dcf99f..5268453901d 100644 --- a/fastos/src/vespa/fastos/timestamp.cpp +++ b/fastos/src/vespa/fastos/timestamp.cpp @@ -1,43 +1,11 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "timestamp.h" -#include <cmath> -#include <sys/time.h> +#include <chrono> using std::chrono::system_clock; -using std::chrono::steady_clock; -using std::chrono::nanoseconds; -using std::chrono::duration_cast; namespace fastos { -const TimeStamp::TimeT TimeStamp::MILLI; -const TimeStamp::TimeT TimeStamp::MICRO; -const TimeStamp::TimeT TimeStamp::NANO; -const TimeStamp::TimeT TimeStamp::SEC; - -using seconds = std::chrono::duration<double>; - -std::string -TimeStamp::asString(double timeInSeconds) -{ - double intpart; - double fractpart = std::modf(timeInSeconds, &intpart); - time_t timeStamp = (time_t)intpart; - struct tm timeStruct; - gmtime_r(&timeStamp, &timeStruct); - char timeString[128]; - strftime(timeString, sizeof(timeString), "%F %T", &timeStruct); - char retval[160]; - uint32_t milliSeconds = std::min((uint32_t)(fractpart * 1000.0), 999u); - snprintf(retval, sizeof(retval), "%s.%03u UTC", timeString, milliSeconds); - return std::string(retval); -} - -std::string -TimeStamp::asString(std::chrono::system_clock::time_point ns) { - return asString(seconds(ns.time_since_epoch()).count()); -} - time_t time() { return system_clock::to_time_t(system_clock::now()); diff --git a/fastos/src/vespa/fastos/timestamp.h b/fastos/src/vespa/fastos/timestamp.h index 37587f4dc3e..e050fe1bcbb 100644 --- a/fastos/src/vespa/fastos/timestamp.h +++ b/fastos/src/vespa/fastos/timestamp.h @@ -1,50 +1,10 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <cstdint> -#include <limits> -#include <string> -#include <chrono> +#include <ctime> namespace fastos { -class TimeStamp -{ -public: - typedef int64_t TimeT; - static const TimeT MILLI = 1000LL; - static const TimeT MICRO = 1000*MILLI; - static const TimeT NANO = 1000*MICRO; - static const TimeT SEC = NANO; - TimeStamp() : _time(0) { } - TimeStamp(const timeval & tv) : _time(tv.tv_sec*SEC + tv.tv_usec*MILLI) { } - TimeStamp(int v) : _time(v) { } - TimeStamp(unsigned int v) : _time(v) { } - TimeStamp(long v) : _time(v) { } - TimeStamp(unsigned long v) : _time(v) { } - TimeStamp(long long v) : _time(v) { } - TimeStamp(unsigned long long v) : _time(v) { } - TimeT val() const { return _time; } - operator TimeT () const { return val(); } - TimeStamp & operator += (TimeStamp b) { _time += b._time; return *this; } - TimeStamp & operator -= (TimeStamp b) { _time -= b._time; return *this; } - TimeT time() const { return val()/NANO; } - TimeT ms() const { return val()/1000000; } - TimeT us() const { return val()/1000; } - TimeT ns() const { return val(); } - double sec() const { return val()/1000000000.0; } - std::string toString() const { return asString(sec()); } - static std::string asString(double timeInSeconds); - static std::string asString(std::chrono::system_clock::time_point time); -private: - TimeT _time; -}; - -inline TimeStamp operator +(TimeStamp a, TimeStamp b) { return TimeStamp(a.val() + b.val()); } -inline TimeStamp operator -(TimeStamp a, TimeStamp b) { return TimeStamp(a.val() - b.val()); } -inline TimeStamp operator *(long a, TimeStamp b) { return TimeStamp(a * b.val()); } -inline TimeStamp operator *(double a, TimeStamp b) { return TimeStamp(static_cast<int64_t>(a * b.val())); } - time_t time(); } |