summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2016-04-07 10:29:11 +0200
committerJose <jose@zeroc.com>2016-04-07 10:29:11 +0200
commit058a0c6c3ee2f059be0d8c7eba940aa31463fa7f (patch)
treea52b7eb37253b8da13db2b7f617f3233b440bbfb /cpp/src/IceUtil
parentFixed issue with IE where accessing the stack from Exception.toString leads t... (diff)
downloadice-058a0c6c3ee2f059be0d8c7eba940aa31463fa7f.tar.bz2
ice-058a0c6c3ee2f059be0d8c7eba940aa31463fa7f.tar.xz
ice-058a0c6c3ee2f059be0d8c7eba940aa31463fa7f.zip
ICE-7035 - Add option to roll log files
Diffstat (limited to 'cpp/src/IceUtil')
-rw-r--r--cpp/src/IceUtil/Time.cpp38
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)
{