You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2018/12/26 02:41:58 UTC

[GitHub] ShannonDing closed pull request #39: [ISSUE #38] Using std::chrono to get current time stamp

ShannonDing closed pull request #39: [ISSUE #38] Using std::chrono to get current time stamp
URL: https://github.com/apache/rocketmq-client-cpp/pull/39
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/common/UtilAll.cpp b/src/common/UtilAll.cpp
index 85d2a362..4932c1d8 100644
--- a/src/common/UtilAll.cpp
+++ b/src/common/UtilAll.cpp
@@ -16,6 +16,8 @@
  */
 #include "UtilAll.h"
 
+#include <chrono>
+
 namespace rocketmq {
 //<!************************************************************************
 std::string UtilAll::s_localHostName;
@@ -280,15 +282,17 @@ string UtilAll::getProcessName() {
 }
 
 uint64_t UtilAll::currentTimeMillis() {
-  boost::posix_time::ptime current_date_microseconds =
-      boost::posix_time::microsec_clock::local_time();
-  return current_date_microseconds.time_of_day().total_milliseconds();
+  auto since_epoch =
+      std::chrono::duration_cast<std::chrono::milliseconds>(
+          std::chrono::system_clock::now().time_since_epoch());
+  return static_cast<uint64_t>(since_epoch.count());
 }
 
 uint64_t UtilAll::currentTimeSeconds() {
-  boost::posix_time::ptime current_date_microseconds =
-      boost::posix_time::microsec_clock::local_time();
-  return current_date_microseconds.time_of_day().total_seconds();
+  auto since_epoch =
+      std::chrono::duration_cast<std::chrono::seconds>(
+          std::chrono::system_clock::now().time_since_epoch());
+  return static_cast<uint64_t>(since_epoch.count());
 }
 
 bool UtilAll::deflate(std::string &input, std::string &out, int level) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services