From 33de762cf636e3f13f17e02d70de2869664e3f2b Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Sat, 17 Oct 2009 11:10:54 +0200 Subject: Implement Date object. --- include/plist/Date.h | 7 ++++--- src/Date.cpp | 27 +++++++++++++++------------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/plist/Date.h b/include/plist/Date.h index e9645aa..5472657 100644 --- a/include/plist/Date.h +++ b/include/plist/Date.h @@ -23,6 +23,7 @@ #define DATE_H #include +#include namespace PList { @@ -34,13 +35,13 @@ class Date : public Node Date(plist_t node); Date(Date& d); Date& operator=(Date& d); - Date(uint64_t i); + Date(timeval t); virtual ~Date(); Node* Clone(); - void SetValue(uint64_t i); - uint64_t GetValue(); + void SetValue(timeval t); + timeval GetValue(); }; }; diff --git a/src/Date.cpp b/src/Date.cpp index 18e1d27..46ef14e 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -32,19 +32,21 @@ Date::Date(plist_t node) : Node(node) { } -Date::Date(Date& d) : Node(PLIST_DATE) +Date::Date(PList::Date& d) : Node(PLIST_DATE) { - //TODO + timeval t = d.GetValue(); + plist_set_date_val(_node, t.tv_sec, t.tv_usec); } -Date& Date::operator=(PList::Date& b) +Date& Date::operator=(PList::Date& d) { - //TODO + plist_free(_node); + _node = plist_copy(d.GetPlist()); } -Date::Date(uint64_t i) : Node(PLIST_DATE) +Date::Date(timeval t) : Node(PLIST_DATE) { - plist_set_date_val(_node, i, 0); + plist_set_date_val(_node, t.tv_sec, t.tv_usec); } Date::~Date() @@ -56,16 +58,17 @@ Node* Date::Clone() return new Date(*this); } -void Date::SetValue(uint64_t i) +void Date::SetValue(timeval t) { - plist_set_date_val(_node, i, 0); + plist_set_date_val(_node, t.tv_sec, t.tv_usec); } -uint64_t Date::GetValue() +timeval Date::GetValue() { - int32_t i = 0; - plist_get_date_val(_node, &i, &i); - return i; + int32_t tv_sec = 0; + int32_t tv_usec = 0; + plist_get_date_val(_node, &tv_sec, &tv_usec); + return {tv_sec, tv_usec}; } }; -- cgit v1.1-32-gdbae