Jonathan Beck | a922b71 | 2009-10-13 20:04:06 +0200 | [diff] [blame] | 1 | /* |
| 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 Beck | 6710f4b | 2009-10-28 18:31:34 +0100 | [diff] [blame] | 10 | * |
Jonathan Beck | a922b71 | 2009-10-13 20:04:06 +0200 | [diff] [blame] | 11 | * 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 Beck | 6710f4b | 2009-10-28 18:31:34 +0100 | [diff] [blame] | 15 | * |
Jonathan Beck | a922b71 | 2009-10-13 20:04:06 +0200 | [diff] [blame] | 16 | * 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 Beck | 6710f4b | 2009-10-28 18:31:34 +0100 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
Jonathan Beck | a922b71 | 2009-10-13 20:04:06 +0200 | [diff] [blame] | 19 | */ |
| 20 | |
Rosen Penev | 319de9a | 2020-05-30 20:14:35 -0700 | [diff] [blame] | 21 | #include <cstdlib> |
Jonathan Beck | a922b71 | 2009-10-13 20:04:06 +0200 | [diff] [blame] | 22 | #include <plist/Date.h> |
| 23 | |
| 24 | namespace PList |
| 25 | { |
| 26 | |
Jonathan Beck | c1363be | 2009-10-26 18:41:15 +0100 | [diff] [blame] | 27 | Date::Date(Node* parent) : Node(PLIST_DATE, parent) |
Jonathan Beck | a922b71 | 2009-10-13 20:04:06 +0200 | [diff] [blame] | 28 | { |
| 29 | } |
| 30 | |
Jonathan Beck | c1363be | 2009-10-26 18:41:15 +0100 | [diff] [blame] | 31 | Date::Date(plist_t node, Node* parent) : Node(node, parent) |
Jonathan Beck | 8186a9d | 2009-10-15 19:28:30 +0200 | [diff] [blame] | 32 | { |
| 33 | } |
| 34 | |
Aaron Burghardt | ccd6f05 | 2014-08-15 21:59:01 -0400 | [diff] [blame] | 35 | Date::Date(const PList::Date& d) : Node(PLIST_DATE) |
Jonathan Beck | 32be8ec | 2009-10-16 22:26:13 +0200 | [diff] [blame] | 36 | { |
Jonathan Beck | 33de762 | 2009-10-17 11:10:54 +0200 | [diff] [blame] | 37 | timeval t = d.GetValue(); |
| 38 | plist_set_date_val(_node, t.tv_sec, t.tv_usec); |
Jonathan Beck | 32be8ec | 2009-10-16 22:26:13 +0200 | [diff] [blame] | 39 | } |
| 40 | |
Rosen Penev | 8c7e258 | 2020-12-21 20:04:57 -0800 | [diff] [blame] | 41 | Date& Date::operator=(const PList::Date& d) |
Jonathan Beck | 32be8ec | 2009-10-16 22:26:13 +0200 | [diff] [blame] | 42 | { |
Jonathan Beck | 33de762 | 2009-10-17 11:10:54 +0200 | [diff] [blame] | 43 | plist_free(_node); |
| 44 | _node = plist_copy(d.GetPlist()); |
Jonathan Beck | 1bc3339 | 2009-10-28 17:57:52 +0100 | [diff] [blame] | 45 | return *this; |
Jonathan Beck | 32be8ec | 2009-10-16 22:26:13 +0200 | [diff] [blame] | 46 | } |
| 47 | |
Jonathan Beck | 33de762 | 2009-10-17 11:10:54 +0200 | [diff] [blame] | 48 | Date::Date(timeval t) : Node(PLIST_DATE) |
Jonathan Beck | a922b71 | 2009-10-13 20:04:06 +0200 | [diff] [blame] | 49 | { |
Jonathan Beck | 33de762 | 2009-10-17 11:10:54 +0200 | [diff] [blame] | 50 | plist_set_date_val(_node, t.tv_sec, t.tv_usec); |
Jonathan Beck | a922b71 | 2009-10-13 20:04:06 +0200 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | Date::~Date() |
| 54 | { |
| 55 | } |
| 56 | |
Aaron Burghardt | ccd6f05 | 2014-08-15 21:59:01 -0400 | [diff] [blame] | 57 | Node* Date::Clone() const |
Jonathan Beck | 32be8ec | 2009-10-16 22:26:13 +0200 | [diff] [blame] | 58 | { |
| 59 | return new Date(*this); |
| 60 | } |
| 61 | |
Jonathan Beck | 33de762 | 2009-10-17 11:10:54 +0200 | [diff] [blame] | 62 | void Date::SetValue(timeval t) |
Jonathan Beck | a922b71 | 2009-10-13 20:04:06 +0200 | [diff] [blame] | 63 | { |
Jonathan Beck | 33de762 | 2009-10-17 11:10:54 +0200 | [diff] [blame] | 64 | plist_set_date_val(_node, t.tv_sec, t.tv_usec); |
Jonathan Beck | a922b71 | 2009-10-13 20:04:06 +0200 | [diff] [blame] | 65 | } |
| 66 | |
Aaron Burghardt | ccd6f05 | 2014-08-15 21:59:01 -0400 | [diff] [blame] | 67 | timeval Date::GetValue() const |
Jonathan Beck | a922b71 | 2009-10-13 20:04:06 +0200 | [diff] [blame] | 68 | { |
Jonathan Beck | 33de762 | 2009-10-17 11:10:54 +0200 | [diff] [blame] | 69 | int32_t tv_sec = 0; |
| 70 | int32_t tv_usec = 0; |
| 71 | plist_get_date_val(_node, &tv_sec, &tv_usec); |
Jonathan Beck | d21c7d4 | 2009-10-17 23:03:50 +0200 | [diff] [blame] | 72 | timeval t = {tv_sec, tv_usec}; |
| 73 | return t; |
Jonathan Beck | a922b71 | 2009-10-13 20:04:06 +0200 | [diff] [blame] | 74 | } |
| 75 | |
Rosen Penev | 7c69e03 | 2020-05-30 20:06:00 -0700 | [diff] [blame] | 76 | } // namespace PList |