summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/qpid/sys/posix/Time.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-03-11 22:13:10 +0000
committerAlan Conway <aconway@apache.org>2008-03-11 22:13:10 +0000
commitc2d757b8db2dca0f2f288453a26b0cb78d430801 (patch)
tree995779a911ef0bc98c6cafd809b4deb197c3d2dd /qpid/cpp/src/qpid/sys/posix/Time.cpp
parenteea2a4ffb9682247360416437755059bce77afc3 (diff)
downloadqpid-python-c2d757b8db2dca0f2f288453a26b0cb78d430801.tar.gz
rubygen/0-10/specification.rb:
- Simplified enum mapping/encoding. - struct encoding - ostream << operators src/qpid/Serializer.h - free funciton serialization - separate Encoder/Decoder for const correctness - split() to allow separate encode/decode for complex cases. src/qpid/amqp_0_10/Assembly.cpp, Assembly.h: AMQP 0-10 final Assembly src/qpid/amqp_0_10/Codec.h - Replaced enable_if with overloads, simpler & more flexible. src/qpid/amqp_0_10/Frame.cpp, .h: AMQP 0-10 final frame. src/qpid/amqp_0_10/Holder.h: - provide const and non-const apply src/qpid/amqp_0_10/Segment.cpp, .h: AMQP 0-10 final Segment. src/qpid/amqp_0_10/apply.h - ConstApplyFunctor for const apply. src/qpid/amqp_0_10/built_in_types.h - SerializableString encoding src/qpid/amqp_0_10/complex_types.cpp, .h - const application - Action base class for command/control. src/qpid/framing/AMQBody.h - removed 0-10 final changes, moving integration point down the stack. src/qpid/sys/Shlib.h - removed unused and uncompilable (on some compilers) function. src/qpid/sys/Time.h, .cpp - ostream << for AbsTime and Duration. src/tests/Assembly.cpp, Segment.cpp, apply.cpp, serialize.cpp: testing new code. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@636126 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src/qpid/sys/posix/Time.cpp')
-rw-r--r--qpid/cpp/src/qpid/sys/posix/Time.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/qpid/cpp/src/qpid/sys/posix/Time.cpp b/qpid/cpp/src/qpid/sys/posix/Time.cpp
index ac63a3d038..b2b7a81130 100644
--- a/qpid/cpp/src/qpid/sys/posix/Time.cpp
+++ b/qpid/cpp/src/qpid/sys/posix/Time.cpp
@@ -22,7 +22,7 @@
#include "PrivatePosix.h"
#include "qpid/sys/Time.h"
-
+#include <ostream>
#include <time.h>
#include <sys/time.h>
@@ -40,7 +40,7 @@ AbsTime AbsTime::now() {
struct timespec& toTimespec(struct timespec& ts, const Duration& t) {
ts.tv_sec = t / TIME_SEC;
ts.tv_nsec = t % TIME_SEC;
- return ts;
+ return ts;
}
struct timeval& toTimeval(struct timeval& tv, const Duration& t) {
@@ -53,5 +53,29 @@ Duration toTime(const struct timespec& ts) {
return ts.tv_sec*TIME_SEC + ts.tv_nsec;
}
+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.timeValue()/TIME_SEC);
+ timeinfo = localtime (&rawtime);
+ 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
+ );
+ return o << time_string;
+}
+
}}