diff options
author | Jose <jose@zeroc.com> | 2016-04-07 10:29:11 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2016-04-07 10:29:11 +0200 |
commit | 058a0c6c3ee2f059be0d8c7eba940aa31463fa7f (patch) | |
tree | a52b7eb37253b8da13db2b7f617f3233b440bbfb /cpp/src/IceUtil/Time.cpp | |
parent | Fixed issue with IE where accessing the stack from Exception.toString leads t... (diff) | |
download | ice-058a0c6c3ee2f059be0d8c7eba940aa31463fa7f.tar.bz2 ice-058a0c6c3ee2f059be0d8c7eba940aa31463fa7f.tar.xz ice-058a0c6c3ee2f059be0d8c7eba940aa31463fa7f.zip |
ICE-7035 - Add option to roll log files
Diffstat (limited to 'cpp/src/IceUtil/Time.cpp')
-rw-r--r-- | cpp/src/IceUtil/Time.cpp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/cpp/src/IceUtil/Time.cpp b/cpp/src/IceUtil/Time.cpp index d792757a9f1..aa6f6e944d9 100644 --- a/cpp/src/IceUtil/Time.cpp +++ b/cpp/src/IceUtil/Time.cpp @@ -247,22 +247,8 @@ IceUtil::Time::toMicroSecondsDouble() const std::string IceUtil::Time::toDateTime() const { - time_t time = static_cast<long>(_usec / 1000000); - - struct tm* t; -#ifdef _WIN32 - t = localtime(&time); -#else - struct tm tr; - localtime_r(&time, &tr); - t = &tr; -#endif - - char buf[32]; - strftime(buf, sizeof(buf), "%x %H:%M:%S", t); - std::ostringstream os; - os << buf << "."; + os << toFormatString("%x %H:%M:%S") << "."; os.fill('0'); os.width(3); os << static_cast<long>(_usec % 1000000 / 1000); @@ -294,6 +280,28 @@ IceUtil::Time::toDuration() const return os.str(); } +std::string +IceUtil::Time::toFormatString(const std::string& format) const +{ + time_t time = static_cast<long>(_usec / 1000000); + + struct tm* t; +#ifdef _WIN32 + t = localtime(&time); +#else + struct tm tr; + localtime_r(&time, &tr); + t = &tr; +#endif + + char buf[32]; + if(strftime(buf, sizeof(buf), format.c_str(), t) == 0) + { + return std::string(); + } + return std::string(buf); +} + Time::Time(Int64 usec) : _usec(usec) { |