From bdc2664ee2fea811cd72aa9950c63192ec5ec2e1 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Mon, 3 Oct 2005 12:24:08 +0000 Subject: [PATCH] Made 'datetime' compatible with C's time_t. --- src/dateTime.cpp | 29 +++++++++++++++++++++++++++++ vmime/dateTime.hpp | 3 +++ 2 files changed, 32 insertions(+) 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 + 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();