diff --git a/hazelcast/src/hazelcast/client/network.cpp b/hazelcast/src/hazelcast/client/network.cpp index 749bf18663..9c301c8fff 100644 --- a/hazelcast/src/hazelcast/client/network.cpp +++ b/hazelcast/src/hazelcast/client/network.cpp @@ -1015,10 +1015,10 @@ namespace hazelcast { } std::ostream &operator<<(std::ostream &os, const Connection &connection) { - os << "ClientConnection{" + os << "Connection{" << "alive=" << connection.is_alive() - << ", connectionId=" << connection.get_connection_id() - << ", remoteEndpoint="; + << ", connection id=" << connection.get_connection_id() + << ", remote endpoint="; if (connection.get_remote_address()) { os << *connection.get_remote_address(); } else { diff --git a/hazelcast/src/hazelcast/util/util.cpp b/hazelcast/src/hazelcast/util/util.cpp index 715a88c676..9364949fc7 100644 --- a/hazelcast/src/hazelcast/util/util.cpp +++ b/hazelcast/src/hazelcast/util/util.cpp @@ -435,7 +435,14 @@ namespace hazelcast { } auto systemDuration = duration_cast(t - steady_clock::now()); - auto brokenTime = system_clock::to_time_t(system_clock::now() + systemDuration); + auto msecs = duration_cast(systemDuration).count() % 1000; + auto system_time = system_clock::now() + systemDuration; + if (msecs < 0) { + msecs = 1000 + msecs; + system_time -= std::chrono::seconds(1); + } + + auto brokenTime = system_clock::to_time_t(system_time); struct tm localBrokenTime; int result = util::localtime(&brokenTime, &localBrokenTime); assert(!result); @@ -445,7 +452,7 @@ namespace hazelcast { char time_buffer[80]; std::strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%d %H:%M:%S", &localBrokenTime); oss << time_buffer; - oss << '.' << std::setfill('0') << std::setw(3) << duration_cast(systemDuration).count() % 1000; + oss << '.' << msecs; return oss.str(); } diff --git a/hazelcast/test/src/HazelcastTests2.cpp b/hazelcast/test/src/HazelcastTests2.cpp index 720bb95742..449523cbc1 100644 --- a/hazelcast/test/src/HazelcastTests2.cpp +++ b/hazelcast/test/src/HazelcastTests2.cpp @@ -191,6 +191,14 @@ namespace hazelcast { int64_t actualDuration = end - start; ASSERT_GE(actualDuration, parkDurationNanos); } + + TEST_F (ClientUtilTest, print_older_stead_clock_time) { + auto now = std::chrono::steady_clock::now(); + auto time_str = hazelcast::util::StringUtil::time_to_string(now); + ASSERT_EQ(std::string::npos, time_str.substr(time_str.find_last_of('.')).find('-')); + time_str = hazelcast::util::StringUtil::time_to_string(now - std::chrono::milliseconds(1720)); + ASSERT_EQ(std::string::npos, time_str.substr(time_str.find_last_of('.')).find('-')); + } } } }