summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2009-10-17 11:10:54 +0200
committerGravatar Jonathan Beck2009-10-17 11:10:54 +0200
commit33de762cf636e3f13f17e02d70de2869664e3f2b (patch)
treeedb92293a1f61d358c76180b9d96b7642f1614a4
parent6f453688c0b97ea979b2b2b515f4030e69e846fb (diff)
downloadlibplist-33de762cf636e3f13f17e02d70de2869664e3f2b.tar.gz
libplist-33de762cf636e3f13f17e02d70de2869664e3f2b.tar.bz2
Implement Date object.
-rw-r--r--include/plist/Date.h7
-rw-r--r--src/Date.cpp27
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 <plist/Node.h>
+#include <ctime>
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};
}
};