lemonzone2010 closed pull request #40: [ISSUE #38]fix: Incorrect 
UtilAll::currentTimeMillis and UtilAll::currentTimeSeconds
URL: https://github.com/apache/rocketmq-client-cpp/pull/40
 
 
   

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..57a4266a 100644
--- a/src/common/UtilAll.cpp
+++ b/src/common/UtilAll.cpp
@@ -20,6 +20,7 @@ namespace rocketmq {
 //<!************************************************************************
 std::string UtilAll::s_localHostName;
 std::string UtilAll::s_localIpAddress;
+boost::posix_time::ptime epoch(boost::gregorian::date(1970, 
boost::gregorian::Jan, 1));
 
 bool UtilAll::startsWith_retry(const string &topic) {
   return topic.find(RETRY_GROUP_TOPIC_PREFIX) == 0;
@@ -280,15 +281,13 @@ 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();
+  boost::posix_time::time_duration time_from_epoch = 
boost::posix_time::microsec_clock::universal_time() - epoch;
+  return time_from_epoch.total_milliseconds();
 }
 
 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();
+  boost::posix_time::time_duration time_from_epoch = 
boost::posix_time::microsec_clock::universal_time() - epoch;
+  return time_from_epoch.total_seconds();
 }
 
 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:
[email protected]


With regards,
Apache Git Services

Reply via email to