aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2005-10-03 12:24:08 +0000
committerVincent Richard <[email protected]>2005-10-03 12:24:08 +0000
commitbdc2664ee2fea811cd72aa9950c63192ec5ec2e1 (patch)
tree0693fc2f43d32c8330ea419c017596d9b05d7a20
parentToo much CPU time used when waiting for data to be received. (diff)
downloadvmime-bdc2664ee2fea811cd72aa9950c63192ec5ec2e1.tar.gz
vmime-bdc2664ee2fea811cd72aa9950c63192ec5ec2e1.zip
Made 'datetime' compatible with C's time_t.
-rw-r--r--src/dateTime.cpp29
-rw-r--r--vmime/dateTime.hpp3
2 files changed, 32 insertions, 0 deletions
diff --git a/src/dateTime.cpp b/src/dateTime.cpp
index d0cfcd9e..36aafe2a 100644
--- a/src/dateTime.cpp
+++ b/src/dateTime.cpp
@@ -646,6 +646,35 @@ datetime::datetime(const datetime& d)
}
+datetime::datetime(const time_t t, const int zone)
+{
+#ifdef _REENTRANT
+ struct tm tms;
+
+ if (!gmtime_r(&t, &tms))
+ localtime_r(&t, &tms);
+#else
+ struct tm* gtm = gmtime(&t);
+ struct tm* ltm = localtime(&t);
+
+ struct tm tms;
+
+ if (gtm)
+ tms = *gtm;
+ else if (ltm)
+ tms = *ltm;
+#endif // _REENTRANT
+
+ m_year = tms.tm_year + 1900;
+ m_month = tms.tm_mon + 1;
+ m_day = tms.tm_mday;
+ m_hour = tms.tm_hour;
+ m_minute = tms.tm_min;
+ m_second = tms.tm_sec;
+ m_zone = zone;
+}
+
+
datetime::datetime(const string& date)
{
parse(date);
diff --git a/vmime/dateTime.hpp b/vmime/dateTime.hpp
index 3b0bd252..5f2499ce 100644
--- a/vmime/dateTime.hpp
+++ b/vmime/dateTime.hpp
@@ -28,6 +28,8 @@
#include "vmime/base.hpp"
#include "vmime/component.hpp"
+#include <ctime>
+
namespace vmime
{
@@ -46,6 +48,7 @@ public:
datetime(const int year, const int month, const int day, const int hour, const int minute, const int second, const int zone = GMT);
datetime(const datetime& d);
datetime(const string& date);
+ datetime(const time_t t, const int zone = GMT);
// Destructor
~datetime();