Made 'datetime' compatible with C's time_t.
This commit is contained in:
parent
887930fac8
commit
bdc2664ee2
@ -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)
|
datetime::datetime(const string& date)
|
||||||
{
|
{
|
||||||
parse(date);
|
parse(date);
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
#include "vmime/base.hpp"
|
#include "vmime/base.hpp"
|
||||||
#include "vmime/component.hpp"
|
#include "vmime/component.hpp"
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
|
||||||
namespace vmime
|
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 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 datetime& d);
|
||||||
datetime(const string& date);
|
datetime(const string& date);
|
||||||
|
datetime(const time_t t, const int zone = GMT);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~datetime();
|
~datetime();
|
||||||
|
Loading…
Reference in New Issue
Block a user