blob: 8b8e650ee2de144b7bb8706fc92a69673bb60fbf [file] [log] [blame]
Jonathan Becka922b712009-10-13 20:04:06 +02001/*
2 * Date.cpp
3 *
4 * Copyright (c) 2009 Jonathan Beck All Rights Reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
Jonathan Beck6710f4b2009-10-28 18:31:34 +010010 *
Jonathan Becka922b712009-10-13 20:04:06 +020011 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
Jonathan Beck6710f4b2009-10-28 18:31:34 +010015 *
Jonathan Becka922b712009-10-13 20:04:06 +020016 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
Jonathan Beck6710f4b2009-10-28 18:31:34 +010018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Jonathan Becka922b712009-10-13 20:04:06 +020019 */
20
Rosen Penev319de9a2020-05-30 20:14:35 -070021#include <cstdlib>
Jonathan Becka922b712009-10-13 20:04:06 +020022#include <plist/Date.h>
23
24namespace PList
25{
26
Jonathan Beckc1363be2009-10-26 18:41:15 +010027Date::Date(Node* parent) : Node(PLIST_DATE, parent)
Jonathan Becka922b712009-10-13 20:04:06 +020028{
29}
30
Jonathan Beckc1363be2009-10-26 18:41:15 +010031Date::Date(plist_t node, Node* parent) : Node(node, parent)
Jonathan Beck8186a9d2009-10-15 19:28:30 +020032{
33}
34
Aaron Burghardtccd6f052014-08-15 21:59:01 -040035Date::Date(const PList::Date& d) : Node(PLIST_DATE)
Jonathan Beck32be8ec2009-10-16 22:26:13 +020036{
Jonathan Beck33de7622009-10-17 11:10:54 +020037 timeval t = d.GetValue();
38 plist_set_date_val(_node, t.tv_sec, t.tv_usec);
Jonathan Beck32be8ec2009-10-16 22:26:13 +020039}
40
Rosen Penev8c7e2582020-12-21 20:04:57 -080041Date& Date::operator=(const PList::Date& d)
Jonathan Beck32be8ec2009-10-16 22:26:13 +020042{
Jonathan Beck33de7622009-10-17 11:10:54 +020043 plist_free(_node);
44 _node = plist_copy(d.GetPlist());
Jonathan Beck1bc33392009-10-28 17:57:52 +010045 return *this;
Jonathan Beck32be8ec2009-10-16 22:26:13 +020046}
47
Jonathan Beck33de7622009-10-17 11:10:54 +020048Date::Date(timeval t) : Node(PLIST_DATE)
Jonathan Becka922b712009-10-13 20:04:06 +020049{
Jonathan Beck33de7622009-10-17 11:10:54 +020050 plist_set_date_val(_node, t.tv_sec, t.tv_usec);
Jonathan Becka922b712009-10-13 20:04:06 +020051}
52
53Date::~Date()
54{
55}
56
Aaron Burghardtccd6f052014-08-15 21:59:01 -040057Node* Date::Clone() const
Jonathan Beck32be8ec2009-10-16 22:26:13 +020058{
59 return new Date(*this);
60}
61
Jonathan Beck33de7622009-10-17 11:10:54 +020062void Date::SetValue(timeval t)
Jonathan Becka922b712009-10-13 20:04:06 +020063{
Jonathan Beck33de7622009-10-17 11:10:54 +020064 plist_set_date_val(_node, t.tv_sec, t.tv_usec);
Jonathan Becka922b712009-10-13 20:04:06 +020065}
66
Aaron Burghardtccd6f052014-08-15 21:59:01 -040067timeval Date::GetValue() const
Jonathan Becka922b712009-10-13 20:04:06 +020068{
Jonathan Beck33de7622009-10-17 11:10:54 +020069 int32_t tv_sec = 0;
70 int32_t tv_usec = 0;
71 plist_get_date_val(_node, &tv_sec, &tv_usec);
Jonathan Beckd21c7d42009-10-17 23:03:50 +020072 timeval t = {tv_sec, tv_usec};
73 return t;
Jonathan Becka922b712009-10-13 20:04:06 +020074}
75
Rosen Penev7c69e032020-05-30 20:06:00 -070076} // namespace PList