Made 'datetime' compatible with C's time_t.

This commit is contained in:
Vincent Richard 2005-10-03 12:24:08 +00:00
parent 887930fac8
commit bdc2664ee2
2 changed files with 32 additions and 0 deletions

View File

@ -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);

View File

@ -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();