From 7cb0bec405173396b7fe826471c9ae5ca7a5cd2a Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Thu, 18 Jun 2015 17:00:47 +0300 Subject: [PATCH] [alohalytics] Separated reusable AlohalyticsBaseEvent::TimestampToString() method. --- 3party/Alohalytics/src/event_base.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/3party/Alohalytics/src/event_base.h b/3party/Alohalytics/src/event_base.h index 4785b13022..d87d16039e 100644 --- a/3party/Alohalytics/src/event_base.h +++ b/3party/Alohalytics/src/event_base.h @@ -43,23 +43,25 @@ struct AlohalyticsBaseEvent { uint64_t timestamp; - virtual std::string ToString() const { - const time_t timet = static_cast(timestamp / 1000); + static std::string TimestampToString(uint64_t ts) { + const time_t timet = static_cast(ts / 1000); char buf[100]; - if (::strftime(buf, 100, "%e-%b-%Y %H:%M:%S", ::gmtime(&timet))) { + if (::strftime(buf, sizeof(buf), "%e-%b-%Y %H:%M:%S", ::gmtime(&timet))) { return buf; } else { return "INVALID_TIME"; } } + virtual std::string ToString() const { return TimestampToString(timestamp); } + static uint64_t CurrentTimestamp() { return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) .count(); } -// To avoid unnecessary calls on a server side #ifndef ALOHALYTICS_SERVER + // We need automatic timestamping on a client-side only. AlohalyticsBaseEvent() : timestamp(CurrentTimestamp()) {} #endif