summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Date.cpp22
-rw-r--r--src/Node.cpp2
-rw-r--r--src/plist.c49
3 files changed, 60 insertions, 13 deletions
diff --git a/src/Date.cpp b/src/Date.cpp
index 8b8e650..cbfa123 100644
--- a/src/Date.cpp
+++ b/src/Date.cpp
@@ -34,8 +34,8 @@ Date::Date(plist_t node, Node* parent) : Node(node, parent)
34 34
35Date::Date(const PList::Date& d) : Node(PLIST_DATE) 35Date::Date(const PList::Date& d) : Node(PLIST_DATE)
36{ 36{
37 timeval t = d.GetValue(); 37 int64_t t = d.GetValue();
38 plist_set_date_val(_node, t.tv_sec, t.tv_usec); 38 plist_set_unix_date_val(_node, t);
39} 39}
40 40
41Date& Date::operator=(const PList::Date& d) 41Date& Date::operator=(const PList::Date& d)
@@ -45,9 +45,9 @@ Date& Date::operator=(const PList::Date& d)
45 return *this; 45 return *this;
46} 46}
47 47
48Date::Date(timeval t) : Node(PLIST_DATE) 48Date::Date(int64_t t) : Node(PLIST_DATE)
49{ 49{
50 plist_set_date_val(_node, t.tv_sec, t.tv_usec); 50 plist_set_unix_date_val(_node, t);
51} 51}
52 52
53Date::~Date() 53Date::~Date()
@@ -59,18 +59,16 @@ Node* Date::Clone() const
59 return new Date(*this); 59 return new Date(*this);
60} 60}
61 61
62void Date::SetValue(timeval t) 62void Date::SetValue(int64_t t)
63{ 63{
64 plist_set_date_val(_node, t.tv_sec, t.tv_usec); 64 plist_set_unix_date_val(_node, t);
65} 65}
66 66
67timeval Date::GetValue() const 67int64_t Date::GetValue() const
68{ 68{
69 int32_t tv_sec = 0; 69 int64_t sec = 0;
70 int32_t tv_usec = 0; 70 plist_get_unix_date_val(_node, &sec);
71 plist_get_date_val(_node, &tv_sec, &tv_usec); 71 return sec;
72 timeval t = {tv_sec, tv_usec};
73 return t;
74} 72}
75 73
76} // namespace PList 74} // namespace PList
diff --git a/src/Node.cpp b/src/Node.cpp
index 0bd428a..1043b31 100644
--- a/src/Node.cpp
+++ b/src/Node.cpp
@@ -73,7 +73,7 @@ Node::Node(plist_type type, Node* parent) : _parent(parent)
73 _node = plist_new_data(NULL,0); 73 _node = plist_new_data(NULL,0);
74 break; 74 break;
75 case PLIST_DATE: 75 case PLIST_DATE:
76 _node = plist_new_date(0,0); 76 _node = plist_new_unix_date(0);
77 break; 77 break;
78 case PLIST_ARRAY: 78 case PLIST_ARRAY:
79 _node = plist_new_array(); 79 _node = plist_new_array();
diff --git a/src/plist.c b/src/plist.c
index 3f86105..4fc2f00 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -46,6 +46,8 @@
46#include <hashtable.h> 46#include <hashtable.h>
47#include <ptrarray.h> 47#include <ptrarray.h>
48 48
49#define MAC_EPOCH 978307200
50
49#ifdef _MSC_VER 51#ifdef _MSC_VER
50typedef SSIZE_T ssize_t; 52typedef SSIZE_T ssize_t;
51#endif 53#endif
@@ -528,6 +530,15 @@ plist_t plist_new_date(int32_t sec, int32_t usec)
528 return plist_new_node(data); 530 return plist_new_node(data);
529} 531}
530 532
533plist_t plist_new_unix_date(int64_t sec)
534{
535 plist_data_t data = plist_new_plist_data();
536 data->type = PLIST_DATE;
537 data->realval = (double)sec - MAC_EPOCH;
538 data->length = sizeof(double);
539 return plist_new_node(data);
540}
541
531plist_t plist_new_null(void) 542plist_t plist_new_null(void)
532{ 543{
533 plist_data_t data = plist_new_plist_data(); 544 plist_data_t data = plist_new_plist_data();
@@ -1392,6 +1403,20 @@ void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec)
1392 } 1403 }
1393} 1404}
1394 1405
1406void plist_get_unix_date_val(plist_t node, int64_t *sec)
1407{
1408 if (!node || !sec)
1409 return;
1410 plist_type type = plist_get_node_type(node);
1411 uint64_t length = 0;
1412 double val = 0;
1413 if (PLIST_DATE != type)
1414 return;
1415 plist_get_type_and_value(node, &type, (void *) &val, &length);
1416 assert(length == sizeof(double));
1417 *sec = (int64_t)val + MAC_EPOCH;
1418}
1419
1395int plist_data_compare(const void *a, const void *b) 1420int plist_data_compare(const void *a, const void *b)
1396{ 1421{
1397 plist_data_t val_a = NULL; 1422 plist_data_t val_a = NULL;
@@ -1551,6 +1576,12 @@ void plist_set_date_val(plist_t node, int32_t sec, int32_t usec)
1551 plist_set_element_val(node, PLIST_DATE, &val, sizeof(double)); 1576 plist_set_element_val(node, PLIST_DATE, &val, sizeof(double));
1552} 1577}
1553 1578
1579void plist_set_unix_date_val(plist_t node, int64_t sec)
1580{
1581 double val = (double)(sec - MAC_EPOCH);
1582 plist_set_element_val(node, PLIST_DATE, &val, sizeof(double));
1583}
1584
1554int plist_bool_val_is_true(plist_t boolnode) 1585int plist_bool_val_is_true(plist_t boolnode)
1555{ 1586{
1556 if (!PLIST_IS_BOOLEAN(boolnode)) { 1587 if (!PLIST_IS_BOOLEAN(boolnode)) {
@@ -1686,6 +1717,24 @@ int plist_date_val_compare(plist_t datenode, int32_t cmpsec, int32_t cmpusec)
1686 return 1; 1717 return 1;
1687} 1718}
1688 1719
1720int plist_unix_date_val_compare(plist_t datenode, int64_t cmpval)
1721{
1722 if (!PLIST_IS_DATE(datenode)) {
1723 return -1;
1724 }
1725 int64_t dateval = 0;
1726 plist_get_unix_date_val(datenode, &dateval);
1727 if (dateval == cmpval) {
1728 return 0;
1729 }
1730
1731 if (dateval < cmpval) {
1732 return -1;
1733 }
1734
1735 return 1;
1736}
1737
1689int plist_string_val_compare(plist_t strnode, const char* cmpval) 1738int plist_string_val_compare(plist_t strnode, const char* cmpval)
1690{ 1739{
1691 if (!PLIST_IS_STRING(strnode)) { 1740 if (!PLIST_IS_STRING(strnode)) {