diff options
author | 2025-05-13 18:34:32 +0200 | |
---|---|---|
committer | 2025-05-13 18:34:32 +0200 | |
commit | cb76e4da84c61609c13e84c922f14a27b8348a36 (patch) | |
tree | 6f0057efd11780ec38da6e8b686726f51bd10f30 /src/Date.cpp | |
parent | d7fe479707af57aeedf7e41c08e7fb698cd2e2a3 (diff) | |
download | libplist-cb76e4da84c61609c13e84c922f14a27b8348a36.tar.gz libplist-cb76e4da84c61609c13e84c922f14a27b8348a36.tar.bz2 |
Add plist_new_unix_date, plist_get_unix_date_val, plist_set_unix_date_val functions
These functions work with int64_t values representing a UNIX timestamp instead
of using the 'MAC epoch'. They should be used instead of plist_new_date,
plist_get_date_val, and plist_set_date_val, which are now marked deprecated
and might be removed in a future version of libplist.
Diffstat (limited to 'src/Date.cpp')
-rw-r--r-- | src/Date.cpp | 22 |
1 files changed, 10 insertions, 12 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) Date::Date(const PList::Date& d) : Node(PLIST_DATE) { - timeval t = d.GetValue(); - plist_set_date_val(_node, t.tv_sec, t.tv_usec); + int64_t t = d.GetValue(); + plist_set_unix_date_val(_node, t); } Date& Date::operator=(const PList::Date& d) @@ -45,9 +45,9 @@ Date& Date::operator=(const PList::Date& d) return *this; } -Date::Date(timeval t) : Node(PLIST_DATE) +Date::Date(int64_t t) : Node(PLIST_DATE) { - plist_set_date_val(_node, t.tv_sec, t.tv_usec); + plist_set_unix_date_val(_node, t); } Date::~Date() @@ -59,18 +59,16 @@ Node* Date::Clone() const return new Date(*this); } -void Date::SetValue(timeval t) +void Date::SetValue(int64_t t) { - plist_set_date_val(_node, t.tv_sec, t.tv_usec); + plist_set_unix_date_val(_node, t); } -timeval Date::GetValue() const +int64_t Date::GetValue() const { - int32_t tv_sec = 0; - int32_t tv_usec = 0; - plist_get_date_val(_node, &tv_sec, &tv_usec); - timeval t = {tv_sec, tv_usec}; - return t; + int64_t sec = 0; + plist_get_unix_date_val(_node, &sec); + return sec; } } // namespace PList |