|
@@ -31,13 +31,17 @@
|
|
#ifndef GOOGLE_PROTOBUF_UTIL_TIME_UTIL_H__
|
|
#ifndef GOOGLE_PROTOBUF_UTIL_TIME_UTIL_H__
|
|
#define GOOGLE_PROTOBUF_UTIL_TIME_UTIL_H__
|
|
#define GOOGLE_PROTOBUF_UTIL_TIME_UTIL_H__
|
|
|
|
|
|
-#include <sys/time.h>
|
|
|
|
-
|
|
|
|
#include <ctime>
|
|
#include <ctime>
|
|
#include <ostream>
|
|
#include <ostream>
|
|
#include <string>
|
|
#include <string>
|
|
|
|
+#ifdef _MSC_VER
|
|
|
|
+#include <winsock2.h>
|
|
|
|
+#else
|
|
|
|
+#include <sys/time.h>
|
|
|
|
+#endif
|
|
|
|
|
|
#include <google/protobuf/duration.pb.h>
|
|
#include <google/protobuf/duration.pb.h>
|
|
|
|
+#include <google/protobuf/stubs/port.h>
|
|
#include <google/protobuf/timestamp.pb.h>
|
|
#include <google/protobuf/timestamp.pb.h>
|
|
|
|
|
|
namespace google {
|
|
namespace google {
|
|
@@ -85,6 +89,9 @@ class LIBPROTOBUF_EXPORT TimeUtil {
|
|
static string ToString(const Duration& duration);
|
|
static string ToString(const Duration& duration);
|
|
static bool FromString(const string& value, Duration* timestamp);
|
|
static bool FromString(const string& value, Duration* timestamp);
|
|
|
|
|
|
|
|
+#ifdef GetCurrentTime
|
|
|
|
+#undef GetCurrentTime // Visual Studio has macro GetCurrentTime
|
|
|
|
+#endif
|
|
// Gets the current UTC time.
|
|
// Gets the current UTC time.
|
|
static Timestamp GetCurrentTime();
|
|
static Timestamp GetCurrentTime();
|
|
// Returns the Time representing "1970-01-01 00:00:00".
|
|
// Returns the Time representing "1970-01-01 00:00:00".
|
|
@@ -153,12 +160,12 @@ namespace protobuf {
|
|
// Overloaded operators for Duration.
|
|
// Overloaded operators for Duration.
|
|
//
|
|
//
|
|
// Assignment operators.
|
|
// Assignment operators.
|
|
-Duration& operator+=(Duration& d1, const Duration& d2); // NOLINT
|
|
|
|
-Duration& operator-=(Duration& d1, const Duration& d2); // NOLINT
|
|
|
|
-Duration& operator*=(Duration& d, int64 r); // NOLINT
|
|
|
|
-Duration& operator*=(Duration& d, double r); // NOLINT
|
|
|
|
-Duration& operator/=(Duration& d, int64 r); // NOLINT
|
|
|
|
-Duration& operator/=(Duration& d, double r); // NOLINT
|
|
|
|
|
|
+LIBPROTOBUF_EXPORT Duration& operator+=(Duration& d1, const Duration& d2); // NOLINT
|
|
|
|
+LIBPROTOBUF_EXPORT Duration& operator-=(Duration& d1, const Duration& d2); // NOLINT
|
|
|
|
+LIBPROTOBUF_EXPORT Duration& operator*=(Duration& d, int64 r); // NOLINT
|
|
|
|
+LIBPROTOBUF_EXPORT Duration& operator*=(Duration& d, double r); // NOLINT
|
|
|
|
+LIBPROTOBUF_EXPORT Duration& operator/=(Duration& d, int64 r); // NOLINT
|
|
|
|
+LIBPROTOBUF_EXPORT Duration& operator/=(Duration& d, double r); // NOLINT
|
|
// Overload for other integer types.
|
|
// Overload for other integer types.
|
|
template <typename T>
|
|
template <typename T>
|
|
Duration& operator*=(Duration& d, T r) { // NOLINT
|
|
Duration& operator*=(Duration& d, T r) { // NOLINT
|
|
@@ -170,7 +177,7 @@ Duration& operator/=(Duration& d, T r) { // NOLINT
|
|
int64 x = r;
|
|
int64 x = r;
|
|
return d /= x;
|
|
return d /= x;
|
|
}
|
|
}
|
|
-Duration& operator%=(Duration& d1, const Duration& d2); // NOLINT
|
|
|
|
|
|
+LIBPROTOBUF_EXPORT Duration& operator%=(Duration& d1, const Duration& d2); // NOLINT
|
|
// Relational operators.
|
|
// Relational operators.
|
|
inline bool operator<(const Duration& d1, const Duration& d2) {
|
|
inline bool operator<(const Duration& d1, const Duration& d2) {
|
|
if (d1.seconds() == d2.seconds()) {
|
|
if (d1.seconds() == d2.seconds()) {
|
|
@@ -221,7 +228,7 @@ template<typename T>
|
|
inline Duration operator/(Duration d, T r) {
|
|
inline Duration operator/(Duration d, T r) {
|
|
return d /= r;
|
|
return d /= r;
|
|
}
|
|
}
|
|
-int64 operator/(const Duration& d1, const Duration& d2);
|
|
|
|
|
|
+LIBPROTOBUF_EXPORT int64 operator/(const Duration& d1, const Duration& d2);
|
|
|
|
|
|
inline Duration operator%(const Duration& d1, const Duration& d2) {
|
|
inline Duration operator%(const Duration& d1, const Duration& d2) {
|
|
Duration result = d1;
|
|
Duration result = d1;
|
|
@@ -236,7 +243,9 @@ inline ostream& operator<<(ostream& out, const Duration& d) {
|
|
// Overloaded operators for Timestamp
|
|
// Overloaded operators for Timestamp
|
|
//
|
|
//
|
|
// Assignement operators.
|
|
// Assignement operators.
|
|
|
|
+LIBPROTOBUF_EXPORT
|
|
Timestamp& operator+=(Timestamp& t, const Duration& d); // NOLINT
|
|
Timestamp& operator+=(Timestamp& t, const Duration& d); // NOLINT
|
|
|
|
+LIBPROTOBUF_EXPORT
|
|
Timestamp& operator-=(Timestamp& t, const Duration& d); // NOLINT
|
|
Timestamp& operator-=(Timestamp& t, const Duration& d); // NOLINT
|
|
// Relational operators.
|
|
// Relational operators.
|
|
inline bool operator<(const Timestamp& t1, const Timestamp& t2) {
|
|
inline bool operator<(const Timestamp& t1, const Timestamp& t2) {
|
|
@@ -273,7 +282,7 @@ inline Timestamp operator-(const Timestamp& t, const Duration& d) {
|
|
Timestamp result = t;
|
|
Timestamp result = t;
|
|
return result -= d;
|
|
return result -= d;
|
|
}
|
|
}
|
|
-Duration operator-(const Timestamp& t1, const Timestamp& t2);
|
|
|
|
|
|
+LIBPROTOBUF_EXPORT Duration operator-(const Timestamp& t1, const Timestamp& t2);
|
|
|
|
|
|
inline ostream& operator<<(ostream& out, const Timestamp& t) {
|
|
inline ostream& operator<<(ostream& out, const Timestamp& t) {
|
|
out << google::protobuf::util::TimeUtil::ToString(t);
|
|
out << google::protobuf::util::TimeUtil::ToString(t);
|