diff options
Diffstat (limited to 'cpp/src/qpid/sys')
| -rw-r--r-- | cpp/src/qpid/sys/Time.h | 3 | ||||
| -rw-r--r-- | cpp/src/qpid/sys/posix/Time.cpp | 35 | ||||
| -rw-r--r-- | cpp/src/qpid/sys/windows/Time.cpp | 13 | ||||
| -rw-r--r-- | cpp/src/qpid/sys/windows/Time.h | 2 |
4 files changed, 36 insertions, 17 deletions
diff --git a/cpp/src/qpid/sys/Time.h b/cpp/src/qpid/sys/Time.h index b7173406ca..ca229c2f27 100644 --- a/cpp/src/qpid/sys/Time.h +++ b/cpp/src/qpid/sys/Time.h @@ -165,6 +165,9 @@ QPID_COMMON_EXTERN void sleep(int secs); /** Portable sleep for a number of microseconds */ QPID_COMMON_EXTERN void usleep(uint64_t usecs); +/** Output formatted date/time for now*/ +void outputFormattedNow(std::ostream&); + }} #endif /*!_sys_Time_h*/ diff --git a/cpp/src/qpid/sys/posix/Time.cpp b/cpp/src/qpid/sys/posix/Time.cpp index d8d0a58d2e..5eb65357f6 100644 --- a/cpp/src/qpid/sys/posix/Time.cpp +++ b/cpp/src/qpid/sys/posix/Time.cpp @@ -79,25 +79,28 @@ std::ostream& operator<<(std::ostream& o, const Duration& d) { return o << int64_t(d) << "ns"; } -std::ostream& operator<<(std::ostream& o, const AbsTime& t) { - static const char * month_abbrevs[] = { - "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" - }; - struct tm * timeinfo; - time_t rawtime(t.timepoint/TIME_SEC); - timeinfo = localtime (&rawtime); +namespace { +inline std::ostream& outputFormattedTime(std::ostream& o, const ::time_t* time) { + ::tm timeinfo; char time_string[100]; - sprintf ( time_string, - "%d-%s-%02d %02d:%02d:%02d", - 1900 + timeinfo->tm_year, - month_abbrevs[timeinfo->tm_mon], - timeinfo->tm_mday, - timeinfo->tm_hour, - timeinfo->tm_min, - timeinfo->tm_sec - ); + ::strftime(time_string, 100, + "%Y-%m-%d %H:%M:%S", + localtime_r(time, &timeinfo)); return o << time_string; } +} + +std::ostream& operator<<(std::ostream& o, const AbsTime& t) { + ::time_t rawtime(t.timepoint/TIME_SEC); + return outputFormattedTime(&rawtime); +} + +void outputFormattedNow(std::ostream& o) { + ::time_t rawtime; + ::time(&rawtime); + outputFormattedTime(o, &rawtime); + o << " "; +} void sleep(int secs) { ::sleep(secs); diff --git a/cpp/src/qpid/sys/windows/Time.cpp b/cpp/src/qpid/sys/windows/Time.cpp index 2390826831..1d7b94e8d7 100644 --- a/cpp/src/qpid/sys/windows/Time.cpp +++ b/cpp/src/qpid/sys/windows/Time.cpp @@ -72,6 +72,7 @@ std::ostream& operator<<(std::ostream& o, const AbsTime& t) { return o << time_string; } + void toPtime(ptime& pt, const AbsTime& t) { pt = t.getPrivate(); } @@ -87,4 +88,16 @@ void usleep(uint64_t usecs) { ::Sleep(msecs); } +void outputFormattedNow(std::ostream& o) { + ::time_t rawtime; + ::tm timeinfo; + char time_string[100]; + + ::time( &rawtime ); + ::localtime_s(&timeinfo, &rawtime); + ::strftime(time_string, 100, + "%Y-%m-%d %H:%M:%S", + &timeinfo); + o << time_string << " "; +} }} diff --git a/cpp/src/qpid/sys/windows/Time.h b/cpp/src/qpid/sys/windows/Time.h index 49b3c4bab3..2987b1c8b2 100644 --- a/cpp/src/qpid/sys/windows/Time.h +++ b/cpp/src/qpid/sys/windows/Time.h @@ -19,7 +19,7 @@ * */ -#include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/date_time/posix_time/posix_time_types.hpp> namespace qpid { namespace sys { |
