BDate: added time_t constructor.

* This class is pretty much useless as it is.
This commit is contained in:
Axel Dörfler
2015-09-04 17:33:07 +02:00
parent cc7e5aac40
commit 19d8cb703c
2 changed files with 20 additions and 15 deletions
+2
View File
@@ -91,6 +91,8 @@ public:
BDate(); BDate();
BDate(const BDate& other); BDate(const BDate& other);
BDate(int32 year, int32 month, int32 day); BDate(int32 year, int32 month, int32 day);
BDate(time_t time,
time_type type = B_LOCAL_TIME);
BDate(const BMessage* archive); BDate(const BMessage* archive);
~BDate(); ~BDate();
+18 -15
View File
@@ -486,6 +486,23 @@ BDate::BDate(int32 year, int32 month, int32 day)
} }
BDate::BDate(time_t time, time_type type)
{
struct tm result;
struct tm* timeinfo;
if (type == B_GMT_TIME)
timeinfo = gmtime_r(&time, &result);
else
timeinfo = localtime_r(&time, &result);
if (timeinfo != NULL) {
_SetDate(timeinfo->tm_year + 1900, timeinfo->tm_mon + 1,
timeinfo->tm_mday);
}
}
/*! /*!
Constructs a new BDate object from the provided archive. Constructs a new BDate object from the provided archive.
*/ */
@@ -586,21 +603,7 @@ BDate::IsValid(int32 year, int32 month, int32 day)
BDate BDate
BDate::CurrentDate(time_type type) BDate::CurrentDate(time_type type)
{ {
time_t timer; return BDate(time(NULL), type);
struct tm result;
struct tm* timeinfo;
time(&timer);
if (type == B_GMT_TIME)
timeinfo = gmtime_r(&timer, &result);
else
timeinfo = localtime_r(&timer, &result);
if (timeinfo == NULL)
return BDate();
return BDate(timeinfo->tm_year + 1900, timeinfo->tm_mon +1, timeinfo->tm_mday);
} }